added code for web tail

This commit is contained in:
Eugenio Marzo
2022-10-23 15:06:03 +02:00
parent 2ed91b41e6
commit 4ac7a8020f
4 changed files with 59 additions and 16 deletions
+6 -1
View File
@@ -33,9 +33,14 @@ elseif ngx.var.request_method == "POST" and action == 'set' then
red:set("chaos_container", body_data)
ngx.say("New chaos container definition has been configured in Redis")
return ngx.exit(ngx.status)
elseif ngx.var.request_method == "POST" and action == "set_log_pod_regex" then
elseif ngx.var.request_method == "POST" and action == "enabled_logs_tail" then
local body_data = ngx.req.get_body_data()
red:set("log_pod_regex", body_data)
red:set("logs_enabled", "1")
ngx.say("New container definition has been saved in Redis")
return ngx.exit(ngx.status)
elseif ngx.var.request_method == "POST" and action == "disabled_logs_tail" then
red:set("logs_enabled", "0")
ngx.say("New container definition has been saved in Redis")
return ngx.exit(ngx.status)
end
+13 -12
View File
@@ -49,18 +49,19 @@ namespace = "kubeinvaders"
while True:
webtail_pods = []
final_pod_list = []
if r.exists("log_pod_regex"):
logging.info("Found regex log_pod_regex in Redis. Logs from all pods should be collected")
log_pod_regex = r.get("log_pod_regex")
try:
api_response = api_instance.list_pod_for_all_namespaces()
except ApiException as e:
logging.info(e)
logging.info(f"Going to search pod compliant with the regex on {len(api_response.items)} pods")
for pod in api_response.items:
if re.search(f"{log_pod_regex}", pod.metadata.name):
webtail_pods.append(pod)
logging.info(f"Taking log of {pod.metadata.name} because it is compliant with the regex {log_pod_regex}")
if r.exists("log_pod_regex") and r.exists('logs_enabled')
if r.get("logs_enabled") == 1:
logging.info("Found regex log_pod_regex in Redis. Logs from all pods should be collected")
log_pod_regex = r.get("log_pod_regex")
try:
api_response = api_instance.list_pod_for_all_namespaces()
except ApiException as e:
logging.info(e)
logging.info(f"Going to search pod compliant with the regex on {len(api_response.items)} pods")
for pod in api_response.items:
if re.search(f"{log_pod_regex}", pod.metadata.name):
webtail_pods.append(pod)
logging.info(f"Taking log of {pod.metadata.name} because it is compliant with the regex {log_pod_regex}")
try:
api_response = api_instance.list_namespaced_pod(namespace="kubeinvaders")