mirror of
https://github.com/lucky-sideburn/kubeinvaders.git
synced 2026-02-14 17:50:00 +00:00
add kubeping
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,4 +1,5 @@
|
||||
develop.tar
|
||||
kimsufi.sh
|
||||
utils
|
||||
dev-tools/*.tgz
|
||||
.vagrant
|
||||
|
||||
@@ -41,7 +41,6 @@ function getIngressLists() {
|
||||
var oReq = new XMLHttpRequest();
|
||||
oReq.onreadystatechange = function () {
|
||||
if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
|
||||
console.log("[SAVE-CHAOS-REPORT-INGRESS-LISTS]" + JSON.parse(this.responseText));
|
||||
parseIngressListJSON(JSON.parse(this.responseText));
|
||||
}
|
||||
};;
|
||||
@@ -51,9 +50,7 @@ function getIngressLists() {
|
||||
}
|
||||
|
||||
function diffBetweenTwoDates(date1, date2) {
|
||||
// console.log("[SAVE-CHAOS-REPORT-CONF] Diff between two dates: " + date1 + " and " + date2);
|
||||
var diff = (date2.getTime() - date1.getTime()) / 1000;
|
||||
// console.log("[SAVE-CHAOS-REPORT-CONF] Diff between two dates: " + diff + " seconds")
|
||||
return diff;
|
||||
}
|
||||
|
||||
|
||||
@@ -164,8 +164,28 @@
|
||||
|
||||
|
||||
<div id="main-game-div" style="display: block;">
|
||||
<!-- Modal -->
|
||||
<div class="modal fade id="currentChaosContainerModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
|
||||
|
||||
<div class="modal fade" id="kubePingModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
|
||||
<div class="modal-dialog modal-lg" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h6 class="modal-title">Help us improve KubeInvaders</h6>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p style="color: #161616; font-size: medium; font-weight: normal;">KubeInvaders is still under active development. To help us better understand how the game is being used and identify any potential issues, we kindly request your permission to send an anonymous ping to our systems.
|
||||
This ping will help us gather usage statistics without revealing any personal information. You can opt out of this at any time by changing your settings.
|
||||
Would you like to help us improve KubeInvaders by sending an anonymous ping?
|
||||
</p>
|
||||
<div class="modal-footer">
|
||||
<button type="button" id="saveButton" class="btn btn-light" onclick="setKubePingStatusPing(1)">Ping</button>
|
||||
<button type="button" id="closeButton3" class="btn btn-dark" data-dismiss="modal" onclick="setKubePingStatusPing(0)">Don't ping</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal fade" id="currentChaosContainerModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-body">
|
||||
@@ -573,7 +593,7 @@ Using YAML programming, you can define your own chaos engineering experiments an
|
||||
<form>
|
||||
<div class="form-group">
|
||||
<label for="chaosProgramTextArea"></label>
|
||||
<textarea class="form-control chaos-prog-area" id="chaosProgramTextArea" rows="50" style="min-width: 100%; font-family: Courier, monospace;">
|
||||
<textarea class="form-control chaos-prog-area" id="chaosProgramTextArea" rows="50" style="min-width: 100%; font-weight: normal; font-size: small;">
|
||||
chaos-codename: CODENAME_PLACEHOLDER
|
||||
experiments:
|
||||
- name: cpu_attack_exp
|
||||
@@ -709,14 +729,14 @@ k8s_jobs:
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="./bootstrap-5.0.0-dist/js/bootstrap.min.js"></script>
|
||||
<script src="./js/jquery-3.6.0.min.js"></script>
|
||||
<script src="./js/popper.min.js"></script>
|
||||
<script src="./utils.js"></script>
|
||||
<script src="./programming_mode.js"></script>
|
||||
<script src="./modals.js"></script>
|
||||
<script src="./mode_controls.js"></script>
|
||||
<script src="./game_console.js"></script>
|
||||
<script src="./bootstrap-5.0.0-dist/js/bootstrap.min.js"></script>
|
||||
<script src="./js/jquery-3.6.0.min.js"></script>
|
||||
<script src="./js/popper.min.js"></script>
|
||||
<script src="./kubeinvaders.js"></script>
|
||||
<script src="./echarts/echarts.min.js"></script>
|
||||
<script src="./chaos_report.js"></script>
|
||||
|
||||
@@ -55,6 +55,7 @@ var random_code = (Math.random() + 1).toString(36).substring(7);
|
||||
var change_codename = false;
|
||||
var latest_sent_chaos_program = "";
|
||||
var editor = null;
|
||||
var kubeping_sent = false;
|
||||
|
||||
var editor_chaos_container_definition = CodeMirror.fromTextArea(currentChaosContainerJsonTextArea, {
|
||||
lineNumbers: true,
|
||||
|
||||
@@ -3,6 +3,17 @@ function setModalState(state) {
|
||||
modal_opened = state;
|
||||
}
|
||||
|
||||
function showKubePingModal() {
|
||||
if (!kubeping_sent) {
|
||||
$('#kubePingModal').modal('show');
|
||||
KubePingStatus();
|
||||
}
|
||||
}
|
||||
|
||||
function closeKubePingModal() {
|
||||
$('#kubePingModal').modal('hide');
|
||||
}
|
||||
|
||||
function showCurrentChaosContainer() {
|
||||
getCurrentChaosContainer();
|
||||
$('#currentChaosContainerModal').modal('show');
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/* Functions for controlling game modes */
|
||||
|
||||
function startGameMode() {
|
||||
kubePingModalSwitch();
|
||||
if (game_mode_switch) {
|
||||
game_mode_switch = false;
|
||||
$("#gameModeButton").text("Enable Game Mode");
|
||||
@@ -36,6 +37,7 @@ function startGameMode() {
|
||||
}
|
||||
|
||||
function startProgrammingMode() {
|
||||
kubePingModalSwitch();
|
||||
if (is_demo_mode()) {
|
||||
demo_mode_alert();
|
||||
return;
|
||||
|
||||
@@ -169,9 +169,9 @@ body {
|
||||
background-color: #ffffff;
|
||||
}
|
||||
|
||||
div {
|
||||
/* div {
|
||||
font-family: pixel;
|
||||
}
|
||||
} */
|
||||
|
||||
.game-canvas {
|
||||
background: #161616;
|
||||
|
||||
@@ -47,3 +47,31 @@ function demo_mode_alert() {
|
||||
function is_demo_mode() {
|
||||
return demo_mode;
|
||||
}
|
||||
|
||||
function kubePingModalSwitch() {
|
||||
var oReq = new XMLHttpRequest();
|
||||
oReq.onreadystatechange = function () {
|
||||
if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
|
||||
console.log("[K-INV STARTUP] kubeping status is: |" + this.responseText.trim() + "|");
|
||||
if (this.responseText.trim() == "Key not found" || is_demo_mode()) {
|
||||
showKubePingModal()
|
||||
}
|
||||
}
|
||||
};;
|
||||
oReq.open("GET", k8s_url + "/chaos/redis/get?key=kubeping", true);
|
||||
oReq.send();
|
||||
}
|
||||
|
||||
function setKubePingStatusPing(value) {
|
||||
var oReq = new XMLHttpRequest();
|
||||
oReq.open("POST", k8s_url + "/chaos/redis/set?key=kubeping", true);
|
||||
|
||||
oReq.onreadystatechange = function () {
|
||||
if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
|
||||
kubeping_sent = true;
|
||||
}
|
||||
};;
|
||||
oReq.setRequestHeader("Content-Type", "application/text");
|
||||
oReq.send(String(value));
|
||||
closeKubePingModal();
|
||||
}
|
||||
44
kimsufi.sh
44
kimsufi.sh
@@ -1,44 +0,0 @@
|
||||
function build() {
|
||||
journalctl --vacuum-size=1M
|
||||
rm -rf /var/lib/containers/storage/*
|
||||
rm -rf /run/containers/storage/*
|
||||
podman system reset -f
|
||||
/bin/cp Dockerfile_full Dockerfile
|
||||
podman build /usr/local/src/kubeinvaders -t 10.10.10.3:5000/local/kubeinvaders:develop
|
||||
for i in $(podman ps -a | grep -v CONTAINER | awk '{ print $1}'); do podman rm $i -f ; done
|
||||
podman tag 10.10.10.3:5000/local/kubeinvaders:develop 10.10.10.3:5000/local/kubeinvaders_base:develop
|
||||
podman push 10.10.10.3:5000/local/kubeinvaders_base:develop
|
||||
}
|
||||
|
||||
function build_redux() {
|
||||
journalctl --vacuum-size=1M
|
||||
/bin/cp Dockerfile_redux Dockerfile
|
||||
for i in $(podman ps -a | grep -v CONTAINER | awk '{ print $1}'); do podman rm $i -f ; done
|
||||
podman build /usr/local/src/kubeinvaders -t 10.10.10.3:5000/local/kubeinvaders:develop
|
||||
}
|
||||
|
||||
function run(){
|
||||
podman run -p 8080:8080 \
|
||||
--env K8S_TOKEN=eyJhbGciOiJSUzI1NiIsImtpZCI6ImlrbVNQMWg5QUVCLVhjQl9uT0V4aVpQY0RNdTR2aVVHTzdJeXBZSXNnZkkifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlaW52YWRlcnMiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlY3JldC5uYW1lIjoia3ViZWludmFkZXJzLXRva2VuLWo1Y3hzIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6Imt1YmVpbnZhZGVycyIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6ImYxOTViODI4LWRhZTYtNGM1ZC05YzliLTVlOGQwYTI0NTEzZiIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDprdWJlaW52YWRlcnM6a3ViZWludmFkZXJzIn0.NqVdsSw3cs3jMevheokUNPfb9WmlQe7g6CrAytcApq9Z9FFFomXib5kb1fgdKYVJn4vb0a6H3kHB8hKJo0UcPu24wVCAYwxsfCTuK13tsCJxrycs2TxyoTWsXALMbBMgDJthCal14RwikWFpW4EyHryqkEAAn-U5goBdaabCSHhWCiR4ulbmuKy8xep8yppRw66505hq4Rdc6gMcj4_bgTDLKSh_g1lySHdHiiTo1v5X71_BD5QEKIEj2Ak4mslpAy-aQUOso4HicIIvd7I1NLDfis1Scj9IjhL8jdRXrOSk9KUbFBJCOMCye2pSYK3eqRDsjVe7BKPZB53WtMW7ew \
|
||||
--env ENDPOINT=localhost:8080 \
|
||||
--env KUBERNETES_SERVICE_HOST=10.10.10.4 \
|
||||
--env KUBERNETES_SERVICE_PORT_HTTPS=6443 \
|
||||
--env INSECURE_ENDPOINT=true \
|
||||
--env NAMESPACE=namespace1,namespace2 \
|
||||
10.10.10.3:5000/local/kubeinvaders:develop
|
||||
}
|
||||
|
||||
if [ "$1" == "build" ]; then
|
||||
build
|
||||
elif [ "$1" == "run" ]; then
|
||||
run
|
||||
elif [ "$1" == "all" ]; then
|
||||
build
|
||||
run
|
||||
elif [ "$1" == "allredux" ]; then
|
||||
build_redux
|
||||
run
|
||||
else
|
||||
echo "Usage: $0 [build|run]"
|
||||
fi
|
||||
|
||||
@@ -118,7 +118,48 @@ server {
|
||||
local args = ngx.req.get_uri_args()
|
||||
local key = args["key"]
|
||||
|
||||
ngx.say(tostring(red:get(key)))
|
||||
if red:exists(key) == 0 then
|
||||
ngx.say("Key not found")
|
||||
else
|
||||
ngx.say(tostring(red:get(key)))
|
||||
end
|
||||
}
|
||||
}
|
||||
|
||||
location /chaos/redis/set {
|
||||
content_by_lua_block {
|
||||
local redis = require "resty.redis"
|
||||
local red = redis:new()
|
||||
local okredis, errredis = red:connect("unix:/tmp/redis.sock")
|
||||
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.req.read_body()
|
||||
local data = ngx.req.get_body_data()
|
||||
local args = ngx.req.get_uri_args()
|
||||
local key = args["key"]
|
||||
ngx.log(ngx.INFO, "[KUBEPING] Setting key " .. key .. " with data |" .. tostring(data) .. "|")
|
||||
ngx.say(tostring(red:set(key, tostring(data))))
|
||||
|
||||
if key == "kubeping" and data == "1" then
|
||||
local http = require("socket.http")
|
||||
|
||||
local function get_data(url)
|
||||
local respbody = {}
|
||||
local code, response = http.request(url)
|
||||
if code == 200 then
|
||||
local json = require("json")
|
||||
respbody = json.decode(response)
|
||||
else
|
||||
print("Errore nella richiesta: " .. code)
|
||||
end
|
||||
return respbody
|
||||
end
|
||||
|
||||
local data = get_data("https://devopstribe.it/kubeping")
|
||||
print(data.result)
|
||||
end
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user