mirror of
https://github.com/lucky-sideburn/kubeinvaders.git
synced 2026-04-06 18:36:52 +00:00
96 lines
3.2 KiB
Plaintext
96 lines
3.2 KiB
Plaintext
# lua_package_path '/usr/share/lua/5.1/?.lua;;';
|
|
|
|
server {
|
|
listen 8080 default_server;
|
|
root /var/www/html/;
|
|
index index.html;
|
|
|
|
location / {
|
|
add_header 'Access-Control-Allow-Origin' '*';
|
|
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
|
|
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
|
|
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
|
|
try_files $uri $uri/ =404;
|
|
add_header Last-Modified $date_gmt;
|
|
if_modified_since off;
|
|
expires off;
|
|
etag off;
|
|
}
|
|
|
|
location /kube/pods {
|
|
access_by_lua_file "/tmp/pod.lua";
|
|
}
|
|
|
|
location /kube/delete/pods {
|
|
access_by_lua_file "/tmp/pod.lua";
|
|
}
|
|
|
|
location /kube/nodes {
|
|
access_by_lua_file "/tmp/node.lua";
|
|
}
|
|
|
|
location /kube/chaos/nodes {
|
|
access_by_lua_file "/tmp/chaos-node.lua";
|
|
}
|
|
|
|
location /kube/endpoint {
|
|
content_by_lua_block {
|
|
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.say(os.getenv("ENDPOINT"))
|
|
}
|
|
}
|
|
|
|
location /kube/namespaces {
|
|
content_by_lua_block {
|
|
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.say(os.getenv("NAMESPACE"))
|
|
}
|
|
}
|
|
|
|
location /metrics {
|
|
default_type text/html;
|
|
content_by_lua_block {
|
|
local redis = require "resty.redis"
|
|
local red = redis:new()
|
|
|
|
-- local okredis, errredis = red:connect(os.getenv("REDIS_HOST"), 6379)
|
|
local okredis, errredis = red:connect("unix:/tmp/redis.sock")
|
|
|
|
for i, res in ipairs(red:keys("*")) do
|
|
ngx.log(ngx.ERR, res)
|
|
|
|
if string.find(res, "chaos_node_jobs_total_on") then
|
|
node = string.gsub(res, "chaos_node_jobs_total_on_", "")
|
|
metric = "chaos_jobs_node_count{node=\"".. node .."\"}"
|
|
ngx.say(metric .. " " .. red:get(res))
|
|
|
|
elseif string.find(res, "deleted_pods_total_on") then
|
|
namespace = string.gsub(res, "deleted_pods_total_on_", "")
|
|
metric = "deleted_namespace_pods_count{namespace=\"".. namespace .."\"}"
|
|
ngx.say(metric .. " " .. red:get(res))
|
|
else
|
|
ngx.say(res .. " " .. red:get(res))
|
|
end
|
|
end
|
|
}
|
|
}
|
|
|
|
location /kube/kube-linter {
|
|
default_type text/html;
|
|
content_by_lua_block {
|
|
local arg = ngx.req.get_uri_args()
|
|
ngx.req.read_body()
|
|
local request_body = ngx.req.get_body_data()
|
|
local handle = io.popen("/opt/kube-linter-parser.sh " .. arg['k8s_url'] .. " " .. arg['namespace'] .. " " .. arg['pod_name'] .. " " .. arg['token'])
|
|
local result = handle:read("*a")
|
|
ngx.say(result)
|
|
}
|
|
}
|
|
}
|