Skip to content

Commit

Permalink
Merge pull request #14 from binkhq/master
Browse files Browse the repository at this point in the history
Namespace restrictions & quality of life enhancements
  • Loading branch information
storax committed Aug 21, 2021
2 parents 759d3ed + afa5b3a commit f834f32
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
17 changes: 11 additions & 6 deletions kubedoom.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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, " ")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -169,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)
}
4 changes: 4 additions & 0 deletions manifest/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resources:
- namespace.yaml
- deployment.yaml
- rbac.yaml
File renamed without changes.

0 comments on commit f834f32

Please sign in to comment.