improvements

This commit is contained in:
Eugenio Marzo
2023-01-07 16:50:22 +01:00
parent b84d105890
commit e1aa9def3b
15 changed files with 53 additions and 25 deletions
+3
View File
@@ -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"]
@@ -0,0 +1,4 @@
#!/bin/bash
docker build . -t docker.io/luckysideburn/kubeinvaders:develop_local
docker push docker.io/luckysideburn/kubeinvaders:develop_local
+14
View File
@@ -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
+10 -3
View File
@@ -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
+22 -22
View File
@@ -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: