mirror of
https://github.com/lucky-sideburn/kubeinvaders.git
synced 2026-08-23 21:46:21 +00:00
fix endpoint
This commit is contained in:
@@ -2,4 +2,6 @@
|
||||
|
||||
redis-server /etc/redis/redis.conf &
|
||||
|
||||
sed -i "s/ENDPOINT_PLACEHOLDER/$ENDPOINT/g" /var/www/html/kubeinvaders.js
|
||||
|
||||
nginx -c /etc/nginx/nginx.conf -g 'daemon off;'
|
||||
|
||||
@@ -87,7 +87,7 @@ function getNamespaces(){
|
||||
namespaces = namespaces.split(",");
|
||||
namespace = namespaces[namespaces_index];
|
||||
};;
|
||||
oReq.open("GET", "https://kubeinvaders.io/kube/namespaces");
|
||||
oReq.open("GET", "https://ENDPOINT_PLACEHOLDER/kube/namespaces");
|
||||
oReq.send();
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ function getEndpoint(){
|
||||
oReq.onload = function () {
|
||||
endpoint = this.responseText;
|
||||
};;
|
||||
oReq.open("GET", "https://kubeinvaders.io/kube/endpoint");
|
||||
oReq.open("GET", "https://ENDPOINT_PLACEHOLDER/kube/endpoint");
|
||||
oReq.send();
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ function startChaosNode(node_name){
|
||||
oReq.onload = function () {
|
||||
console.log(JSON.parse(this.responseText))
|
||||
};;
|
||||
oReq.open("GET", "https://kubeinvaders.io/kube/chaos/nodes?nodename=node_name=" + node_name + "&namespace=" + namespace);
|
||||
oReq.open("GET", "https://ENDPOINT_PLACEHOLDER/kube/chaos/nodes?nodename=node_name=" + node_name + "&namespace=" + namespace);
|
||||
oReq.send();
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ function deletePods(pod_name){
|
||||
oReq.onload = function () {
|
||||
console.log(JSON.parse(this.responseText))
|
||||
};;
|
||||
oReq.open("GET", "https://kubeinvaders.io/kube/pods?action=delete&pod_name=" + pod_name + "&namespace=" + namespace);
|
||||
oReq.open("GET", "https://ENDPOINT_PLACEHOLDER/kube/pods?action=delete&pod_name=" + pod_name + "&namespace=" + namespace);
|
||||
oReq.send();
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ function getPods(){
|
||||
json_parsed = JSON.parse(this.responseText)
|
||||
pods = json_parsed["items"].concat(nodes);
|
||||
};;
|
||||
oReq.open("GET", "https://kubeinvaders.io/kube/pods?action=list&namespace=" + namespace);
|
||||
oReq.open("GET", "https://ENDPOINT_PLACEHOLDER/kube/pods?action=list&namespace=" + namespace);
|
||||
oReq.send();
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ function getNodes(){
|
||||
json_parsed = JSON.parse(this.responseText)
|
||||
nodes = json_parsed["items"];
|
||||
};;
|
||||
oReq.open("GET", "https://kubeinvaders.io/kube/nodes");
|
||||
oReq.open("GET", "https://ENDPOINT_PLACEHOLDER/kube/nodes");
|
||||
oReq.send();
|
||||
}
|
||||
|
||||
|
||||
+36
-2
@@ -1,8 +1,7 @@
|
||||
loadfile("/tmp/metrics.lua")
|
||||
|
||||
local https = require "ssl.https"
|
||||
local ltn12 = require "ltn12"
|
||||
local json = require 'lunajson'
|
||||
local redis = require "resty.redis"
|
||||
|
||||
if os.getenv("KUBERNETES_SERVICE_HOST") then
|
||||
k8s_url = "https://" .. os.getenv("KUBERNETES_SERVICE_HOST") .. ":" .. os.getenv("KUBERNETES_SERVICE_PORT_HTTPS")
|
||||
@@ -16,6 +15,41 @@ local url = k8s_url.. "/api/v1/nodes"
|
||||
local decoded = nil
|
||||
local nodes = {}
|
||||
|
||||
|
||||
if ngx.var.request_method == "GET" and string.match(ngx.var.request_uri, "^.*/chaos[-]node.*$") then
|
||||
local red = redis:new()
|
||||
local okredis, errredis = red:connect("unix:/tmp/redis.sock")
|
||||
|
||||
if okredis then
|
||||
ngx.log(ngx.ERR, "Connection to Redis is ok")
|
||||
else
|
||||
ngx.log(ngx.ERR, "Connection to Redis is not ok")
|
||||
ngx.log(ngx.ERR, errredis)
|
||||
end
|
||||
-- Count the total of chaos jobs launched against nodes
|
||||
local chaos_node_res, err = red:get("chaos_node_jobs_total")
|
||||
|
||||
if chaos_node_res == ngx.null then
|
||||
ngx.say(err)
|
||||
red:set("chaos_node_jobs_total", 0)
|
||||
else
|
||||
local incr = chaos_node_res + 1
|
||||
local res, err = red:set("chaos_node_jobs_total",incr)
|
||||
end
|
||||
|
||||
-- Count the total of chaos jobs launched against nodes per node
|
||||
local node_name = arg['node_name']
|
||||
local chaos_node_res, err = red:get("chaos_node_jobs_total_on_" .. node_name)
|
||||
if chaos_node_res == ngx.null then
|
||||
ngx.say(err)
|
||||
red:set("chaos_node_jobs_total_on_" .. node_name, 1)
|
||||
else
|
||||
local incr = chaos_node_res + 1
|
||||
local res, err = red:set("chaos_node_jobs_total_on_" .. node_name,incr)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
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'
|
||||
|
||||
+40
-3
@@ -1,7 +1,8 @@
|
||||
loadfile("/tmp/metrics.lua")
|
||||
local https = require "ssl.https"
|
||||
local ltn12 = require "ltn12"
|
||||
local json = require 'lunajson'
|
||||
local redis = require "resty.redis"
|
||||
local incr = 0
|
||||
|
||||
if os.getenv("KUBERNETES_SERVICE_HOST") then
|
||||
k8s_url = "https://" .. os.getenv("KUBERNETES_SERVICE_HOST") .. ":" .. os.getenv("KUBERNETES_SERVICE_PORT_HTTPS")
|
||||
@@ -24,6 +25,44 @@ 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';
|
||||
|
||||
|
||||
if action == "delete" then
|
||||
local red = redis:new()
|
||||
local okredis, errredis = red:connect("unix:/tmp/redis.sock")
|
||||
|
||||
if okredis then
|
||||
ngx.log(ngx.ERR, "Connection to Redis is ok")
|
||||
else
|
||||
ngx.log(ngx.ERR, "Connection to Redis is not ok")
|
||||
ngx.log(ngx.ERR, errredis)
|
||||
end
|
||||
-- Count the total of deleted pods
|
||||
local res, err = red:get("deleted_pods_total")
|
||||
|
||||
if res == ngx.null then
|
||||
ngx.say(err)
|
||||
red:set("deleted_pods_total", 1)
|
||||
else
|
||||
incr = res + 1
|
||||
red:set("deleted_pods_total", incr)
|
||||
end
|
||||
|
||||
-- TODO: Make a better regular expression!
|
||||
local namespace_pods = string.match(ngx.var.request_uri, '^.*/namespaces/(.*)/.*$')
|
||||
local namespace = namespace_pods:gsub("/pods", "")
|
||||
|
||||
-- Count the total of deleted pods for namespace
|
||||
local res, err = red:get("deleted_pods_total_on_" .. namespace)
|
||||
|
||||
if res == ngx.null then
|
||||
red:set("deleted_pods_total_on_" .. namespace, 1)
|
||||
else
|
||||
incr = res + 1
|
||||
red:set("deleted_pods_total_on_" .. namespace, incr)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if action == "list" then
|
||||
url = k8s_url.. "/api/v1/namespaces/" .. namespace .. "/pods"
|
||||
|
||||
@@ -61,8 +100,6 @@ ngx.log(ngx.ERR, ok)
|
||||
ngx.log(ngx.ERR, statusCode)
|
||||
ngx.log(ngx.ERR, statusText)
|
||||
|
||||
ngx.log(ngx.ERR, table.concat(resp))
|
||||
|
||||
if action == "list" then
|
||||
local i = 1
|
||||
pods["items"] = {}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
redis-server /etc/redis/redis.conf &
|
||||
|
||||
if [ ! -z $DEVELOPMENT ];
|
||||
then
|
||||
ENDPOINT_JS=$(echo "${ENDPOINT}" | sed "s/\//\\\\\//g")
|
||||
envsubst '${ENDPOINT}' < "/etc/nginx/conf.d/KubeInvaders_dev.templ" > "/etc/nginx/conf.d/KubeInvaders.conf"
|
||||
sed -i "s/var\ ENV={};/var\ ENV={};ENV[\"TOKEN\"]=\"$TOKEN\";ENV[\"ENDPOINT\"]=\"$ENDPOINT_JS\";ENV[\"NAMESPACE\"]=\"$NAMESPACE\";ENV[\"HITSLIMIT\"]=\"$HITSLIMIT\";ENV[\"ALIENPROXIMITY\"]=\"$ALIENPROXIMITY\";ENV[\"UPDATETIME\"]=\"$UPDATETIME\";/g" /var/www/html/KubeInvaders_wasm.js
|
||||
else
|
||||
ENDPOINT=$(echo "https://${ROUTE_HOST}" | sed "s/\//\\\\\//g")
|
||||
envsubst '${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT_HTTPS}' < "/etc/nginx/conf.d/KubeInvaders.templ" > "/etc/nginx/conf.d/KubeInvaders.conf"
|
||||
sed -i "s/var\ ENV={};/var\ ENV={};ENV[\"TOKEN\"]=\"$TOKEN\";ENV[\"ENDPOINT\"]=\"$ENDPOINT\/kube\";ENV[\"NAMESPACE\"]=\"$NAMESPACE\";ENV[\"HITSLIMIT\"]=\"$HITSLIMIT\";ENV[\"ALIENPROXIMITY\"]=\"$ALIENPROXIMITY\";ENV[\"UPDATETIME\"]=\"$UPDATETIME\";/g" /var/www/html/KubeInvaders_wasm.js
|
||||
fi
|
||||
|
||||
sed -i "s/TOTAL_ENV_SIZE=1024/TOTAL_ENV_SIZE=2048/g" /var/www/html/KubeInvaders_wasm.js
|
||||
sed -i "s/TOTAL_ENV_SIZE=1024/TOTAL_ENV_SIZE=2048/g" /var/www/html/KubeInvaders_asmjs.js
|
||||
|
||||
nginx -c /etc/nginx/nginx.conf -g 'daemon off;'
|
||||
Reference in New Issue
Block a user