start support for kubevirt

This commit is contained in:
luckysideburn
2024-12-22 11:40:16 +00:00
parent 8b4ba25be9
commit 66704ad297
9 changed files with 119 additions and 24 deletions
+2 -1
View File
@@ -20,7 +20,7 @@ RUN chmod 777 /usr/local/openresty/nginx
RUN apt-get -y install luarocks lua-json lua-socket libyaml-dev
RUN apt-get update --fix-missing
RUN for pkg in luasec lunajson lyaml; do luarocks install $pkg; done
RUN for pkg in luasec lunajson lua-resty-http lyaml; do luarocks install $pkg; done
# Install kube-linter
RUN curl -L -O https://github.com/stackrox/kube-linter/releases/download/0.6.0/kube-linter-linux.tar.gz
@@ -50,6 +50,7 @@ RUN chmod 777 /var/www/html
COPY scripts/metrics.lua /usr/local/openresty/nginx/conf/kubeinvaders/metrics.lua
COPY scripts/pod.lua /usr/local/openresty/nginx/conf/kubeinvaders/pod.lua
COPY scripts/ingress.lua /usr/local/openresty/nginx/conf/kubeinvaders/ingress.lua
COPY scripts/vm.lua /usr/local/openresty/nginx/conf/kubeinvaders/vm.lua
COPY scripts/node.lua /usr/local/openresty/nginx/conf/kubeinvaders/node.lua
COPY scripts/kube-linter.lua /usr/local/openresty/nginx/conf/kubeinvaders/kube-linter.lua
COPY scripts/chaos-node.lua /usr/local/openresty/nginx/conf/kubeinvaders/chaos-node.lua
+7 -7
View File
@@ -152,10 +152,10 @@
</div>
<div class="sidebar" id="sidebar">
<a id="gameModeButton" onclick="startGameMode()">Game Mode</a>
<a id="programmingModeButton" onclick="startProgrammingMode()">Programming Mode</a>
<a href="#" onclick="showSetCurrentChaosContainer()">Chaos Container Editor</a>
<a href="#" onclick="showSpecialKeys()">Show Special Keys</a>
<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>
</div>
<!-- Main content -->
@@ -445,12 +445,12 @@ Using YAML programming, you can define your own chaos engineering experiments an
<div class="accordion" id="specialkeys" style="margin-top: 2%; margin-bottom: 2%;">
<div class="accordion-item">
<h2 class="accordion-header" id="specialkeys-headingThree">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#specialkeys-collapseThree" aria-expanded="false" aria-controls="collapseThree">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#specialkeys-collapseThree" aria-expanded="false" aria-controls="collapseThree" style="font-size: small; font-family: pixel;">
show keys and options
</button>
</h2>
<div id="specialkeys-collapseThree" class="accordion-collapse collapse" aria-labelledby="headingThree" data-bs-parent="#accordionExample">
<div class="accordion-body" style="font-weight: normal; font-size: small;">
<div class="accordion-body" style="font-weight: normal; font-size: small; font-family: pixel;">
h => Activate or deactivate help<br>
s => Activate or deactivate shuffle for aliens<br>
n => Change namespace<br>
@@ -694,7 +694,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: v1.9.7</p>
<p class="text-muted credit" style="color:#fff;">version: 2024-12-22 11:38:01</p>
</div>
</div>
</div>
+1 -1
View File
@@ -62,7 +62,7 @@ function getIngressLists() {
parseIngressListJSON(JSON.parse(this.responseText));
}
};;
oReq.open("GET", k8s_url + "/kube/ingress/get?namespace=" + namespace, true);
oReq.open("GET", k8s_url + "/kube/ingresses?namespace=" + namespace, true);
oReq.setRequestHeader("Content-Type", "application/json");
oReq.send();
}
+1
View File
@@ -70,6 +70,7 @@ var spaceshipxOld = 0;
var randomFactor = 10;
// pods list from kubernetes
var pods = [];
var virtualMachines = [];
var game_mode_switch = false;
var programming_mode_switch = false;
var chaos_program_valid = false;
+49 -1
View File
@@ -360,7 +360,15 @@ function getPods() {
if (nodes && nodes.length > 0) {
pods = new_pods.concat(nodes);
} else {
}
else {
pods = new_pods;
}
if (nodes && virtualMachines.length > 0) {
pods = new_pods.concat(virtualMachines);
}
else {
pods = new_pods;
}
};;
@@ -391,10 +399,42 @@ function getNodes() {
}
}
function getVMs() {
if (chaos_nodes) {
var oReq = new XMLHttpRequest();
oReq.onload = function () {
const jsonData = JSON.parse(this.responseText);
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 });
});
console.log("Mappa delle VM e dei loro stati:");
vmList.items.forEach(vm => {
console.log(`Nome: ${vm.name}, Stato: ${vm.status}`);
});
};;
oReq.open("GET", k8s_url + "/kube/vm?namespace=" + namespace);
oReq.send();
}
else {
virtualMachines = [];
}
}
window.setInterval(function getKubeItems() {
if (game_mode_switch) {
getNodes();
getPods();
getVMs();
}
}, 500)
@@ -486,7 +526,15 @@ function drawAlien(alienX, alienY, name, status) {
var image = new Image(); // Image constructor
if (nodes.some((node) => node.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`;
+5 -1
View File
@@ -62,10 +62,14 @@ server {
sub_filter selected_env_vars_placeholder $selected_env_vars;
}
location /kube/ingress/get {
location /kube/ingresses {
access_by_lua_file "/usr/local/openresty/nginx/conf/kubeinvaders/ingress.lua";
}
location /kube/vm {
access_by_lua_file "/usr/local/openresty/nginx/conf/kubeinvaders/vm.lua";
}
location /kube/chaos/programming_mode {
access_by_lua_file "/usr/local/openresty/nginx/conf/kubeinvaders/programming_mode.lua";
}
+8 -4
View File
@@ -72,15 +72,19 @@ 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
ngx.log(ngx.INFO, "Ingress: " .. v3["hosts"][i])
table.insert(host_list, "https://" .. v3["hosts"][i])
if v3["hosts"] ~= nil then
ngx.log(ngx.INFO, "Ingress: " .. v3["hosts"][i])
table.insert(host_list, "https://" .. v3["hosts"][i])
end
end
end
end
for k3,v3 in ipairs(v2["spec"]["rules"]) do
ngx.log(ngx.INFO, "Ingress: " .. v3["host"])
table.insert(host_list, "http://" .. v3["host"])
if v3["hosts"] ~= nil then
ngx.log(ngx.INFO, "Ingress: " .. v3["host"])
table.insert(host_list, "http://" .. v3["host"])
end
end
end
-9
View File
@@ -75,10 +75,6 @@ else
ngx.exit(ngx.OK)
end
--ngx.log(ngx.INFO, "token: " .. token)
-- ngx.log(ngx.INFO, "url: " .. url)
-- ngx.log(ngx.INFO, "namespace: " .. namespace)
local headers = {
["Accept"] = "application/json",
["Content-Type"] = "application/json",
@@ -94,11 +90,6 @@ local ok, statusCode, headers, statusText = https.request{
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)
if action == "list" then
local i = 1
local j = 0
+46
View File
@@ -0,0 +1,46 @@
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 = ""
if os.getenv("KUBERNETES_SERVICE_HOST") then
k8s_url = "https://" .. os.getenv("KUBERNETES_SERVICE_HOST") .. ":" .. os.getenv("KUBERNETES_SERVICE_PORT_HTTPS")
else
k8s_url = os.getenv("ENDPOINT")
end
local token = os.getenv("TOKEN")
local arg = ngx.req.get_uri_args()
local namespace = arg["namespace"]
local url = k8s_url .. "/apis/kubevirt.io/v1/namespaces/" .. namespace .. "/virtualmachines"
local decoded = nil
ngx.header['Access-Control-Allow-Origin'] = '*'
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.INFO, "Requesting nodes using this url: " .. url)
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
ngx.say(res.body)