added configuration file

This commit is contained in:
Eugenio Marzo
2019-03-31 11:40:34 +02:00
parent 1606177964
commit 85178fb537
9 changed files with 372 additions and 18 deletions
+5
View File
@@ -0,0 +1,5 @@
token eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJmb29iYXIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlY3JldC5uYW1lIjoiYm90LXRva2VuLTY3cHBqIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImJvdCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6IjRmZTZkOWUwLWRlNjEtMTFlOC1hOTIzLTIyM2Q5NTVhNzBlOSIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDpmb29iYXI6Ym90In0.ksXQC13mcYqkdPafZ-NK8RcbzTMCufB-83NekeKYW57b9fMCEvbs41no0cbOoeq2Y6J7TnHiDxOIJnIlgP60ceNYB9D3JbgOGTpvyEtNeb3VdKZV7GQUo_MpjwYH0rWD_WbflNM6wT2X34D9T7kwNVYAAN0ccQxGk9qbEswaHerfYMGY9pI4WY3wCtX3UMlI9JyS8CQt3K9aKTyzuvcjURLckpvnluBahrq90WSJBePxUs2Nm5BkmkHjlkOhoitXzfVZ8SuwgszHTThB3PVaPlV7GqS9WaIJcQZDktq1kX_vTR1sj-sok60qmRS-ngUsIVGVatIQlHwk7OJua3l_9A
endpoint https://ocmaster39:8443
namespace foobar
+2 -1
View File
@@ -1,3 +1,4 @@
.KubeInv.conf
/.internal
/build
.externalToolBuilders
@@ -7,4 +8,4 @@ Thumbs.db
*.pyc
.project
.cproject
builtins
builtins
+4
View File
@@ -22,3 +22,7 @@ mouse_trigger {
input: MOUSE_BUTTON_1
action: "click"
}
text_trigger {
input: TEXT
action: "type"
}
+1 -2
View File
@@ -1,12 +1,11 @@
local COLLISION_RESPONSE = hash("collision_response")
function refresh_pods()
http.request("https://ocmaster39:8443/api/v1/namespaces/foobar/pods", "GET", http_pod_result,headers)
http.request(endpoint .. "/api/v1/namespaces/" .. namespace .. "/pods", "GET", http_pod_result,headers)
end
function init(self)
msg.post(".", "acquire_input_focus")
token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJmb29iYXIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlY3JldC5uYW1lIjoiYm90LXRva2VuLTZiNndkIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImJvdCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6IjRmZTZkOWUwLWRlNjEtMTFlOC1hOTIzLTIyM2Q5NTVhNzBlOSIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDpmb29iYXI6Ym90In0.GwuazgmPxWIGgFNuVQxpNz5kXweuPjUHMnsemX1YJAINYgzvZ2FMaTCqJJ1pN3Vdk05KA9YD69lJLYv3kBDSeTdWOCuIYSGyq0EPhUu5eGdFvDxg1Hqj58XWTfNS79Yb3jPTTETGLqDPLJIMqKbmvIERxVZlVT8cGWo6xVhDrUaA0YrGD6SFdvh35pqGV-hmyyzhqU27p51zUG4cYv9KVk1TVVJst2qDIoB2vCnab04qaaPuWB3GmVQLXEG09qqGWvYuil88gb76iMNv7vfX3FMKuENxD175et5hhIbEjWg2jdxqGzZ6wj8Qi19WJr-1fREk_loefi-1ipC-zc5uLw"
headers = {
["Authorization"] = "Bearer " .. token ,
["Accept"] = "application/json",
+204
View File
@@ -0,0 +1,204 @@
script: "/main/kubeinvaders.gui_script"
fonts {
name: "system_font"
font: "/builtins/fonts/system_font.font"
}
fonts {
name: "kubefont"
font: "/main/kubefont.font"
}
background_color {
x: 0.0
y: 0.0
z: 0.0
w: 0.0
}
nodes {
position {
x: 120.0
y: 80.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
size {
x: 300.0
y: 300.0
z: 0.0
w: 1.0
}
color {
x: 0.1908397
y: 1.0
z: 0.0
w: 1.0
}
type: TYPE_TEXT
blend_mode: BLEND_MODE_ALPHA
text: ""
font: "kubefont"
id: "status"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_CENTER
outline {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
shadow {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
adjust_mode: ADJUST_MODE_FIT
line_break: false
layer: ""
inherit_alpha: true
alpha: 1.0
outline_alpha: 1.0
shadow_alpha: 1.0
template_node_child: false
text_leading: 1.0
text_tracking: 0.0
}
nodes {
position {
x: 601.0
y: 131.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 1.076
y: 1.076
z: 1.076
w: 1.0
}
size {
x: 600.0
y: 600.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_TEXT
blend_mode: BLEND_MODE_ALPHA
text: ""
font: "kubefont"
id: "howto"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_CENTER
outline {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
shadow {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
adjust_mode: ADJUST_MODE_FIT
line_break: false
layer: ""
inherit_alpha: true
alpha: 1.0
outline_alpha: 1.0
shadow_alpha: 1.0
template_node_child: false
text_leading: 1.0
text_tracking: 0.0
}
nodes {
position {
x: 598.0
y: 34.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
size {
x: 200.0
y: 100.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_TEXT
blend_mode: BLEND_MODE_ALPHA
text: ""
font: "kubefont"
id: "info"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_CENTER
outline {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
shadow {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
adjust_mode: ADJUST_MODE_FIT
line_break: false
layer: ""
inherit_alpha: true
alpha: 1.0
outline_alpha: 1.0
shadow_alpha: 1.0
template_node_child: false
text_leading: 1.0
text_tracking: 0.0
}
material: "/builtins/materials/gui.material"
adjust_reference: ADJUST_REFERENCE_PARENT
max_nodes: 512
+17
View File
@@ -0,0 +1,17 @@
font: "/builtins/fonts/vera_mo_bd.ttf"
material: "/builtins/fonts/font.material"
size: 20
antialias: 1
alpha: 1.0
outline_alpha: 0.0
outline_width: 0.0
shadow_alpha: 0.0
shadow_blur: 0
shadow_x: 0.0
shadow_y: 0.0
extra_characters: ""
output_format: TYPE_BITMAP
all_chars: false
cache_width: 0
cache_height: 0
render_mode: MODE_SINGLE_LAYER
+33
View File
@@ -0,0 +1,33 @@
function init(self)
end
function final(self)
-- Add finalization code here
-- Remove this function if not needed
end
function update(self, dt)
-- Add update code here
-- Remove this function if not needed
end
function on_message(self, message_id, message, sender)
if message_id == hash("hello_gui") then
gui.set_text(gui.get_node("status"), "Running pods: " .. message.pod_running)
elseif message_id == hash("howto") then
gui.set_text(gui.get_node("howto"), message.howto_message)
elseif message_id == hash("info") then
gui.set_text(gui.get_node("info"), message.infomessage)
end
end
function on_input(self, action_id, action)
end
function on_reload(self)
-- Add input-handling code here
-- Remove this function if not needed
end
+35
View File
@@ -374,3 +374,38 @@ embedded_instances {
z: 1.0
}
}
embedded_instances {
id: "ui"
data: "components {\n"
" id: \"gui\"\n"
" component: \"/main/gui.gui\"\n"
" position {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" }\n"
" rotation {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" w: 1.0\n"
" }\n"
"}\n"
""
position {
x: 0.0
y: 0.0
z: 0.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale3 {
x: 1.0
y: 1.0
z: 1.0
}
}
+71 -15
View File
@@ -1,10 +1,14 @@
current_pods = {}
check_current_pods = false
endpoint = ""
token = ""
namespace = ""
local timer = require ("main.timer")
function swap_pod(items)
current_pod_not_running = 0
kube_pod_not_running = 0
kube_pod_running = 0
pod_items_size = table.getn(items)
for i,value in ipairs(current_pods) do
@@ -28,11 +32,15 @@ function swap_pod(items)
if value['status']['phase'] ~= "Running" then
kube_pod_not_running = kube_pod_not_running + 1
--print ("[swap_pod]:" .. value['metadata']['name'] .. " is not running on Kubernetes cluster")
else
kube_pod_running = kube_pod_running + 1
end
end
print ("[swap_pod]: current pods on Kubernetes: " .. pod_items_size)
print ("[swap_pod]: not running pods Kubernetes: " .. kube_pod_not_running)
print ("[swap_pod]: not running pods in KubeInvaders: " .. current_pod_not_running)
msg.post("ui#gui", "hello_gui",{ pod_running = kube_pod_running })
if (current_pod_not_running > 0) and (kube_pod_not_running > current_pod_not_running )then
diff = kube_pod_not_running - current_pod_not_running
@@ -73,16 +81,16 @@ function http_update_pod_result(self, _, response)
end
function update_pod()
http.request("https://ocmaster39:8443/api/v1/namespaces/foobar/pods", "GET", http_update_pod_result,headers)
http.request(endpoint .. "/api/v1/namespaces/" .. namespace .. "/pods", "GET", http_update_pod_result,headers)
end
function delete_pod(pod_name)
print "[delete_pod] delete pods of Kubernetes"
http.request("https://ocmaster39:8443/api/v1/namespaces/foobar/pods/" .. pod_name, "DELETE", http_pod_delete_result,headers)
http.request(endpoint .. "/api/v1/namespaces/" .. namespace .. "/pods/" .. pod_name, "DELETE", http_pod_delete_result,headers)
end
function delete_request_pod()
http.request("https://ocmaster39:8443/api/v1/namespaces/foobar/pods", "GET", http_pod_delete_request_result,headers)
http.request(endpoint .. "/api/v1/namespaces/".. namespace .. "/pods", "GET", http_pod_delete_request_result,headers)
end
function http_pod_delete_result(self, _, response)
@@ -144,21 +152,69 @@ function http_pod_result(self, _, response)
end
function set_pods()
http.request("https://ocmaster39:8443/api/v1/namespaces/foobar/pods", "GET", http_pod_result,headers)
http.request(endpoint .. "/api/v1/namespaces/".. namespace .. "/pods", "GET", http_pod_result,headers)
end
function init(self)
msg.post(".", "acquire_input_focus")
token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJmb29iYXIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlY3JldC5uYW1lIjoiYm90LXRva2VuLTZiNndkIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImJvdCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6IjRmZTZkOWUwLWRlNjEtMTFlOC1hOTIzLTIyM2Q5NTVhNzBlOSIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDpmb29iYXI6Ym90In0.GwuazgmPxWIGgFNuVQxpNz5kXweuPjUHMnsemX1YJAINYgzvZ2FMaTCqJJ1pN3Vdk05KA9YD69lJLYv3kBDSeTdWOCuIYSGyq0EPhUu5eGdFvDxg1Hqj58XWTfNS79Yb3jPTTETGLqDPLJIMqKbmvIERxVZlVT8cGWo6xVhDrUaA0YrGD6SFdvh35pqGV-hmyyzhqU27p51zUG4cYv9KVk1TVVJst2qDIoB2vCnab04qaaPuWB3GmVQLXEG09qqGWvYuil88gb76iMNv7vfX3FMKuENxD175et5hhIbEjWg2jdxqGzZ6wj8Qi19WJr-1fREk_loefi-1ipC-zc5uLw"
headers = {
["Authorization"] = "Bearer " .. token ,
["Accept"] = "application/json",
["Content-Type"] = "application/json"
}
timer.repeat_seconds(0.5, function()
update_pod()
end)
set_pods()
conf = {}
fp = io.open( ".KubeInv.conf", "r" )
if fp ~= nil then
for line in fp:lines() do
line = line:match( "%s*(.+)" )
if line and line:sub( 1, 1 ) ~= "#" and line:sub( 1, 1 ) ~= ";" then
option = line:match( "%S+" ):lower()
value = line:match( "%S*%s*(.*)" )
if not value then
conf[option] = true
else
if not value:find( "," ) then
conf[option] = value
else
value = value .. ","
conf[option] = {}
for entry in value:gmatch( "%s*(.-)," ) do
conf[option][#conf[option]+1] = entry
end
end
end
end
end
fp:close()
end
local handle = io.popen('pwd')
local result = handle:read("*a")
handle:close()
if conf["token"] == nil or conf["endpoint"] == nil or conf["namespace"] == nil then
msg.post("ui#gui", "howto",{ howto_message = "Please create .KubeInv.conf in " .. result .. "Example of KubeInv.conf:\n\nnamespace foobar\ntoken eyJhbGciOiJ43i423i94239i49\nendpoint https://ocmaster39:8443\n"})
else
print( "token: ", conf["token"] )
print( "endpoint: ", conf["endpoint"] )
print( "namespace: ", conf["namespace"] )
endpoint = conf["endpoint"]
namespace = conf["namespace"]
token = conf["token"]
info = "Endpoint: " .. conf["endpoint"] .. " " .. "Namespace: " .. conf["namespace"]
msg.post("ui#gui", "info",{ infomessage = info })
msg.post(".", "acquire_input_focus")
headers = {
["Authorization"] = "Bearer " .. token ,
["Accept"] = "application/json",
["Content-Type"] = "application/json"
}
timer.repeat_seconds(0.5, function()
update_pod()
end)
set_pods()
end
end
function update(self, dt)