I am trying to kill a container using client-go and e2e framework in Golang but not able to do it successfully. Example of the full implementation can be accessed e2e apart from this I am using kind image as "kindest/node:v1.26.6"
I have tried the following commands but none using the following pieces of code.
args := []string{"kill", "1"}
var stdout, stderr bytes.Buffer
err := cfg.Client().Resources().ExecInPod(ctx, namespace, podName, containerName, args, &stdout, &stderr)
args = []string{"/bin/sh", "-c", "'kill", "1'"}
err = cfg.Client().Resources().ExecInPod(ctx, namespace, podName, containerName, args, &stdout, &stderr)
args = []string{"/bin/sh", "-c", "\"kill 1\""}
err = cfg.Client().Resources().ExecInPod(ctx, namespace, podName, containerName, args, &stdout, &stderr)
But all of them are giving error. Some are giving
exec failed: unable to start container process: exec: "kill": executable file not found in $PATH: unknown"
while some are giving
"command terminated with exit code 127" or "command terminated with exit code 2"
I have also tried the following and it is working but in this case I have a dependency on kubectl which I want to avoid.
cmdString := fmt.Sprintf("/c kubectl exec -it %s -n %s -c %s -- bash -c 'kill 1'", podName, namespace, containerName)
args := strings.Split(cmdString, " ")
cmd := exec.Command("powershell", args...)
err := cmd.Run()