From df8b0a9049e6c643a9ec5586622a71ab0a2ed93c Mon Sep 17 00:00:00 2001 From: luckysideburn Date: Sun, 22 Dec 2024 18:49:11 +0000 Subject: [PATCH] developing kubevirt support --- html/index.html | 24 +++++++++-------- html/js/globalvars.js | 1 + html/js/kubeinvaders.js | 55 ++++++++++++++++++++++++-------------- scripts/ingress.lua | 58 ++++++++++++++++++----------------------- scripts/pod.lua | 1 - 5 files changed, 76 insertions(+), 63 deletions(-) diff --git a/html/index.html b/html/index.html index 6abac4801..f89eb56ab 100644 --- a/html/index.html +++ b/html/index.html @@ -59,7 +59,7 @@ .sidebar a { padding: 10px 15px; text-decoration: none; - font-size: 18px; + font-size: 16px; color: #ffffff; display: block; } @@ -67,7 +67,7 @@ .sidebar #gameModeButton{ padding: 10px 15px; text-decoration: none; - font-size: 18px; + font-size: 16px; color: #ffffff; display: block; } @@ -75,7 +75,7 @@ .sidebar #programmingModeButton{ padding: 10px 15px; text-decoration: none; - font-size: 18px; + font-size: 16px; color: #ffffff; display: block; } @@ -153,9 +153,9 @@ @@ -341,8 +341,9 @@

h => Activate or deactivate help
s => Activate or deactivate shuffle for aliens
n => Change namespace
- p => Activate or deactivate chaos engineering against pods
- c => Activate or deactivate chaos engineering against nodes + p => Activate or deactivate chaos engineering on pods
+ c => Activate or deactivate chaos engineering on nodes
+ v => Activate or deactivate chaos engineering on virtual machines (kubevirt)
@@ -694,7 +696,7 @@

-

version: 2024-12-22 11:38:01

+

version: 2024-12-22 18:48:13

diff --git a/html/js/globalvars.js b/html/js/globalvars.js index 695d0b25f..66ac55528 100644 --- a/html/js/globalvars.js +++ b/html/js/globalvars.js @@ -129,6 +129,7 @@ var shuffle = true; var help = false; var chaos_nodes = false; var chaos_pods = true; +var chaos_vms = false var log_tail_alert = ''); + + } + else { + chaos_vms = true + $('#alert_placeholder').replaceWith(alert_div + 'Latest action: Show Virtual Machines'); + } + } + else if (e.keyCode == 80) { if (chaos_pods) { chaos_pods = false; @@ -530,12 +547,12 @@ function drawAlien(alienX, alienY, name, status) { ctx.drawImage(image, alienX, alienY, 30, 40); ctx.fillText(name.substring(0, 10) + '..', alienX, alienY + 50); } - else if (virtualMachines.some((vm) => vm.name == name)) { - image.src = './images/k8s_node.png'; - ctx.font = '10px pixel'; - ctx.drawImage(image, alienX, alienY, 30, 40); - ctx.fillText(name.substring(0, 10) + '..', alienX, alienY + 50); - } + // else if (virtualMachines.some((vm) => vm.name == name)) { + // image.src = './images/k8s_node.png'; + // ctx.font = '10px pixel'; + // ctx.drawImage(image, alienX, alienY, 30, 40); + // ctx.fillText(name.substring(0, 10) + '..', alienX, alienY + 50); + // } else { image.src = `./images/sprite_invader_${status}.png`; ctx.font = '8px pixel'; diff --git a/scripts/ingress.lua b/scripts/ingress.lua index b6af05b1e..2b74358f3 100644 --- a/scripts/ingress.lua +++ b/scripts/ingress.lua @@ -2,6 +2,7 @@ local https = require "ssl.https" local ltn12 = require "ltn12" local json = require 'lunajson' local redis = require "resty.redis" +local http = require("resty.http") local k8s_url = "" @@ -33,6 +34,7 @@ local arg = ngx.req.get_uri_args() local namespace = arg["namespace"] local url = k8s_url .. "/apis/networking.k8s.io/v1/namespaces/" .. namespace .. "/ingresses" local decoded = nil +local host_list = {} ngx.header['Access-Control-Allow-Origin'] = '*' ngx.header['Access-Control-Allow-Methods'] = 'GET, POST, OPTIONS' @@ -41,47 +43,39 @@ ngx.header['Access-Control-Expose-Headers'] = 'Content-Length,Content-Range'; ngx.log(ngx.INFO, "Requesting nodes using this url: " .. url) -local headers = { - ["Accept"] = "application/json", - ["Content-Type"] = "application/json", - ["Authorization"] = "Bearer " .. token, -} - -local resp = {} -local host_list = {} -local ok, statusCode, headers, statusText = https.request{ - url = url, - headers = headers, - method = "GET", - sink = ltn12.sink.table(resp) -} - -ngx.log(ngx.INFO, "REQUEST LOGS...") -ngx.log(ngx.INFO, ok) -ngx.log(ngx.INFO, statusCode) -ngx.log(ngx.INFO, statusText) -ngx.log(ngx.INFO, "[INGRESS-LIST] resp: " .. convert_table_to_string(resp)) - -decoded = json.decode(table.concat(resp)) -if table.getn(decoded["items"]) == 0 then - host_list = {"No Ingress found"} +local httpc = http.new() + +-- Esegui la richiesta +local res, err = httpc:request_uri(url, { + method = "GET", + ssl_verify = false, -- TODO: use a valid certificate + headers = { + ["Accept"] = "application/json", + ["Content-Type"] = "application/json", + ["Authorization"] = "Bearer " .. token + } +}) + +if not res then + ngx.log(ngx.ERR, "Errore durante la richiesta HTTP: ", err) + return end -for k2,v2 in ipairs(decoded["items"]) do +decoded = json.decode(res.body) +ngx.log(ngx.ERR, "Decoded: " .. json.encode(decoded)) +for k2,v2 in ipairs(decoded["items"]) do if check_table_key_exists(v2["spec"], "tls") then for k3,v3 in ipairs(v2["spec"]["tls"]) do - for i in pairs(v3["hosts"]) do - if v3["hosts"] ~= nil then - ngx.log(ngx.INFO, "Ingress: " .. v3["hosts"][i]) - table.insert(host_list, "https://" .. v3["hosts"][i]) - end + for i, host in ipairs(v3["hosts"]) do + ngx.log(ngx.INFO, "Ingress: " .. host) + table.insert(host_list, "https://" .. host) end end end - for k3,v3 in ipairs(v2["spec"]["rules"]) do - if v3["hosts"] ~= nil then + for k3, v3 in ipairs(v2["spec"]["rules"]) do + if v3["host"] ~= nil then ngx.log(ngx.INFO, "Ingress: " .. v3["host"]) table.insert(host_list, "http://" .. v3["host"]) end diff --git a/scripts/pod.lua b/scripts/pod.lua index 16cae72b9..c36c4fac1 100644 --- a/scripts/pod.lua +++ b/scripts/pod.lua @@ -37,7 +37,6 @@ if action == "delete" then ngx.log(ngx.INFO, "Connection to Redis is not ok") ngx.log(ngx.INFO, errredis) end - -- Count the total of deleted pods local res, err = red:get("deleted_pods_total")