mirror of
https://github.com/lucky-sideburn/kubeinvaders.git
synced 2026-02-14 17:50:00 +00:00
fix
This commit is contained in:
@@ -57,7 +57,8 @@ RUN pip3 install -r /opt/programming_mode/requirements.txt
|
||||
RUN pip3 install -r /opt/programming_mode/requirements.txt
|
||||
|
||||
COPY nginx/KubeInvaders.conf /etc/nginx/conf.d/KubeInvaders.conf
|
||||
RUN chmod g+rwx /var/cache/nginx /var/run /var/log/nginx /var/www/html /etc/nginx/conf.d
|
||||
RUN chmod g+rwx /var/cache/nginx /var/run /var/log/nginx /etc/nginx/conf.d
|
||||
RUN chmod 777 /var/www/html
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
|
||||
@@ -144,7 +144,7 @@ function getChaosJobsLogs() {
|
||||
}
|
||||
}
|
||||
};;
|
||||
oReq.open("GET", "https://" + clu_endpoint + "/chaoslogs" + random_code + ".html");
|
||||
oReq.open("GET", "https://" + clu_endpoint + "/chaoslogs-" + random_code + ".html");
|
||||
oReq.send();
|
||||
}
|
||||
|
||||
|
||||
@@ -37,20 +37,23 @@ elseif ngx.var.request_method == "POST" and action == 'set' then
|
||||
elseif ngx.var.request_method == "POST" and action == "set_log_regex" then
|
||||
local body_data = ngx.req.get_body_data()
|
||||
red:set("log_pod_regex:" .. arg['id'], body_data)
|
||||
--os.execute("> /var/www/html/chaoslogs" .. arg['id'] .. ".html")
|
||||
ngx.say("New container definition has been saved in Redis => " .. body_data)
|
||||
os.execute("> /var/www/html/chaoslogs-" .. arg['id'] .. ".html")
|
||||
ngx.say("Regex has been set => " .. body_data)
|
||||
ngx.log(ngx.ERR, "Set Regex for web log tail. log id " .. arg['id'])
|
||||
return ngx.exit(ngx.status)
|
||||
|
||||
elseif ngx.var.request_method == "POST" and action == "enable_log_tail" then
|
||||
local body_data = ngx.req.get_body_data()
|
||||
red:set("logs_enabled:" .. arg['id'], "1")
|
||||
--os.execute("> /var/www/html/chaoslogs" .. arg['id'] .. ".html")
|
||||
os.execute("> /var/www/html/chaoslogs-" .. arg['id'] .. ".html")
|
||||
ngx.log(ngx.ERR, "Enable Log Tail for log id " .. arg['id'])
|
||||
ngx.say("Enable Log Tail for log id " .. arg['id'])
|
||||
return ngx.exit(ngx.status)
|
||||
|
||||
elseif ngx.var.request_method == "POST" and action == "disable_log_tail" then
|
||||
red:set("logs_enabled:" .. arg['id'], "0")
|
||||
--os.execute("> /var/www/html/chaoslogs" .. arg['id'] .. ".html")
|
||||
os.execute("> /var/www/html/chaoslogs-" .. arg['id'] .. ".html")
|
||||
ngx.say("Disable Log Tail for log id " .. arg['id'])
|
||||
ngx.log(ngx.ERR, "Disable Log Tail for log id " .. arg['id'])
|
||||
return ngx.exit(ngx.status)
|
||||
end
|
||||
|
||||
@@ -20,15 +20,21 @@ import urllib3
|
||||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||
|
||||
def line_prepender(filename, line, logid):
|
||||
logging.info(f"[logid:{logid}] Entering in line_prepender function")
|
||||
log_html_file = pathlib.Path(filename)
|
||||
if not log_html_file.exists():
|
||||
logging.info(f"[logid:{logid}] {log_html_file} does not exists. Going to reset Redis keys")
|
||||
with open(log_html_file, "w") as myfile:
|
||||
logging.info(f"[logid:{logid}] {log_html_file.exists} does not exists. Create new blank file {log_html_file}")
|
||||
myfile.write('')
|
||||
for key in r.scan_iter(f"log_time:{logid}:*"):
|
||||
logging.info(f"[logid:{logid}] Delete key {key}")
|
||||
r.delete(key)
|
||||
for key in r.scan_iter(f"log:{logid}:*"):
|
||||
logging.info(f"[logid:{logid}] Delete key {key}")
|
||||
r.delete(key)
|
||||
with open(filename, 'r+') as f:
|
||||
logging.info(f"[logid:{logid}] Insert in the head of {filename} the line: {line}")
|
||||
content = f.read()
|
||||
f.seek(0, 0)
|
||||
f.write(line.rstrip('\r\n') + '\n' + content)
|
||||
@@ -84,14 +90,14 @@ for key in r.scan_iter("logs_enabled:*"):
|
||||
|
||||
while True:
|
||||
if not r.exists("log_cleaner:{logid}"):
|
||||
if pathlib.Path(f"/var/www/html/chaoslogs{logid}.html").exists():
|
||||
os.remove(f"/var/www/html/chaoslogs{logid}.html")
|
||||
if pathlib.Path(f"/var/www/html/chaoslogs-{logid}.html").exists():
|
||||
os.remove(f"/var/www/html/chaoslogs-{logid}.html")
|
||||
r.set(f"log_cleaner:{logid}", "1")
|
||||
r.expire(f"log_cleaner:{logid}", 30)
|
||||
|
||||
logging.info(f"Loop iteration for log id {logid}")
|
||||
|
||||
file = pathlib.Path(f"/var/www/html/chaoslogs{logid}.html")
|
||||
file = pathlib.Path(f"/var/www/html/chaoslogs-{logid}.html")
|
||||
|
||||
if not file.exists():
|
||||
for key in r.scan_iter(f"log:{logid}:*"):
|
||||
@@ -120,11 +126,11 @@ for key in r.scan_iter("logs_enabled:*"):
|
||||
annotations_re = json_re["annotations"]
|
||||
labels_re = json_re["labels"]
|
||||
|
||||
logging.info(f"Gobal Json Regex is #{json_re}")
|
||||
logging.info(f"Regex for pod name is #{pod_re}")
|
||||
logging.info(f"Regex namespace name #{namespace_re}")
|
||||
logging.info(f"Regex for labels is #{labels_re}")
|
||||
logging.info(f"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 re.search(f"{pod_re}", pod.metadata.name) and re.search(f"{namespace_re}", pod.metadata.namespace) and re.search(f"{labels_re}", str(pod.metadata.labels)) and re.search(f"{annotations_re}", str(pod.metadata.annotations)):
|
||||
@@ -179,9 +185,10 @@ for key in r.scan_iter("logs_enabled:*"):
|
||||
store = True
|
||||
|
||||
if not r.exists(f"log:{logid}:{pod.metadata.name}:{sha256log}") or store:
|
||||
logging.info(f"[logid:{logid}] The key log:{logid}:{pod.metadata.name}:{sha256log} does not exists. Preparing to store log content")
|
||||
file = pathlib.Path('/var/www/html')
|
||||
if file.exists():
|
||||
log_html_file = pathlib.Path(f"/var/www/html/chaoslogs{logid}.html")
|
||||
log_html_file = pathlib.Path(f"/var/www/html/chaoslogs-{logid}.html")
|
||||
line_prepender(log_html_file, logrow, logid)
|
||||
|
||||
r.set(f"log:{logid}{pod.metadata.name}:{sha256log}", logrow)
|
||||
|
||||
@@ -8,4 +8,4 @@ else
|
||||
export TOKEN="$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)"
|
||||
fi
|
||||
export PYTHONWARNINGS="ignore:Unverified HTTPS request"
|
||||
python3 /opt/logs_loop/start.py https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT_HTTPS} &> /tmp/foo.log
|
||||
python3 /opt/logs_loop/start.py https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT_HTTPS}
|
||||
|
||||
Reference in New Issue
Block a user