mirror of
https://github.com/lucky-sideburn/kubeinvaders.git
synced 2026-08-23 21:46:21 +00:00
fix
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
docker system prune -a -f
|
||||
docker build . -t docker.io/luckysideburn/kubeinvaders:develop
|
||||
docker push luckysideburn/kubeinvaders:develop
|
||||
kubectl create namespace kubeinvaders
|
||||
|
||||
@@ -207,7 +207,7 @@ function enableLogTail() {
|
||||
|
||||
function disableLogTail() {
|
||||
var oReq = new XMLHttpRequest();
|
||||
oReq.open("POST", "https://" + clu_endpoint + "/kube/chaos/containers?action=disable_log_tail=id" + random_code, true);
|
||||
oReq.open("POST", "https://" + clu_endpoint + "/kube/chaos/containers?action=disable_log_tail&id=" + random_code, true);
|
||||
oReq.onreadystatechange = function () {
|
||||
if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
|
||||
$('#alert_placeholder3').replaceWith(log_tail_alert + 'Logs tail stopped </div>');
|
||||
@@ -222,7 +222,7 @@ function setLogRegex() {
|
||||
log_tail_div.style.display = "block";
|
||||
$('#alert_placeholder3').replaceWith(log_tail_alert + 'Setting regex for filtering log source (by pod name)</div>');
|
||||
var oReq = new XMLHttpRequest();
|
||||
oReq.open("POST", "https://" + clu_endpoint + "/kube/chaos/containers?action=set_log_regex", true);
|
||||
oReq.open("POST", "https://" + clu_endpoint + "/kube/chaos/containers?action=set_log_regex&id=" + random_code, true);
|
||||
oReq.onreadystatechange = function () {
|
||||
if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
|
||||
$('#alert_placeholder3').replaceWith(log_tail_alert + 'Regex has been configured...</div>');
|
||||
|
||||
@@ -37,20 +37,20 @@ 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.html")
|
||||
--os.execute("> /var/www/html/chaoslogs" .. arg['id'] .. ".html")
|
||||
ngx.say("New container definition has been saved in Redis => " .. body_data)
|
||||
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.html")
|
||||
--os.execute("> /var/www/html/chaoslogs" .. arg['id'] .. ".html")
|
||||
ngx.say("Enable Log Tail")
|
||||
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.html")
|
||||
--os.execute("> /var/www/html/chaoslogs" .. arg['id'] .. ".html")
|
||||
ngx.say("Disable Log Tail")
|
||||
return ngx.exit(ngx.status)
|
||||
end
|
||||
|
||||
+22
-20
@@ -16,15 +16,17 @@ import time
|
||||
import re
|
||||
from hashlib import sha256
|
||||
import time
|
||||
import urllib3
|
||||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||
|
||||
def line_prepender(filename, line):
|
||||
def line_prepender(filename, line, logid):
|
||||
log_html_file = pathlib.Path(filename)
|
||||
if not log_html_file.exists():
|
||||
with open(log_html_file, "w") as myfile:
|
||||
myfile.write('')
|
||||
for key in r.scan_iter("log_time:*"):
|
||||
for key in r.scan_iter(f"log_time:{logid}:*"):
|
||||
r.delete(key)
|
||||
for key in r.scan_iter("log:*"):
|
||||
for key in r.scan_iter(f"log:{logid}:*"):
|
||||
r.delete(key)
|
||||
with open(filename, 'r+') as f:
|
||||
content = f.read()
|
||||
@@ -44,21 +46,10 @@ else:
|
||||
|
||||
if os.environ.get("DEV"):
|
||||
logging.info("Setting env var for dev...")
|
||||
r.set("log_pod_regex", ".*")
|
||||
r.set("logs_enabled", 1)
|
||||
logging.info(r.get("log_pod_regex"))
|
||||
logging.info(r.get("logs_enabled"))
|
||||
|
||||
if r.exists("log_pod_regex"):
|
||||
logging.info("The Redis key log_pod_regex exists...")
|
||||
else:
|
||||
logging.info("The Redis key log_pod_regex does NOT exists...")
|
||||
r.set("log_pod_regex", '{"pod":".*", "namespace":".*", "labels":".*", "annotations":".*"}')
|
||||
|
||||
if r.exists('logs_enabled'):
|
||||
logging.info("The Redis key logs_enabled exists...")
|
||||
else:
|
||||
logging.info("The Redis key logs_enabled does NOT exists...")
|
||||
r.set("log_pod_regex", '{"pod":".*", "namespace":".*", "labels":".*", "annotations":".*"}')
|
||||
r.set("logs_enabled:aaaa", 1)
|
||||
logging.info(r.get("log_pod_regex:aaaa"))
|
||||
logging.info(r.get("logs_enabled:aaaa"))
|
||||
|
||||
configuration = client.Configuration()
|
||||
token = os.environ["TOKEN"]
|
||||
@@ -80,6 +71,17 @@ for key in r.scan_iter("logs_enabled:*"):
|
||||
|
||||
logid = key.split(":")[1]
|
||||
|
||||
if r.exists(f"log_pod_regex:{logid}"):
|
||||
logging.info(f"[logid:{logid}] The Redis key log_pod_regex exists...")
|
||||
else:
|
||||
logging.info(f"[logid:{logid}] The Redis key log_pod_regex does NOT exists...")
|
||||
r.set(f"log_pod_regex:{logid}", '{"pod":".*", "namespace":".*", "labels":".*", "annotations":".*"}')
|
||||
|
||||
if r.exists(f"logs_enabled:{logid}"):
|
||||
logging.info(f"[logid:{logid}] The Redis key logs_enabled exists...")
|
||||
else:
|
||||
logging.info(f"[logid:{logid}]The Redis key logs_enabled does NOT exists...")
|
||||
|
||||
while True:
|
||||
if not r.exists("log_cleaner:{logid}"):
|
||||
if pathlib.Path(f"/var/www/html/chaoslogs{logid}.html").exists():
|
||||
@@ -102,7 +104,7 @@ for key in r.scan_iter("logs_enabled:*"):
|
||||
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")
|
||||
|
||||
log_pod_regex = r.get(f"log_pod_regex:{logid]}")
|
||||
log_pod_regex = r.get(f"log_pod_regex:{logid}")
|
||||
|
||||
logging.info(f"[logid:{logid}] log_pod_regex is => |{log_pod_regex}|")
|
||||
|
||||
@@ -180,7 +182,7 @@ for key in r.scan_iter("logs_enabled:*"):
|
||||
file = pathlib.Path('/var/www/html')
|
||||
if file.exists():
|
||||
log_html_file = pathlib.Path(f"/var/www/html/chaoslogs{logid}.html")
|
||||
line_prepender(log_html_file, logrow)
|
||||
line_prepender(log_html_file, logrow, logid)
|
||||
|
||||
r.set(f"log:{logid}{pod.metadata.name}:{sha256log}", logrow)
|
||||
r.set(f"log_time:{logid}:{pod.metadata.name}", time.time())
|
||||
|
||||
@@ -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}
|
||||
python3 /opt/logs_loop/start.py https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT_HTTPS} &> /tmp/foo.log
|
||||
|
||||
@@ -11,6 +11,8 @@ import string
|
||||
import random
|
||||
import redis
|
||||
import time
|
||||
import urllib3
|
||||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||
|
||||
def create_container(image, name, command, args):
|
||||
container = client.V1Container(
|
||||
|
||||
Reference in New Issue
Block a user