diff --git a/entrypoint.sh b/entrypoint.sh index bf93d05..920c6e3 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,4 +1,5 @@ -#!/bin/sh +#!/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 @@ -7,11 +8,7 @@ else export TOKEN="$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" fi -# TODO: use a sidecar redis-server /etc/redis/redis.conf & bash /opt/metrics_loop/start.sh & bash /opt/logs_loop/start.sh & - -echo '
waiting for logs...
' > /var/www/html/chaoslogs.html - nginx -c /etc/nginx/nginx.conf -g 'daemon off;' diff --git a/html5/kubeinvaders.js b/html5/kubeinvaders.js index 6b80a5d..6e7d0f4 100644 --- a/html5/kubeinvaders.js +++ b/html5/kubeinvaders.js @@ -10,6 +10,16 @@ var spaceshipWidth = 60; var spaceshipX = (canvas.width-spaceshipWidth)/2; var spaceshipY = (canvas.height-spaceshipHeight)/2; var clu_endpoint = "endpoint_placeholder"; +var clu_insicure = "insecure_endpoint_placeholder"; +var k8s_url = ""; + +if (clu_insicure == "true") { + k8s_url = "http://" + clu_endpoint; +} +else { + k8s_url = "https://" + clu_endpoint; +} + var namespaces = []; var namespaces_index = 0; var namespace = namespaces[namespaces_index]; @@ -110,7 +120,7 @@ function getCodeName() { } } };; - oReq.open("GET", "https://" + clu_endpoint + "/codename"); + oReq.open("GET", k8s_url + "/codename"); oReq.send(); } @@ -135,7 +145,7 @@ function getSavedPresets() { } } };; - oReq.open("GET", "https://" + clu_endpoint + "/chaos/loadpreset/savedpresets"); + oReq.open("GET", k8s_url + "/chaos/loadpreset/savedpresets"); oReq.send(); } @@ -151,7 +161,7 @@ function loadSavedPreset(tool, lang, defaultpreset) { } } };; - oReq.open("GET", "https://" + clu_endpoint + "/chaos/loadpreset?name=" + tool + "&lang=" + lang); + oReq.open("GET", k8s_url + "/chaos/loadpreset?name=" + tool + "&lang=" + lang); oReq.send() var now = new Date().toLocaleString().replace(',','') $('#alert_placeholder_programming_mode').replaceWith(alert_div + '[' + now + '] Open preset for ' + tool + ''); @@ -176,7 +186,7 @@ function resetPreset() { } };; - oReq.open("POST", "https://" + clu_endpoint + "/chaos/loadpreset/reset?name="+ latest_preset_name + "&lang="+ latest_preset_lang); + oReq.open("POST", k8s_url + "/chaos/loadpreset/reset?name="+ latest_preset_name + "&lang="+ latest_preset_lang); oReq.send({}); } @@ -189,7 +199,7 @@ function savePreset(action) { //console.log("Saving preset. name:" + presetName + ", lang:" + presetName + ", body: " + presetBody); var oReq = new XMLHttpRequest(); - oReq.open("POST", "https://" + clu_endpoint + "/chaos/loadpreset/save?name=" + presetName + "&lang=" + presetLang, true); + oReq.open("POST", k8s_url + "/chaos/loadpreset/save?name=" + presetName + "&lang=" + presetLang, true); oReq.onreadystatechange = function () { if (this.readyState === XMLHttpRequest.DONE && this.status === 200 && action == "apply") { @@ -235,7 +245,7 @@ function drawChaosProgramFlow() { // $('#chaosProgramTextArea').val(chaosProgramWithCodename); var oReq = new XMLHttpRequest(); - oReq.open("POST", "https://" + clu_endpoint + "/chaos/programs/json-flow", true); + oReq.open("POST", k8s_url + "/chaos/programs/json-flow", true); oReq.onreadystatechange = function () { if (this.readyState === XMLHttpRequest.DONE && this.status === 200) { @@ -335,7 +345,7 @@ function getMetrics() { } } };; - oReq.open("GET", "https://" + clu_endpoint + "/metrics"); + oReq.open("GET", k8s_url + "/metrics"); oReq.send(); } @@ -349,7 +359,7 @@ function getChaosJobsLogs() { } } };; - oReq.open("GET", "https://" + clu_endpoint + "/chaoslogs-" + random_code + ".html"); + oReq.open("GET", k8s_url + "/chaoslogs-" + random_code + ".html"); oReq.send(); keepAliveJobsLogs(); } @@ -363,7 +373,7 @@ function keepAliveJobsLogs() { } } };; - oReq.open("GET", "https://" + clu_endpoint + "/chaos/logs/keepalive?logid=" + random_code); + oReq.open("GET", k8s_url + "/chaos/logs/keepalive?logid=" + random_code); oReq.send(); } @@ -376,7 +386,7 @@ function runKubeLinter() { result_parsed = JSON.stringify(JSON.parse(kubelinter), null, 4); $('#currentKubeLinterResult').text(result_parsed); };; - oReq.open("GET", "https://" + clu_endpoint + "/kube/kube-linter?namespace=" + namespace); + oReq.open("GET", k8s_url + "/kube/kube-linter?namespace=" + namespace); oReq.send(); } @@ -387,7 +397,7 @@ function getNamespaces() { namespaces = namespaces.split(","); namespace = namespaces[namespaces_index]; };; - oReq.open("GET", "https://" + clu_endpoint + "/kube/namespaces"); + oReq.open("GET", k8s_url + "/kube/namespaces"); oReq.send(); } @@ -396,7 +406,7 @@ function getEndpoint() { oReq.onload = function () { endpoint = this.responseText; };; - oReq.open("GET", "https://" + clu_endpoint + "/kube/endpoint"); + oReq.open("GET", k8s_url + "/kube/endpoint"); oReq.send(); } @@ -408,13 +418,13 @@ function getCurrentChaosContainer() { $('#currentChaosContainerYaml').text(job_parsed); $('#currentChaosContainerJsonTextArea').val(job_parsed); };; - oReq.open("GET", "https://" + clu_endpoint + "/kube/chaos/containers?action=container_definition"); + oReq.open("GET", k8s_url + "/kube/chaos/containers?action=container_definition"); oReq.send(); } function enableLogTail() { var oReq = new XMLHttpRequest(); - oReq.open("POST", "https://" + clu_endpoint + "/kube/chaos/containers?action=enable_log_tail&id=" + random_code, true); + oReq.open("POST", k8s_url + "/kube/chaos/containers?action=enable_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 started '); @@ -427,7 +437,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", k8s_url + "/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 '); @@ -442,7 +452,7 @@ function setLogRegex() { log_tail_div.style.display = "block"; $('#alert_placeholder3').replaceWith(log_tail_alert + 'Setting regex for filtering log source (by pod name)'); var oReq = new XMLHttpRequest(); - oReq.open("POST", "https://" + clu_endpoint + "/kube/chaos/containers?action=set_log_regex&id=" + random_code, true); + oReq.open("POST", k8s_url + "/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...'); @@ -458,7 +468,7 @@ function setChaosContainer() { } else { var oReq = new XMLHttpRequest(); - oReq.open("POST", "https://" + clu_endpoint + "/kube/chaos/containers?action=set", true); + oReq.open("POST", k8s_url + "/kube/chaos/containers?action=set", true); oReq.onreadystatechange = function () { if (this.readyState === XMLHttpRequest.DONE && this.status === 200) { @@ -481,7 +491,7 @@ function runChaosProgram() { $('#alert_placeholder4').replaceWith(alert_div + 'Chaos Program launched at ' + now + ' '); var oReq = new XMLHttpRequest(); - oReq.open("POST", "https://" + clu_endpoint + "/kube/chaos/programming_mode?id=" + random_code, true); + oReq.open("POST", k8s_url + "/kube/chaos/programming_mode?id=" + random_code, true); oReq.onreadystatechange = function () { if (this.readyState === XMLHttpRequest.DONE && this.status === 200) { //console.log(this.responseText); @@ -499,7 +509,7 @@ function startChaosNode(node_name) { //console.log(JSON.parse(this.responseText)) };; $('#alert_placeholder').replaceWith(alert_div + 'Latest action: Start Chaos Job on ' + node_name + ''); - oReq.open("GET", "https://" + clu_endpoint + "/kube/chaos/nodes?nodename=" + node_name + "&namespace=" + namespace); + oReq.open("GET", k8s_url + "/kube/chaos/nodes?nodename=" + node_name + "&namespace=" + namespace); oReq.send(); } @@ -509,7 +519,7 @@ function deletePods(pod_name) { //console.log(JSON.parse(this.responseText)) };; $('#alert_placeholder').replaceWith(alert_div + 'Latest action: Kill ' + pod_name + ''); - oReq.open("GET", "https://" + clu_endpoint + "/kube/pods?action=delete&pod_name=" + pod_name + "&namespace=" + namespace); + oReq.open("GET", k8s_url + "/kube/pods?action=delete&pod_name=" + pod_name + "&namespace=" + namespace); oReq.send(); } @@ -524,7 +534,7 @@ function getPods() { pods = json_parsed["items"]; } };; - oReq.open("GET", "https://" + clu_endpoint + "/kube/pods?action=list&namespace=" + namespace); + oReq.open("GET", k8s_url + "/kube/pods?action=list&namespace=" + namespace); oReq.send(); } else { @@ -543,7 +553,7 @@ function getNodes() { json_parsed = JSON.parse(this.responseText); nodes = json_parsed["items"]; };; - oReq.open("GET", "https://" + clu_endpoint + "/kube/nodes"); + oReq.open("GET", k8s_url + "/kube/nodes"); oReq.send(); } else { diff --git a/nginx/KubeInvaders.conf b/nginx/KubeInvaders.conf index fcf4659..6a47e20 100644 --- a/nginx/KubeInvaders.conf +++ b/nginx/KubeInvaders.conf @@ -1,10 +1,16 @@ # lua_package_path '/usr/share/lua/5.1/?.lua;;'; - server { listen 8080 default_server; root /var/www/html/; index index.html; - set_by_lua $endpoint 'return os.getenv("ENDPOINT")'; + + set_by_lua_block $endpoint { + return os.getenv("ENDPOINT") + } + + set_by_lua_block $insecure_endpoint { + return os.getenv("INSECURE_ENDPOINT") + } location / { add_header 'Access-Control-Allow-Origin' '*'; @@ -18,6 +24,7 @@ server { etag off; sub_filter_types "*"; sub_filter endpoint_placeholder $endpoint; + sub_filter insecure_endpoint_placeholder $insecure_endpoint; } location /kube/chaos/programming_mode { @@ -98,7 +105,7 @@ server { red:set("latest_codename", random_word) - ngx.log(ngx.ERR, "[programming_mode_codename] Choosing random word " .. random_word) + ngx.log(ngx.INFO, "[programming_mode_codename] Choosing random word " .. random_word) ngx.say(random_word) } @@ -232,7 +239,7 @@ server { ngx.req.read_body() local okredis, errredis = red:connect("unix:/tmp/redis.sock") local key_name = args["lang"] .. "_" .. args["name"] - ngx.log(ngx.ERR, "[PRESETS-RESET] The item " .. key_name .. " should be removed from the key presets_list") + ngx.log(ngx.INFO, "[PRESETS-RESET] The item " .. key_name .. " should be removed from the key presets_list") local handle = io.popen("redis-cli --scan --pattern " .. key_name .. " | xargs redis-cli del") local result = handle:read("*a") @@ -247,7 +254,7 @@ server { local new_preset_list = ""; local cnt = 0; for key, value in ipairs(mysplit(res, ",")) do - ngx.log(ngx.ERR, "[PRESETS-RESET] Split the key presets_list. Current preset is: " .. value) + ngx.log(ngx.INFO, "[PRESETS-RESET] Split the key presets_list. Current preset is: " .. value) if value ~= key_name then preset = value if cnt > 0 then @@ -258,7 +265,7 @@ server { end cnt = cnt + 1 end - ngx.log(ngx.ERR, "[PRESETS-RESET] New key presets_list is: " .. new_preset_list) + ngx.log(ngx.INFO, "[PRESETS-RESET] New key presets_list is: " .. new_preset_list) red:set("presets_list", new_preset_list) end } @@ -282,7 +289,7 @@ server { ngx.say(err) else ngx.say(res) - ngx.log(ngx.ERR, "[PRESETS_LIST] " .. res) + ngx.log(ngx.INFO, "[PRESETS_LIST] " .. res) end } } @@ -303,7 +310,7 @@ server { local all_presets_key = "" if data ~= nil then - ngx.log(ngx.ERR, "[SAVE-PRESETS] lang:" .. args["lang"] .. ", name:" .. args["name"] .. ", payload:" .. data) + ngx.log(ngx.INFO, "[SAVE-PRESETS] lang:" .. args["lang"] .. ", name:" .. args["name"] .. ", payload:" .. data) if (red:exists(key_name) == 0) then red:set(key_name, data) local res, err = red:get(key_name) @@ -367,13 +374,13 @@ server { ngx.header['Access-Control-Expose-Headers'] = 'Content-Length,Content-Range'; ngx.req.read_body() local data = ngx.req.get_body_data() - ngx.log(ngx.ERR, "[PROGRAMMING-MODE-DIAGRAM] data sent from web interface => " .. data) + ngx.log(ngx.INFO, "[PROGRAMMING-MODE-DIAGRAM] data sent from web interface => " .. data) math.randomseed(os.clock()*100000000000) local rand = math.random(999, 9999) local filename = "/tmp/chaosprogram" .. rand - ngx.log(ngx.ERR, "[PROGRAMMING-MODE-DIAGRAM] write temp file " .. filename) + ngx.log(ngx.INFO, "[PROGRAMMING-MODE-DIAGRAM] write temp file " .. filename) local yamlfile = io.open(filename, "w") yamlfile:write(data) @@ -383,16 +390,16 @@ server { local result = handle:read("*a") local rc = handle:close() - ngx.log(ngx.ERR, "[programming_mode_diagram] Result of yaml syntax check =>||" .. result .. "||") + ngx.log(ngx.INFO, "[programming_mode_diagram] Result of yaml syntax check =>||" .. result .. "||") if data == nil then error = "[PROGRAMMING-MODE-DIAGRAM] No chaos program already loaded." - ngx.log(ngx.ERR, error) + ngx.log(ngx.INFO, error) ngx.say(error) elseif not string.match(result, '{.*}') then error = "[PROGRAMMING-MODE-DIAGRAM] Chaos program seems not correct. Please check yaml syntax." - ngx.log(ngx.ERR, error) + ngx.log(ngx.INFO, error) ngx.say(error) end @@ -400,22 +407,22 @@ server { if not key_exists(yaml_data, "jobs") then error = "[PROGRAMMING-MODE-DIAGRAM] Chaos program does not contain 'jobs' key. Please fix yaml definition." - ngx.log(ngx.ERR, error) + ngx.log(ngx.INFO, error) ngx.say(error) elseif not key_exists(yaml_data, "experiments") then error = "[PROGRAMMING-MODE-DIAGRAM] Chaos program does not contain 'experiments' key. Please fix yaml definition" - ngx.log(ngx.ERR, error) + ngx.log(ngx.INFO, error) ngx.say(error) elseif is_key_empty(yaml_data, "jobs") then error = "[PROGRAMMING-MODE-DIAGRAM] Chaos program does not contain valid 'jobs' key. Please fix yaml definition, add jobs" - ngx.log(ngx.ERR, error) + ngx.log(ngx.INFO, error) ngx.say(error) elseif is_key_empty(yaml_data, "experiments") then error = "[PROGRAMMING-MODE-DIAGRAM] Chaos program does not contain valid 'experiments' key. Please fix yaml definition, add experiments" - ngx.log(ngx.ERR, error) + ngx.log(ngx.INFO, error) ngx.say(error) else diff --git a/nginx/nginx.conf b/nginx/nginx.conf index 3e4d51e..ae840b2 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -7,6 +7,7 @@ env ENDPOINT; env NAMESPACE; env KUBERNETES_SERVICE_HOST; env KUBERNETES_SERVICE_PORT_HTTPS; +env INSECURE_ENDPOINT; events { worker_connections 1024; diff --git a/scripts/chaos-containers.lua b/scripts/chaos-containers.lua index c4979be..8d33f96 100644 --- a/scripts/chaos-containers.lua +++ b/scripts/chaos-containers.lua @@ -6,10 +6,10 @@ local red = redis:new() local okredis, errredis = red:connect("unix:/tmp/redis.sock") if okredis then - ngx.log(ngx.ERR, "Connection to Redis is ok") + ngx.log(ngx.INFO, "Connection to Redis is ok") else - ngx.log(ngx.ERR, "Connection to Redis is not ok") - ngx.log(ngx.ERR, errredis) + ngx.log(ngx.INFO, "Connection to Redis is not ok") + ngx.log(ngx.INFO, errredis) end ngx.header['Access-Control-Allow-Origin'] = '*' @@ -18,18 +18,18 @@ ngx.header['Access-Control-Allow-Headers'] = 'DNT,User-Agent,X-Requested-With,If ngx.header['Access-Control-Expose-Headers'] = 'Content-Length,Content-Range' if ngx.var.request_method == "GET" and action == 'container_definition' then - ngx.log(ngx.ERR, "Received request for getting chaos container definition") + ngx.log(ngx.INFO, "Received request for getting chaos container definition") local res, err = red:get("chaos_container") if res == ngx.null then - ngx.log(ngx.ERR, "There is no chaos_container key set in Redis. Taking default chaos container definition") + ngx.log(ngx.INFO, "There is no chaos_container key set in Redis. Taking default chaos container definition") ngx.say(config['default_chaos_container']) else - ngx.log(ngx.ERR, "There is chaos_container key set in Redis. Taking custom chaos container definition") + ngx.log(ngx.INFO, "There is chaos_container key set in Redis. Taking custom chaos container definition") ngx.say(res) end elseif ngx.var.request_method == "POST" and action == 'set' then local body_data = ngx.req.get_body_data() - ngx.log(ngx.ERR, "Received new yaml definition for chaos container: " .. body_data) + ngx.log(ngx.INFO, "Received new yaml definition for chaos container: " .. body_data) red:set("chaos_container", body_data) ngx.say("New chaos container definition has been configured in Redis") return ngx.exit(ngx.status) @@ -39,7 +39,7 @@ elseif ngx.var.request_method == "POST" and action == "set_log_regex" then red:set("log_pod_regex:" .. arg['id'], body_data) red:set("programming_mode", "0") ngx.say("Regex has been set => " .. body_data) - ngx.log(ngx.ERR, "Set Regex for web log tail. Log id " .. arg['id']) + ngx.log(ngx.INFO, "Set Regex for web log tail. Log id " .. arg['id']) --local redis_del_cmd = "(redis-cli KEYS 'regex_cmp:'" .. arg['id'] .. "| xargs redis-cli DEL) || echo" --local handle = io.popen(redis_del_cmd) --local result = handle:read("*a") @@ -51,13 +51,13 @@ elseif ngx.var.request_method == "POST" and action == "enable_log_tail" then red:set("logs_enabled:" .. arg['id'], "1") red:expire("logs_enabled:" .. arg['id'], "10") red:set("programming_mode", "0") - ngx.log(ngx.ERR, "Enable Log Tail for log id " .. arg['id']) + ngx.log(ngx.INFO, "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("programming_mode", "0") ngx.say("Disable Log Tail for log id " .. arg['id']) - ngx.log(ngx.ERR, "Disable Log Tail for log id " .. arg['id']) + ngx.log(ngx.INFO, "Disable Log Tail for log id " .. arg['id']) return ngx.exit(ngx.status) end diff --git a/scripts/chaos-node.lua b/scripts/chaos-node.lua index 10daf8b..a8fdf66 100644 --- a/scripts/chaos-node.lua +++ b/scripts/chaos-node.lua @@ -39,10 +39,10 @@ local resp = {} if ngx.var.request_method == "GET" then if okredis then - ngx.log(ngx.ERR, "Connection to Redis is ok") + ngx.log(ngx.INFO, "Connection to Redis is ok") else - ngx.log(ngx.ERR, "Connection to Redis is not ok") - ngx.log(ngx.ERR, errredis) + ngx.log(ngx.INFO, "Connection to Redis is not ok") + ngx.log(ngx.INFO, errredis) end -- Count the total of chaos jobs launched against nodes local chaos_node_res, err = red:get("chaos_node_jobs_total") @@ -81,11 +81,11 @@ headers = { local res, err = red:get("chaos_container") if res ~= ngx.null then - ngx.log(ngx.ERR, "Found chaos_container defined in Redis!") - ngx.log(ngx.ERR, res) + ngx.log(ngx.INFO, "Found chaos_container defined in Redis!") + ngx.log(ngx.INFO, res) chaos_container = res else - ngx.log(ngx.ERR, "Using default chaos container") + ngx.log(ngx.INFO, "Using default chaos container") chaos_container = config["default_chaos_container"] end @@ -126,7 +126,7 @@ local headers2 = { } url = k8s_url .. "/apis/batch/v1/namespaces/" .. namespace .. "/jobs" -ngx.log(ngx.ERR, "Creating chaos_node job kubeinvaders-chaos-" ..rand) +ngx.log(ngx.INFO, "Creating chaos_node job kubeinvaders-chaos-" ..rand) local ok, statusCode, headers, statusText = https.request{ url = url, @@ -136,12 +136,12 @@ local ok, statusCode, headers, statusText = https.request{ source = ltn12.source.string(body) } -ngx.log(ngx.ERR, ok) -ngx.log(ngx.ERR, statusCode) -ngx.log(ngx.ERR, statusText) +ngx.log(ngx.INFO, ok) +ngx.log(ngx.INFO, statusCode) +ngx.log(ngx.INFO, statusText) local url = k8s_url.. "/apis/batch/v1/namespaces/" .. namespace .. "/jobs" -ngx.log(ngx.ERR, "Getting JobList" .. rand) +ngx.log(ngx.INFO, "Getting JobList" .. rand) local ok, statusCode, headers, statusText = https.request{ url = url, @@ -150,9 +150,9 @@ local ok, statusCode, headers, statusText = https.request{ sink = ltn12.sink.table(resp) } -ngx.log(ngx.ERR, ok) -ngx.log(ngx.ERR, statusCode) -ngx.log(ngx.ERR, statusText) +ngx.log(ngx.INFO, ok) +ngx.log(ngx.INFO, statusCode) +ngx.log(ngx.INFO, statusText) for k,v in ipairs(resp) do decoded = json.decode(v) @@ -160,14 +160,14 @@ for k,v in ipairs(resp) do for k2,v2 in ipairs(decoded["items"]) do if v2["status"]["succeeded"] == 1 and v2["metadata"]["labels"]["approle"] == "chaosnode" then delete_job = "kubectl delete job " .. v2["metadata"]["name"] .. " --token=" .. token .. " --server=" .. k8s_url .. " --insecure-skip-tls-verify=true -n " .. namespace - ngx.log(ngx.ERR, delete_pod) + ngx.log(ngx.INFO, delete_pod) end end end end local url = k8s_url.. "/api/v1/namespaces/" .. namespace .. "/pods" -ngx.log(ngx.ERR, "Getting PodList" .. rand) +ngx.log(ngx.INFO, "Getting PodList" .. rand) local ok, statusCode, headers, statusText = https.request{ url = url, @@ -176,9 +176,9 @@ local ok, statusCode, headers, statusText = https.request{ sink = ltn12.sink.table(resp) } -ngx.log(ngx.ERR, ok) -ngx.log(ngx.ERR, statusCode) -ngx.log(ngx.ERR, statusText) +ngx.log(ngx.INFO, ok) +ngx.log(ngx.INFO, statusCode) +ngx.log(ngx.INFO, statusText) for k,v in ipairs(resp) do decoded = json.decode(v) @@ -186,7 +186,7 @@ for k,v in ipairs(resp) do for k2,v2 in ipairs(decoded["items"]) do if v2["status"]["phase"] == "Succeeded" and v2["metadata"]["labels"]["approle"] == "chaosnode" then delete_pod = "kubectl delete pod " .. v2["metadata"]["name"] .. " --token=" .. token .. " --server=" .. k8s_url .. " --insecure-skip-tls-verify=true -n " .. namespace - ngx.log(ngx.ERR, delete_pod) + ngx.log(ngx.INFO, delete_pod) end end end diff --git a/scripts/logs_loop/start.sh b/scripts/logs_loop/start.sh index 6ff4757..e76e52b 100755 --- a/scripts/logs_loop/start.sh +++ b/scripts/logs_loop/start.sh @@ -11,7 +11,6 @@ export PYTHONWARNINGS="ignore:Unverified HTTPS request" python3 /opt/logs_loop/start.py https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT_HTTPS} & -# WORK AROUND... while true do ( ps -ef | grep start.py | grep logs_loop | grep -v grep ) || ( python3 /opt/logs_loop/start.py https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT_HTTPS} & ) diff --git a/scripts/metrics.lua b/scripts/metrics.lua index 640a10e..2b24c19 100644 --- a/scripts/metrics.lua +++ b/scripts/metrics.lua @@ -9,10 +9,10 @@ if ngx.var.request_method == "GET" and string.match(ngx.var.request_uri, "^.*/ch local okredis, errredis = red:connect("unix:/tmp/redis.sock") if okredis then - ngx.log(ngx.ERR, "Connection to Redis is ok") + ngx.log(ngx.INFO, "Connection to Redis is ok") else - ngx.log(ngx.ERR, "Connection to Redis is not ok") - ngx.log(ngx.ERR, errredis) + ngx.log(ngx.INFO, "Connection to Redis is not ok") + ngx.log(ngx.INFO, errredis) end -- Count the total of chaos jobs launched against nodes local chaos_node_res, err = red:get("chaos_node_jobs_total") @@ -38,7 +38,7 @@ if ngx.var.request_method == "GET" and string.match(ngx.var.request_uri, "^.*/ch elseif ngx.var.request_method == "GET" and ngx.var.request_uri == "/metrics" then for i, res in ipairs(red:keys("*")) do - ngx.log(ngx.ERR, res) + ngx.log(ngx.INFO, res) ngx.say(res .. " " .. red:get(res)) end end diff --git a/scripts/node.lua b/scripts/node.lua index 60c1aa3..079f7f6 100644 --- a/scripts/node.lua +++ b/scripts/node.lua @@ -23,10 +23,10 @@ if ngx.var.request_method == "GET" and string.match(ngx.var.request_uri, "^.*/ch local okredis, errredis = red:connect("unix:/tmp/redis.sock") if okredis then - ngx.log(ngx.ERR, "Connection to Redis is ok") + ngx.log(ngx.INFO, "Connection to Redis is ok") else - ngx.log(ngx.ERR, "Connection to Redis is not ok") - ngx.log(ngx.ERR, errredis) + ngx.log(ngx.INFO, "Connection to Redis is not ok") + ngx.log(ngx.INFO, errredis) end -- Count the total of chaos jobs launched against nodes local chaos_node_res, err = red:get("chaos_node_jobs_total") @@ -57,7 +57,7 @@ ngx.header['Access-Control-Allow-Methods'] = 'GET, POST, OPTIONS' ngx.header['Access-Control-Allow-Headers'] = 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' ngx.header['Access-Control-Expose-Headers'] = 'Content-Length,Content-Range'; -ngx.log(ngx.ERR, "Requesting nodes using this url: " .. url) +ngx.log(ngx.INFO, "Requesting nodes using this url: " .. url) local headers = { ["Accept"] = "application/json", @@ -74,20 +74,20 @@ local ok, statusCode, headers, statusText = https.request{ sink = ltn12.sink.table(resp) } -ngx.log(ngx.ERR, "REQUEST LOGS...") -ngx.log(ngx.ERR, ok) -ngx.log(ngx.ERR, statusCode) -ngx.log(ngx.ERR, statusText) +ngx.log(ngx.INFO, "REQUEST LOGS...") +ngx.log(ngx.INFO, ok) +ngx.log(ngx.INFO, statusCode) +ngx.log(ngx.INFO, statusText) nodes["items"] = {} for k,v in ipairs(resp) do - ngx.log(ngx.ERR, k) + ngx.log(ngx.INFO, k) decoded = json.decode(v) if decoded["kind"] == "NodeList" then for k2,v2 in ipairs(decoded["items"]) do -- TODO: masters should be included? -- if not v2["metadata"]["labels"]["node-role.kubernetes.io/master"] then - ngx.log(ngx.ERR, "found node " .. v2["metadata"]["name"]) + ngx.log(ngx.INFO, "found node " .. v2["metadata"]["name"]) table.insert(nodes["items"], v2["metadata"]["name"]) --end end diff --git a/scripts/pod.lua b/scripts/pod.lua index f3c0f59..ef0493a 100644 --- a/scripts/pod.lua +++ b/scripts/pod.lua @@ -32,10 +32,10 @@ if action == "delete" then local okredis, errredis = red:connect("unix:/tmp/redis.sock") if okredis then - ngx.log(ngx.ERR, "Connection to Redis is ok") + ngx.log(ngx.INFO, "Connection to Redis is ok") else - ngx.log(ngx.ERR, "Connection to Redis is not ok") - ngx.log(ngx.ERR, errredis) + ngx.log(ngx.INFO, "Connection to Redis is not ok") + ngx.log(ngx.INFO, errredis) end -- Count the total of deleted pods @@ -43,11 +43,11 @@ if action == "delete" then if res == ngx.null then ngx.say(err) - ngx.log(ngx.ERR, "deleted_pods_total is not present on Redis. Creating it..") + ngx.log(ngx.INFO, "deleted_pods_total is not present on Redis. Creating it..") red:set("deleted_pods_total", 1) else incr = res + 1 - ngx.log(ngx.ERR, "deleted_pods_total is present on Redis. Incrementing it..") + ngx.log(ngx.INFO, "deleted_pods_total is present on Redis. Incrementing it..") red:set("deleted_pods_total", incr) end @@ -75,9 +75,9 @@ else ngx.exit(ngx.OK) end ---ngx.log(ngx.ERR, "token: " .. token) -ngx.log(ngx.ERR, "url: " .. url) -ngx.log(ngx.ERR, "namespace: " .. namespace) +--ngx.log(ngx.INFO, "token: " .. token) +ngx.log(ngx.INFO, "url: " .. url) +ngx.log(ngx.INFO, "namespace: " .. namespace) local headers = { ["Accept"] = "application/json", @@ -94,10 +94,10 @@ local ok, statusCode, headers, statusText = https.request{ sink = ltn12.sink.table(resp) } -ngx.log(ngx.ERR, "REQUEST LOGS...") -ngx.log(ngx.ERR, ok) -ngx.log(ngx.ERR, statusCode) -ngx.log(ngx.ERR, statusText) +ngx.log(ngx.INFO, "REQUEST LOGS...") +ngx.log(ngx.INFO, ok) +ngx.log(ngx.INFO, statusCode) +ngx.log(ngx.INFO, statusText) if action == "list" then local i = 1 @@ -108,7 +108,7 @@ if action == "list" then if decoded["kind"] == "PodList" then for k2,v2 in ipairs(decoded["items"]) do if v2["status"]["phase"] == "Running" and v2["metadata"]["labels"]["approle"] ~= "chaosnode" then - ngx.log(ngx.ERR, "found pod " .. v2["metadata"]["name"]) + ngx.log(ngx.INFO, "found pod " .. v2["metadata"]["name"]) pods["items"][i] = v2["metadata"]["name"] i = i + 1 pods_not_found = false; @@ -130,7 +130,7 @@ if action == "list" then local latest_fewer_replicas_seconds, err = red:get("latest_fewer_replicas_seconds") local fewer_replicas_time, err = red:get("fewer_replicas_time") - ngx.log(ngx.ERR, "[METRICS] pods_not_running_on=" .. pods_not_running_on) + ngx.log(ngx.INFO, "[METRICS] pods_not_running_on=" .. pods_not_running_on) if fewer_replicas_seconds == ngx.null then red:set("fewer_replicas_seconds", 0) @@ -156,7 +156,7 @@ if action == "list" then end if pods_not_found then - ngx.log(ngx.ERR, "No pods found into the namespace " .. namespace) + ngx.log(ngx.INFO, "No pods found into the namespace " .. namespace) ngx.say("{\"items\": []}") else ngx.say(json.encode(pods)) diff --git a/scripts/programming_mode.lua b/scripts/programming_mode.lua index 0d6adae..06b64f3 100644 --- a/scripts/programming_mode.lua +++ b/scripts/programming_mode.lua @@ -6,10 +6,10 @@ local red = redis:new() local okredis, errredis = red:connect("unix:/tmp/redis.sock") if okredis then - ngx.log(ngx.ERR, "Connection to Redis is ok") + ngx.log(ngx.INFO, "Connection to Redis is ok") else - ngx.log(ngx.ERR, "Connection to Redis is not ok") - ngx.log(ngx.ERR, errredis) + ngx.log(ngx.INFO, "Connection to Redis is not ok") + ngx.log(ngx.INFO, errredis) end local k8s_url = "" @@ -30,7 +30,7 @@ local token = os.getenv("TOKEN") local arg = ngx.req.get_uri_args() local body_data = ngx.req.get_body_data() -ngx.log(ngx.ERR, "[programming_mode]" .. body_data) +ngx.log(ngx.INFO, "[programming_mode]" .. body_data) math.randomseed(os.clock()*100000000000) local rand = math.random(999, 9999) @@ -40,13 +40,13 @@ io.output(file) io.write(body_data) io.close(file) -ngx.log(ngx.ERR, "[programming_mode] set programming_mode Redis key") +ngx.log(ngx.INFO, "[programming_mode] set programming_mode Redis key") red:set("programming_mode", "1") ---ngx.log(ngx.ERR, "[programming_mode] remove do_not_clean_log:" ..arg['id'] .. " Redis key") +--ngx.log(ngx.INFO, "[programming_mode] remove do_not_clean_log:" ..arg['id'] .. " Redis key") --red:del("do_not_clean_log:" .. arg['id']) -ngx.log(ngx.ERR, "[programming_mode] set logs_enabled:" .. arg['id'] .. " Redis key") +ngx.log(ngx.INFO, "[programming_mode] set logs_enabled:" .. arg['id'] .. " Redis key") red:set("logs_enabled:" .. arg['id'], "1") red:expire("logs_enabled:" .. arg['id'], "10")