mirror of
https://github.com/lucky-sideburn/kubeinvaders.git
synced 2026-02-14 17:50:00 +00:00
developing kubevirt support
This commit is contained in:
@@ -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 @@
|
||||
|
||||
<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 -->
|
||||
@@ -341,8 +341,9 @@
|
||||
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>
|
||||
@@ -454,8 +455,9 @@ Using YAML programming, you can define your own chaos engineering experiments an
|
||||
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>
|
||||
@@ -694,7 +696,7 @@ k8s_jobs:
|
||||
<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>
|
||||
|
||||
@@ -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">';
|
||||
|
||||
|
||||
@@ -358,6 +358,10 @@ function getPods() {
|
||||
}
|
||||
}
|
||||
|
||||
if (chaos_vms && virtualMachines && virtualMachines.length > 0) {
|
||||
pods = new_pods.concat(virtualMachines);
|
||||
}
|
||||
|
||||
if (nodes && nodes.length > 0) {
|
||||
pods = new_pods.concat(nodes);
|
||||
}
|
||||
@@ -365,12 +369,6 @@ function getPods() {
|
||||
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();
|
||||
@@ -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:");
|
||||
@@ -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;
|
||||
@@ -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';
|
||||
|
||||
@@ -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 httpc = http.new()
|
||||
|
||||
local resp = {}
|
||||
local host_list = {}
|
||||
local ok, statusCode, headers, statusText = https.request{
|
||||
url = url,
|
||||
headers = headers,
|
||||
method = "GET",
|
||||
sink = ltn12.sink.table(resp)
|
||||
}
|
||||
-- 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
|
||||
}
|
||||
})
|
||||
|
||||
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"}
|
||||
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
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user