diff --git a/deployment-template/services.yml b/deployment-template/services.yml index addf04a..7aa2cec 100644 --- a/deployment-template/services.yml +++ b/deployment-template/services.yml @@ -4,6 +4,7 @@ kind: Service metadata: name: MAKEFILE_SERVICE_NAME-rabbitmq spec: + type: NodePort selector: app: MAKEFILE_SERVICE_NAME-rabbitmq ports: diff --git a/service/health.py b/service/health.py index aa103c7..105dbe2 100644 --- a/service/health.py +++ b/service/health.py @@ -38,7 +38,7 @@ from channels import CommandChannel from kubernetes import client, config from kubernetes_utils import get_current_k8_services, get_current_k8_pods, rm_container, rm_pvc, \ - get_current_k8_pods, rm_service, KubernetesError, update_traefik_configmap, get_k8_logs, list_all_containers, run_k8_exec + get_current_k8_pods, rm_service, KubernetesError, get_k8_logs, list_all_containers, run_k8_exec from codes import AVAILABLE, DELETING, STOPPED, ERROR, REQUESTED, COMPLETE, RESTART, ON, OFF from stores import pg_store, SITE_TENANT_DICT from models_pods import Pod @@ -259,7 +259,7 @@ def check_k8_services(): continue def check_db_pods(k8_pods): - """Go through database for all tenants in this site. Delete/Create whatever is needed. Do proxy config stuff. + """Go through database for all tenants in this site. Delete/Create whatever is needed. """ all_pods = [] stmt = select(Pod) @@ -361,31 +361,6 @@ def check_db_pods(k8_pods): logger.debug(f"Command Channel - Added msg for pod_id: {pod.pod_id}.") - ### Proxy ports and config changes - # For proxy config later. proxy_info_x = {pod.k8_name: {routing_port, url}, ...} - tcp_proxy_info = {} - http_proxy_info = {} - postgres_proxy_info = {} - for pod in all_pods: - # Each pod can have up to 3 networking objects with custom filled port/protocol/name - for net_name, net_info in pod.networking.items(): - if not isinstance(net_info, dict): - net_info = net_info.dict() - - template_info = {"routing_port": net_info['port'], - "url": net_info['url']} - match net_info['protocol']: - case "tcp": - tcp_proxy_info[pod.k8_name] = template_info - case "http": - http_proxy_info[pod.k8_name] = template_info - case "postgres": - postgres_proxy_info[pod.k8_name] = template_info - - # This functions only updates if config is out of date. - update_traefik_configmap(tcp_proxy_info, http_proxy_info, postgres_proxy_info) - - def main(): # Try and run check_db_pods. Will try for 60 seconds until health is declared "broken". logger.info("Top of health. Checking if db's are initialized.") diff --git a/service/health_central.py b/service/health_central.py index 6c91d04..77dfdbb 100644 --- a/service/health_central.py +++ b/service/health_central.py @@ -7,7 +7,7 @@ Does the following: 1. Does startup work for NFS mount 2. Goes through NFS mount and does cleaning -3. Deals with traefik logs and metrics in general +3. Deals with traefik proxy, logs, and metrics """ @@ -193,6 +193,37 @@ def nfs_folder_init(tenant): raise BaseTapyException(msg) +def set_traefik_proxy(): + all_pods = [] + stmt = select(Pod) + for tenant in SITE_TENANT_DICT[conf.site_id]: + all_pods += pg_store[conf.site_id][tenant].run("execute", stmt, scalars=True, all=True) + + ### Proxy ports and config changes + # For proxy config later. proxy_info_x = {pod.k8_name: {routing_port, url}, ...} + tcp_proxy_info = {} + http_proxy_info = {} + postgres_proxy_info = {} + for pod in all_pods: + # Each pod can have up to 3 networking objects with custom filled port/protocol/name + for net_name, net_info in pod.networking.items(): + if not isinstance(net_info, dict): + net_info = net_info.dict() + + template_info = {"routing_port": net_info['port'], + "url": net_info['url']} + match net_info['protocol']: + case "tcp": + tcp_proxy_info[pod.k8_name] = template_info + case "http": + http_proxy_info[pod.k8_name] = template_info + case "postgres": + postgres_proxy_info[pod.k8_name] = template_info + + # This functions only updates if config is out of date. + update_traefik_configmap(tcp_proxy_info, http_proxy_info, postgres_proxy_info) + + def main(): # Try and run check_db_pods. Will try for 60 seconds until health is declared "broken". logger.info("Top of health. Checking if db's are initialized.") @@ -219,7 +250,8 @@ def main(): while True: logger.info(f"Running pods health checks. Now: {time.time()}") check_nfs_files() - + + set_traefik_proxy() ### Have a short wait time.sleep(3) diff --git a/service/kubernetes_utils.py b/service/kubernetes_utils.py index 3784ec4..9fb6859 100644 --- a/service/kubernetes_utils.py +++ b/service/kubernetes_utils.py @@ -564,10 +564,11 @@ def update_traefik_configmap(tcp_proxy_info: Dict[str, Dict[str, str]], current_template = k8.read_namespaced_config_map(name='pods-traefik-conf', namespace=NAMESPACE) if not current_template.data['traefik.yml'] == rendered_template: + logger.debug("Health found difference in Traefik configs, updated configmap.") # Update the configmap with the new template immediately. config_map = client.V1ConfigMap(data = {"traefik.yml": rendered_template}) k8.patch_namespaced_config_map(name='pods-traefik-conf', namespace=NAMESPACE, body=config_map) - # Auto updates proxxy pod. Changes take place according to kubelet sync frequency duration (60s default). + # Auto updates proxy pod. Changes take place according to kubelet sync frequency duration (60s default). def get_traefik_configmap(): """