Skip to content

Commit

Permalink
developing kubevirt support
Browse files Browse the repository at this point in the history
  • Loading branch information
lucky-sideburn committed Dec 22, 2024
1 parent 66704ad commit df8b0a9
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 63 deletions.
24 changes: 13 additions & 11 deletions html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,23 @@
.sidebar a {
padding: 10px 15px;
text-decoration: none;
font-size: 18px;
font-size: 16px;
color: #ffffff;
display: block;
}

.sidebar #gameModeButton{
padding: 10px 15px;
text-decoration: none;
font-size: 18px;
font-size: 16px;
color: #ffffff;
display: block;
}

.sidebar #programmingModeButton{
padding: 10px 15px;
text-decoration: none;
font-size: 18px;
font-size: 16px;
color: #ffffff;
display: block;
}
Expand Down Expand Up @@ -153,9 +153,9 @@

<div class="sidebar" id="sidebar">
<a id="gameModeButton" onclick="startGameMode()" style="font-family: pixel;">Game Mode</a>
<a id="programmingModeButton" onclick="startProgrammingMode()" style="font-family: pixel;">Programming Mode</a>
<a href="#" onclick="showSetCurrentChaosContainer()" style="font-family: pixel;">Chaos Container Editor</a>
<a href="#" onclick="showSpecialKeys()" style="font-family: pixel;">Show Special Keys</a>
<a id="programmingModeButton" onclick="startProgrammingMode()" style="font-family: pixel; font-weight: normal;">Programming Mode</a>
<a href="#" onclick="showSetCurrentChaosContainer()" style="font-family: pixel; font-weight: normal;">Chaos Container Editor</a>
<a href="#" onclick="showSpecialKeys()" style="font-family: pixel; font-weight: normal;">Show Special Keys</a>
</div>

<!-- Main content -->
Expand Down Expand Up @@ -341,8 +341,9 @@ <h6 class="modal-title">Set Chaos Container Definition (Click on the code editor
h => Activate or deactivate help<br>
s => Activate or deactivate shuffle for aliens<br>
n => Change namespace<br>
p => Activate or deactivate chaos engineering against pods<br>
c => Activate or deactivate chaos engineering against nodes
p => Activate or deactivate chaos engineering on pods<br>
c => Activate or deactivate chaos engineering on nodes<br>
v => Activate or deactivate chaos engineering on virtual machines (kubevirt)<br>
</p>
</div>
</div>
Expand Down Expand Up @@ -454,8 +455,9 @@ <h2 class="accordion-header" id="specialkeys-headingThree">
h => Activate or deactivate help<br>
s => Activate or deactivate shuffle for aliens<br>
n => Change namespace<br>
p => Activate or deactivate chaos engineering against pods<br>
c => Activate or deactivate chaos engineering against nodes
p => Activate or deactivate chaos engineering on pods<br>
c => Activate or deactivate chaos engineering on nodes<br>
v => Activate or deactivate chaos engineering on virtual machines (kubevirt)<br>
</div>
</div>
</div>
Expand Down Expand Up @@ -694,7 +696,7 @@ <h2></h2>
<div class="container text-center" style="margin-top: 20%;">
<div>
<img style="scale: 60%" src="images/kubeinvaders_spaceship2.png" id="spaceShip">
<p class="text-muted credit" style="color:#fff;">version: 2024-12-22 11:38:01</p>
<p class="text-muted credit" style="color:#fff;">version: 2024-12-22 18:48:13</p>
</div>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions html/js/globalvars.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<div id="alert_placeholder3" style="margin-top: 2%; margin-bottom: 1%; background-color: #161616; color: #ffffff" class="alert" role="alert">';
var log_tail_alert_no_pixel = '<div id="alert_placeholder3" style="margin-top: 2%; margin-bottom: 1%; background-color: #161616; color: #ffffff; font-family: Courier, monospace;" class="alert" role="alert">';

Expand Down
55 changes: 36 additions & 19 deletions html/js/kubeinvaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,19 +358,17 @@ function getPods() {
}
}

if (chaos_vms && virtualMachines && virtualMachines.length > 0) {
pods = new_pods.concat(virtualMachines);
}

if (nodes && nodes.length > 0) {
pods = new_pods.concat(nodes);
}
else {
pods = new_pods;
}

if (nodes && virtualMachines.length > 0) {
pods = new_pods.concat(virtualMachines);
}
else {
pods = new_pods;
}
};;
oReq.open("GET", k8s_url + "/kube/pods?action=list&namespace=" + namespace);
oReq.send();
Expand Down Expand Up @@ -400,21 +398,21 @@ function getNodes() {
}

function getVMs() {
if (chaos_nodes) {
if (chaos_vms) {
var oReq = new XMLHttpRequest();
oReq.onload = function () {
const jsonData = JSON.parse(this.responseText);

const vmList = {
items: [
// { name: "node1", status: "ready" } // Primo elemento
]
};
// const vmList = {
// items: [
// // { name: "node1", status: "ready" } // Primo elemento
// ]
// };

Array.from(jsonData.items).forEach(vm => {
const name = vm.metadata.name; // Nome della VM
const status = vm.status.printableStatus; // Stato della VM
vmList.items.push({ name: name, status: status });
virtualMachines.push({ name: name, status: status });
});

console.log("Mappa delle VM e dei loro stati:");
Expand Down Expand Up @@ -494,6 +492,25 @@ function keyDownHandler(e) {
$('#alert_placeholder').replaceWith(alert_div + 'Latest action: Show nodes</div>');
}
}

else if (e.keyCode == 86) {

if (is_demo_mode()) {
demo_mode_alert();
return;
}

if (chaos_vms) {
chaos_vms = false;
$('#alert_placeholder').replaceWith(alert_div + 'Latest action: Hide Virtual Machines</div>');

}
else {
chaos_vms = true
$('#alert_placeholder').replaceWith(alert_div + 'Latest action: Show Virtual Machines</div>');
}
}

else if (e.keyCode == 80) {
if (chaos_pods) {
chaos_pods = false;
Expand Down Expand Up @@ -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';
Expand Down
58 changes: 26 additions & 32 deletions scripts/ingress.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""

Expand Down Expand Up @@ -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'
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion scripts/pod.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit df8b0a9

Please sign in to comment.