change namespace

This commit is contained in:
Eugenio Marzo
2019-09-13 08:25:01 +02:00
parent ca92f776eb
commit 0febe53c97
3 changed files with 84 additions and 28 deletions
+32 -22
View File
@@ -9,6 +9,38 @@ KubeInvaders is a game and it has been written with Defold (https://www.defold.c
Through KubeInvaders you can stress your Openshift cluster in a fun way and check how it is resilient.
### Special Input Keys
| Input | Action |
|-----------------|--------------------------|
| n | Change namespace |
| a | Switch to automatic mode |
| m | Switch to manual mode |
### Install KubeInvaders on Openshift
To Install KubeInvaders on your Openshift Cluster clone this repo and launch the following commands:
```bash
TARGET_NAMESPACE=foobar
# Choose route host for your kubeinvaders instance.
ROUTE_HOST=kubeinvaders.org
# Please add your source ip IP_WHITELIST. This will add haproxy.router.openshift.io/ip_whitelist in KubeInvaders route
# https://docs.openshift.com/container-platform/3.9/architecture/networking/routes.html#whitelist
IP_WHITELIST="93.44.96.4"
oc new-project kubeinvaders --display-name='KubeInvaders'
oc create sa kubeinvaders -n kubeinvaders
oc create sa kubeinvaders -n $TARGET_NAMESPACE
oc adm policy add-role-to-user edit -z kubeinvaders -n $TARGET_NAMESPACE
TOKEN=$(oc describe secret -n $TARGET_NAMESPACE $(oc describe sa kubeinvaders -n $TARGET_NAMESPACE | grep Tokens | awk '{ print $2}') | grep 'token:'| awk '{ print $2}')
oc process -f openshift/KubeInvaders.yaml -p ROUTE_HOST=$ROUTE_HOST -p TARGET_NAMESPACE=$TARGET_NAMESPACE -p TOKEN=$TOKEN | oc create -f -
```
### Install KubeInvaders on Kubernetes
```bash
@@ -33,28 +65,6 @@ kubectl set env deployment/kubeinvaders NAMESPACE=$TARGET_NAMESPACE -n kubeinvad
kubectl set env deployment/kubeinvaders ROUTE_HOST=$ROUTE_HOST -n kubeinvaders
```
### Install KubeInvaders on Openshift
To Install KubeInvaders on your Openshift Cluster clone this repo and launch the following commands:
```bash
TARGET_NAMESPACE=foobar
# Choose route host for your kubeinvaders instance.
ROUTE_HOST=kubeinvaders.org
# Please add your source ip IP_WHITELIST. This will add haproxy.router.openshift.io/ip_whitelist in KubeInvaders route
# https://docs.openshift.com/container-platform/3.9/architecture/networking/routes.html#whitelist
IP_WHITELIST="93.44.96.4"
oc new-project kubeinvaders --display-name='KubeInvaders'
oc create sa kubeinvaders -n kubeinvaders
oc create sa kubeinvaders -n $TARGET_NAMESPACE
oc adm policy add-role-to-user edit -z kubeinvaders -n $TARGET_NAMESPACE
TOKEN=$(oc describe secret -n $TARGET_NAMESPACE $(oc describe sa kubeinvaders -n $TARGET_NAMESPACE | grep Tokens | awk '{ print $2}') | grep 'token:'| awk '{ print $2}')
oc process -f openshift/KubeInvaders.yaml -p ROUTE_HOST=$ROUTE_HOST -p TARGET_NAMESPACE=$TARGET_NAMESPACE -p TOKEN=$TOKEN | oc create -f -
```
### Download KubeInvaders - External to Openshift (macOS or Linux clients)
Please check the [releases](https://github.com/lucky-sideburn/KubeInvaders/releases) page.
+4
View File
@@ -26,6 +26,10 @@ key_trigger {
input: KEY_M
action: "manual"
}
key_trigger {
input: KEY_N
action: "namespace"
}
mouse_trigger {
input: MOUSE_BUTTON_1
action: "click"
+48 -6
View File
@@ -3,7 +3,11 @@ check_current_pods = false
endpoint = ""
token = ""
namespace = ""
namespace_list = {}
namespace_cnt = 0
namespace_total = 0
automatic = false
last_namespace_change = false
local timer = require ("main.timer")
function reverse(tbl)
@@ -104,6 +108,7 @@ end
function http_update_pod_result(self, _, response)
kubernetes_pods = {}
msg.post("ui#gui", "error",{ errormessage = "k8s status code request: " .. response.status })
if response.status == 0 then
msg.post("ui#gui", "error",{ errormessage = "Error connecting to " .. conf['endpoint'] })
end
@@ -264,7 +269,6 @@ end
function init(self)
msg.post("ui#gui", "mode",{ mode = "You are using the manual mode. Press \"a\" to use switch to automatic"})
conf = {}
local path = os.getenv("HOME") .. "/.KubeInv.json"
local contents = ""
@@ -288,10 +292,17 @@ function init(self)
print( "namespace: ", conf["namespace"] )
endpoint = conf["endpoint"]
namespace = conf["namespace"]
token = conf["token"]
info = "Endpoint: " .. conf["endpoint"] .. "\n\n" .. "Namespace: " .. conf["namespace"]
namespace_cnt = 0
for i in string.gmatch(conf["namespace"], "[^,]+") do
namespace_list[namespace_cnt] = i
namespace_cnt = namespace_cnt + 1
end
namespace_total = table.getn(namespace_list)
namespace_cnt = 0
namespace = namespace_list[0]
info = "Endpoint: " .. conf["endpoint"] .. "\n\n" .. "Namespace: " .. namespace
msg.post("ui#gui", "info",{ infomessage = info })
msg.post(".", "acquire_input_focus")
@@ -334,15 +345,46 @@ function on_input(self, action_id, action)
local p = go.get_position()
p.x = p.x + 4
go.set_position(p)
elseif action_id == hash("click") and action.pressed then
print(action_id)
elseif action_id == hash("automatic") then
automatic = true
msg.post("ui#gui", "mode",{ mode = "You are using the automatic mode. Press \"m\" to use switch to manual"})
elseif action_id == hash("manual") then
print ("[change_mode] manual")
automatic = false
msg.post("ui#gui", "mode",{ mode = "You are using the manual mode. Press \"a\" to use switch to automatic"})
elseif action_id == hash("namespace") then
print ("[change_namespace] change namespaces requested by user")
msg.post("ui#gui", "error",{ errormessage = "changing namespace!" })
current_time = os.clock()
if last_namespace_change ~= false then
diff_time = current_time - last_namespace_change
print ("[change_namespace] diff_time ".. diff_time)
else
diff_time = 99
end
if diff_time > 0.1 then
for i,value in ipairs(current_pods) do
go.delete(value["id"])
end
current_pods = {}
if namespace_cnt > (namespace_total - 1) then
print ("[change_namespace] return to first namespace")
namespace = namespace_list[0]
namespace_cnt = 0
else
namespace_cnt = namespace_cnt + 1
print ("[change_namespace] go to namespace " .. namespace_cnt)
namespace = namespace_list[namespace_cnt]
end
end
last_namespace_change = os.clock()
info = "Endpoint: " .. conf["endpoint"] .. "\n\n" .. "Namespace: " .. namespace
msg.post("ui#gui", "info",{ infomessage = info })
elseif action_id == hash("space") and action.pressed then
msg.post("ui#gui", "error",{ errormessage = "" })