From bb91f2a1bc30e023ab7f3b64c1be0d02389b3942 Mon Sep 17 00:00:00 2001 From: Chris Pressland Date: Thu, 19 Aug 2021 17:23:00 +0100 Subject: [PATCH 1/3] Added ability to limit Kubedoom to a specific namespace --- README.md | 4 +++- kubedoom.go | 15 ++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 5e35922..ac56669 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,8 @@ $ docker run -p5901:5900 \ storaxdev/kubedoom:0.5.0 ``` +Optionally, if you set `-e NAMESPACE={your namespace}` you can limit Kubedoom to deleting pods in a single namespace + ### With Podman Run `storaxdev/kubedoom:0.5.0` with podman locally: @@ -97,7 +99,7 @@ the worker node. Then run kubedoom inside the cluster by applying the manifest provided in this repository: ```console -$ kubectl apply -f manifest/ +$ kubectl apply -k manifest/ namespace/kubedoom created deployment.apps/kubedoom created serviceaccount/kubedoom created diff --git a/kubedoom.go b/kubedoom.go index f0d3758..d0349cf 100644 --- a/kubedoom.go +++ b/kubedoom.go @@ -25,7 +25,7 @@ func hash(input string) int32 { func runCmd(cmdstring string) { parts := strings.Split(cmdstring, " ") - cmd := exec.Command(parts[0], parts[1:len(parts)]...) + cmd := exec.Command(parts[0], parts[1:]...) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr err := cmd.Run() @@ -35,7 +35,7 @@ func runCmd(cmdstring string) { } func outputCmd(argv []string) string { - cmd := exec.Command(argv[0], argv[1:len(argv)]...) + cmd := exec.Command(argv[0], argv[1:]...) cmd.Stderr = os.Stderr output, err := cmd.Output() if err != nil { @@ -46,7 +46,7 @@ func outputCmd(argv []string) string { func startCmd(cmdstring string) { parts := strings.Split(cmdstring, " ") - cmd := exec.Command(parts[0], parts[1:len(parts)]...) + cmd := exec.Command(parts[0], parts[1:]...) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr cmd.Stdin = os.Stdin @@ -65,7 +65,12 @@ type podmode struct { } func (m podmode) getEntities() []string { - args := []string{"kubectl", "get", "pods", "-A", "-o", "go-template", "--template={{range .items}}{{.metadata.namespace}}/{{.metadata.name}} {{end}}"} + var args []string + if namespace, exists := os.LookupEnv("NAMESPACE"); exists { + args = []string{"kubectl", "get", "pods", "--namespace", namespace, "-o", "go-template", "--template={{range .items}}{{.metadata.namespace}}/{{.metadata.name}} {{end}}"} + } else { + args = []string{"kubectl", "get", "pods", "-A", "-o", "go-template", "--template={{range .items}}{{.metadata.namespace}}/{{.metadata.name}} {{end}}"} + } output := outputCmd(args) outputstr := strings.TrimSpace(output) pods := strings.Split(outputstr, " ") @@ -97,7 +102,7 @@ func (m nsmode) deleteEntity(entity string) { } func socketLoop(listener net.Listener, mode Mode) { - for true { + for { conn, err := listener.Accept() if err != nil { panic(err) From f7657a39a1a17d0508b4d38e5382e87436cc52eb Mon Sep 17 00:00:00 2001 From: Chris Pressland Date: Thu, 19 Aug 2021 17:23:37 +0100 Subject: [PATCH 2/3] Added kustomization file to manifests, to avoid `00` naming --- manifest/kustomization.yaml | 4 ++++ manifest/{00namespace.yaml => namespace.yaml} | 0 2 files changed, 4 insertions(+) create mode 100644 manifest/kustomization.yaml rename manifest/{00namespace.yaml => namespace.yaml} (100%) diff --git a/manifest/kustomization.yaml b/manifest/kustomization.yaml new file mode 100644 index 0000000..cffbef1 --- /dev/null +++ b/manifest/kustomization.yaml @@ -0,0 +1,4 @@ +resources: + - namespace.yaml + - deployment.yaml + - rbac.yaml diff --git a/manifest/00namespace.yaml b/manifest/namespace.yaml similarity index 100% rename from manifest/00namespace.yaml rename to manifest/namespace.yaml From afa5b3af48e6876f6dec477b1344f18624cd119f Mon Sep 17 00:00:00 2001 From: Chris Pressland Date: Thu, 19 Aug 2021 17:40:54 +0100 Subject: [PATCH 3/3] Lowered difficulty, disabled mouse --- kubedoom.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kubedoom.go b/kubedoom.go index d0349cf..948eca5 100644 --- a/kubedoom.go +++ b/kubedoom.go @@ -174,6 +174,6 @@ func main() { log.Print("You can now connect to it with a VNC viewer at port 5900") log.Print("Trying to start DOOM ...") - startCmd("/usr/bin/env DISPLAY=:99 /usr/local/games/psdoom -warp -E1M1") + startCmd("/usr/bin/env DISPLAY=:99 /usr/local/games/psdoom -warp -E1M1 -skill 1 -nomouse") socketLoop(listener, mode) }