mirror of
https://github.com/lucky-sideburn/kubeinvaders.git
synced 2026-08-23 21:46:21 +00:00
added images and code for kubevirt support
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 426 B |
Binary file not shown.
|
After Width: | Height: | Size: 426 B |
Binary file not shown.
|
After Width: | Height: | Size: 426 B |
Binary file not shown.
|
After Width: | Height: | Size: 426 B |
+1
-1
@@ -697,7 +697,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-25 10:23:42</p>
|
||||
<p class="text-muted credit" style="color:#fff;">version: 2024-12-29 17:50:52</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+21
-9
@@ -336,6 +336,16 @@ function startChaosNode(node_name) {
|
||||
oReq.send();
|
||||
}
|
||||
|
||||
function rebootVirtualMachine(vm_name) {
|
||||
var oReq = new XMLHttpRequest();
|
||||
oReq.onload = function () {
|
||||
$('#alert_placeholder').replaceWith(alert_div + 'Latest action: Prepareing reboot virtual machine ' + vm_name + '</div>');
|
||||
};;
|
||||
$('#alert_placeholder').replaceWith(alert_div + 'Latest action: Reboot virtual machine ' + vm_name + '</div>');
|
||||
oReq.open("GET", k8s_url + "/kube/chaos/vm_reboot?vm_name=" + vm_name + "&namespace=" + namespace);
|
||||
oReq.send();
|
||||
}
|
||||
|
||||
function deletePods(pod_name) {
|
||||
var oReq = new XMLHttpRequest();
|
||||
oReq.onload = function () {
|
||||
@@ -356,8 +366,6 @@ function addNodeAndVMstoPods() {
|
||||
return pods;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function getPods() {
|
||||
if (chaos_pods) {
|
||||
var oReq = new XMLHttpRequest();
|
||||
@@ -405,7 +413,7 @@ function getVMs() {
|
||||
virtualMachines = [];
|
||||
Array.from(jsonData.items).forEach(vm => {
|
||||
const name = vm.metadata.name; // Nome della VM
|
||||
const status = vm.status.printableStatus; // Stato della VM
|
||||
const status = vm.status.printableStatus.toLowerCase(); // Stato della VM
|
||||
virtualMachines.push({ name: name, status: status });
|
||||
});
|
||||
};;
|
||||
@@ -537,9 +545,9 @@ function drawAlien(alienX, alienY, name, status) {
|
||||
ctx.fillText(name.substring(0, 10) + '..', alienX, alienY + 50);
|
||||
}
|
||||
else if (virtualMachines.some((vm) => vm.name == name)) {
|
||||
image.src = './images/k8s_node.png';
|
||||
image.src = `./images/sprite_invader_vm_${status}.png`;
|
||||
ctx.font = '10px pixel';
|
||||
ctx.drawImage(image, alienX, alienY, 30, 40);
|
||||
ctx.drawImage(image, alienX, alienY, 40, 40);
|
||||
ctx.fillText(name.substring(0, 10) + '..', alienX, alienY + 50);
|
||||
}
|
||||
else {
|
||||
@@ -578,6 +586,10 @@ function checkRocketAlienCollision() {
|
||||
aliens[i]["active"] = false;
|
||||
startChaosNode(aliens[i]["name"]);
|
||||
}
|
||||
else if (virtualMachines.some((vm) => vm.name == aliens[i]["name"])) {
|
||||
aliens[i]["active"] = false;
|
||||
rebootVirtualMachine(aliens[i]["name"]);
|
||||
}
|
||||
else {
|
||||
deletePods(aliens[i]["name"]);
|
||||
}
|
||||
@@ -851,10 +863,10 @@ window.setInterval(function setAliens() {
|
||||
}, 1000)
|
||||
|
||||
window.setInterval(function backgroundTasks() {
|
||||
console.log("Nodes:", nodes);
|
||||
console.log("Virtual Machines:", virtualMachines);
|
||||
console.log("chaos_vms flag:", chaos_vms);
|
||||
console.log("Pods:", pods);
|
||||
// console.log("Nodes:", nodes);
|
||||
// console.log("Virtual Machines:", virtualMachines);
|
||||
// console.log("chaos_vms flag:", chaos_vms);
|
||||
// console.log("Pods:", pods);
|
||||
|
||||
if (!codename_configured) {
|
||||
chaosProgram = $('#chaosProgramTextArea').val();
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
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 vm_name = arg["vm_name"]
|
||||
local url = k8s_url .. "/apis/kubevirt.io/v1/namespaces/" .. namespace .. "/virtualmachines/" .. vm_name .. "/restart"
|
||||
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)
|
||||
Reference in New Issue
Block a user