Created
April 23, 2024 15:15
-
-
Save endocrimes/b7a6e542d7f3fc5f3205317d9f6b942c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bytes" | |
_ "embed" | |
"fmt" | |
"os" | |
"os/exec" | |
"strings" | |
) | |
//go:embed uwugoose | |
var goose string | |
var realKubectlPath = "/usr/bin/uwuctl" | |
// var realKubectlPath = "/opt/homebrew/bin/kubectl" | |
func main() { | |
defer func() { | |
if r := recover(); r != nil { | |
fmt.Println("i did a goof and this panicked, so now you know my terrible secret") | |
fmt.Println(goose) | |
os.Exit(0) | |
} | |
}() | |
args := os.Args | |
var containsAllNamespaces bool | |
for i, arg := range args { | |
if strings.EqualFold(arg, "-n") && args[i+1] == "kube-system" { | |
fmt.Println("No resources found in kube-system namespace.") | |
os.Exit(0) | |
} else if strings.EqualFold(arg, "--namespace") && args[i+1] == "kube-system" { | |
fmt.Println("No resources found in kube-system namespace.") | |
os.Exit(0) | |
} | |
if strings.EqualFold(arg, "--all") || strings.EqualFold(arg, "--all-namespaces") { | |
containsAllNamespaces = true | |
} | |
if strings.Contains(arg, "webhook") { | |
fmt.Println("No resources found") | |
os.Exit(0) | |
} | |
if strings.EqualFold(arg, "delete") && len(args) >= i+1 && strings.Contains(args[i+1], "pod") { | |
if strings.Contains(args[i+1], "/") { | |
fmt.Println("pod \"" + strings.Split(args[i+1], "/")[1] + "\" deleted") | |
os.Exit(0) | |
} | |
fmt.Println("pod \"" + args[i+2] + "\" deleted") | |
os.Exit(0) | |
} | |
} | |
if len(args) > 3 && !containsAllNamespaces { | |
fmt.Println(goose) | |
os.Exit(0) | |
} | |
cmd := exec.Command(realKubectlPath, args[1:]...) | |
var out bytes.Buffer | |
cmd.Stdout = &out | |
cmd.Stderr = os.Stderr | |
cmd.Stdin = os.Stdin | |
_ = cmd.Run() | |
outBytes := out.Bytes() | |
outStr := string(outBytes) | |
lines := strings.Split(outStr, "\n") | |
for _, line := range lines { | |
if strings.Contains(line, "kube-system") { | |
continue | |
} | |
if strings.Contains(line, "honked") { | |
continue | |
} | |
fmt.Println(line) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment