diff --git a/Dockerfile b/Dockerfile index 24473b3..1bc43ca 100644 --- a/Dockerfile +++ b/Dockerfile @@ -69,6 +69,9 @@ RUN pip3 install -r /opt/programming_mode/requirements.txt EXPOSE 8080 ENV PATH=/usr/local/openresty/nginx/sbin:$PATH + COPY ./entrypoint.sh / + RUN chmod a+rwx ./entrypoint.sh + ENTRYPOINT ["/entrypoint.sh"] diff --git a/dev-tools/build_develop_image.sh b/dev-tools/dev/build_develop_image.sh similarity index 100% rename from dev-tools/build_develop_image.sh rename to dev-tools/dev/build_develop_image.sh diff --git a/dev-tools/dev/build_develop_local_image.sh b/dev-tools/dev/build_develop_local_image.sh new file mode 100644 index 0000000..da7039d --- /dev/null +++ b/dev-tools/dev/build_develop_local_image.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +docker build . -t docker.io/luckysideburn/kubeinvaders:develop_local +docker push docker.io/luckysideburn/kubeinvaders:develop_local diff --git a/dev-tools/docker/start_dev_local.sh b/dev-tools/docker/start_dev_local.sh new file mode 100644 index 0000000..088edd8 --- /dev/null +++ b/dev-tools/docker/start_dev_local.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +docker build . -t docker.io/luckysideburn/kubeinvaders:develop_local + +docker rm -f kinv +docker run -p 8080:8080 \ +--name kinv \ +--env K8S_TOKEN=$KINV_TOKEN \ +--env ENDPOINT=localhost:8080 \ +--env INSECURE_ENDPOINT=true \ +--env KUBERNETES_SERVICE_HOST=$KINV_K8S_IP \ +--env KUBERNETES_SERVICE_PORT_HTTPS=6443 \ +--env NAMESPACE=namespace1 \ +luckysideburn/kubeinvaders:develop_local diff --git a/dev-tools/release_helm.sh b/dev-tools/helm/release_helm.sh similarity index 100% rename from dev-tools/release_helm.sh rename to dev-tools/helm/release_helm.sh diff --git a/dev-tools/test_helm_installation.sh b/dev-tools/helm/test_helm_installation.sh similarity index 100% rename from dev-tools/test_helm_installation.sh rename to dev-tools/helm/test_helm_installation.sh diff --git a/dev-tools/deploy_to_prod.sh b/dev-tools/push/push_prod_image.sh similarity index 100% rename from dev-tools/deploy_to_prod.sh rename to dev-tools/push/push_prod_image.sh diff --git a/dev-tools/start_dev.sh b/dev-tools/start/start_dev.sh similarity index 100% rename from dev-tools/start_dev.sh rename to dev-tools/start/start_dev.sh diff --git a/dev-tools/start_dev_buildah.sh b/dev-tools/start/start_dev_buildah.sh similarity index 100% rename from dev-tools/start_dev_buildah.sh rename to dev-tools/start/start_dev_buildah.sh diff --git a/dev-tools/start_dev_nodeport.sh b/dev-tools/start/start_dev_nodeport.sh similarity index 100% rename from dev-tools/start_dev_nodeport.sh rename to dev-tools/start/start_dev_nodeport.sh diff --git a/dev-tools/start_prod.sh b/dev-tools/start/start_prod.sh similarity index 100% rename from dev-tools/start_prod.sh rename to dev-tools/start/start_prod.sh diff --git a/dev-tools/logs.sh b/dev-tools/utilities/logs.sh similarity index 100% rename from dev-tools/logs.sh rename to dev-tools/utilities/logs.sh diff --git a/dev-tools/deploymentns1ns2.yaml b/dev-tools/yamls/deploymentns1ns2.yaml similarity index 100% rename from dev-tools/deploymentns1ns2.yaml rename to dev-tools/yamls/deploymentns1ns2.yaml diff --git a/entrypoint.sh b/entrypoint.sh index 920c6e3..dfeedb0 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,5 +1,7 @@ #!/bin/bash + set -m + if [ ! -z "$K8S_TOKEN" ];then echo 'Found K8S_TOKEN... using K8S_TOKEN instead of TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)' export TOKEN=$K8S_TOKEN @@ -8,7 +10,12 @@ else export TOKEN="$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" fi +trap "exit" INT TERM ERR +trap "kill 0" EXIT + redis-server /etc/redis/redis.conf & -bash /opt/metrics_loop/start.sh & -bash /opt/logs_loop/start.sh & -nginx -c /etc/nginx/nginx.conf -g 'daemon off;' +/opt/metrics_loop/start.sh & +/opt/logs_loop/start.sh & +nginx -c /etc/nginx/nginx.conf -g 'daemon off;' & + +wait diff --git a/scripts/logs_loop/start.py b/scripts/logs_loop/start.py index 8d8afe9..bab65aa 100644 --- a/scripts/logs_loop/start.py +++ b/scripts/logs_loop/start.py @@ -152,13 +152,13 @@ while True: final_pod_list = [] if r.exists(f"log_pod_regex:{logid}") and r.exists(f"logs_enabled:{logid}"): # and r.get("programming_mode") == "0": - logging.info(f"[logid:{logid}] Found Redis keys for log tail") + #logging.info(f"[logid:{logid}] Found Redis keys for log tail") if r.get(f"logs_enabled:{logid}") == "1": - logging.info(f"[logid:{logid}] Found regex log_pod_regex in Redis. Logs from all pods should be collected") + #logging.info(f"[logid:{logid}] Found regex log_pod_regex in Redis. Logs from all pods should be collected") log_pod_regex = r.get(f"log_pod_regex:{logid}") - logging.info(f"[logid:{logid}] log_pod_regex is => |{log_pod_regex}|") + #logging.info(f"[logid:{logid}] log_pod_regex is => |{log_pod_regex}|") try: api_response = api_instance.list_pod_for_all_namespaces() @@ -166,7 +166,7 @@ while True: logging.info(e) pods_found_info = f"[logid:{logid}] Looking for pods compliant with the current regex. Scanning {len(api_response.items)} pods" - logging.info(pods_found_info) + #logging.info(pods_found_info) r.set(f"log_status:{logid}", pods_found_info) json_re = json.loads(log_pod_regex) @@ -177,11 +177,11 @@ while True: labels_re = json_re["labels"] containers_re = json_re["containers"] - logging.info(f"[logid:{logid}] Gobal Json Regex is |{json_re}|") - logging.info(f"[logid:{logid}] Regex for pod name is |{pod_re}|") - logging.info(f"[logid:{logid}] Regex namespace name |{namespace_re}|") - logging.info(f"[logid:{logid}] Regex for labels is |{labels_re}|") - logging.info(f"[logid:{logid}] Regex for annotation is |{annotations_re}|") + # logging.info(f"[logid:{logid}] Gobal Json Regex is |{json_re}|") + # logging.info(f"[logid:{logid}] Regex for pod name is |{pod_re}|") + # logging.info(f"[logid:{logid}] Regex namespace name |{namespace_re}|") + # logging.info(f"[logid:{logid}] Regex for labels is |{labels_re}|") + # logging.info(f"[logid:{logid}] Regex for annotation is |{annotations_re}|") for pod in api_response.items: if r.exists(f"regex_cmp:{logid}:{pod.metadata.namespace}:{pod.metadata.name}"): @@ -195,37 +195,37 @@ while True: logging.debug(regex_match_info) r.set(f"log_status:{logid}", regex_match_info) else: - logging.debug(f"[logid:{logid}] Regex comparison |{pod_re}| |{pod.metadata.name}|") - logging.debug(f"[logid:{logid}] Regex comparison |{namespace_re}| |{pod.metadata.namespace}|") - logging.debug(f"[logid:{logid}] Regex comparison |{labels_re}| |{str(pod.metadata.labels)}|") - logging.debug(f"[logid:{logid}] Regex comparison |{annotations_re}| |{str(pod.metadata.annotations)}|") + # logging.debug(f"[logid:{logid}] Regex comparison |{pod_re}| |{pod.metadata.name}|") + # logging.debug(f"[logid:{logid}] Regex comparison |{namespace_re}| |{pod.metadata.namespace}|") + # logging.debug(f"[logid:{logid}] Regex comparison |{labels_re}| |{str(pod.metadata.labels)}|") + # logging.debug(f"[logid:{logid}] Regex comparison |{annotations_re}| |{str(pod.metadata.annotations)}|") if re.search(f"{pod_re}", pod.metadata.name) or re.search(r"{pod_re}", pod.metadata.name): - logging.debug(f"[logid:{logid}] Regex comparison |{pod_re}| |{pod.metadata.name}| RESULT: OK") + #logging.debug(f"[logid:{logid}] Regex comparison |{pod_re}| |{pod.metadata.name}| RESULT: OK") regex_key_name = f"regex_cmp:{regexsha}:{regexsha}:{logid}:{pod.metadata.namespace}:{pod.metadata.name}" if re.search(f"{namespace_re}", pod.metadata.namespace) or re.search(r"{namespace_re}", pod.metadata.namespace): - logging.debug(f"[logid:{logid}] Regex comparison |{namespace_re}| |{pod.metadata.namespace}| RESULT: OK") + #logging.debug(f"[logid:{logid}] Regex comparison |{namespace_re}| |{pod.metadata.namespace}| RESULT: OK") if re.search(f"{labels_re}", str(pod.metadata.labels)) or re.search(r"{labels_re}", str(pod.metadata.labels)): - logging.debug(f"[logid:{logid}] Regex comparison |{labels_re}| |{str(pod.metadata.labels)}| RESULT: OK") + #logging.debug(f"[logid:{logid}] Regex comparison |{labels_re}| |{str(pod.metadata.labels)}| RESULT: OK") if re.search(f"{annotations_re}", str(pod.metadata.annotations)) or re.search(r"{annotations_re}", str(pod.metadata.annotations)): - logging.debug(f"[logid:{logid}] Regex comparison |{annotations_re}| |{str(pod.metadata.annotations)}| RESULT: OK") + #logging.debug(f"[logid:{logid}] Regex comparison |{annotations_re}| |{str(pod.metadata.annotations)}| RESULT: OK") webtail_pods.append(pod) regex_match_info = f"[logid:{logid}] Taking logs from {pod.metadata.name}. It is compliant with the Regex {log_pod_regex}" r.set(regex_key_name, "maching") - logging.debug(regex_match_info) + #logging.debug(regex_match_info) r.set(f"log_status:{logid}", regex_match_info) else: - logging.debug(f"[logid:{logid}] Regex comparison |{annotations_re}| |{str(pod.metadata.annotations)}| RESULT FAILED!") + #logging.debug(f"[logid:{logid}] Regex comparison |{annotations_re}| |{str(pod.metadata.annotations)}| RESULT FAILED!") r.set(regex_key_name, "not_maching") else: - logging.debug(f"[logid:{logid}] Regex comparison |{labels_re}| |{str(pod.metadata.labels)}| RESULT: FAILED!") + #logging.debug(f"[logid:{logid}] Regex comparison |{labels_re}| |{str(pod.metadata.labels)}| RESULT: FAILED!") r.set(regex_key_name, "not_maching") else: - logging.debug(f"[logid:{logid}] Regex comparison |{namespace_re}| |{pod.metadata.namespace}| RESULT: FAILED!") + #logging.debug(f"[logid:{logid}] Regex comparison |{namespace_re}| |{pod.metadata.namespace}| RESULT: FAILED!") r.set(regex_key_name, "not_maching") else: - logging.debug(f"[logid:{logid}] Regex comparison |{pod_re}| |{pod.metadata.name}| RESULT FAILED!") + #logging.debug(f"[logid:{logid}] Regex comparison |{pod_re}| |{pod.metadata.name}| RESULT FAILED!") r.set(regex_key_name, "not_maching") try: