Skip to content

Commit

Permalink
chore(signal): Adding signal for the crio/containerd runtime (#306)
Browse files Browse the repository at this point in the history
Signed-off-by: shubhamchaudhary <shubham@chaosnative.com>
  • Loading branch information
ispeakc0de committed Mar 8, 2021
1 parent 4fc421d commit 587fd10
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions chaoslib/litmus/container-kill/helper/container-kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func KillContainer(experimentsDetails *experimentTypes.ExperimentDetails, client
return err
}
case "containerd", "crio":
if err := StopContainerdContainer(containerID, experimentsDetails.SocketPath); err != nil {
if err := StopContainerdContainer(containerID, experimentsDetails.SocketPath, experimentsDetails.Signal); err != nil {
return err
}
default:
Expand Down Expand Up @@ -152,10 +152,18 @@ func GetContainerID(experimentsDetails *experimentTypes.ExperimentDetails, clien
}

//StopContainerdContainer kill the application container
func StopContainerdContainer(containerID, socketPath string) error {
func StopContainerdContainer(containerID, socketPath, signal string) error {
var errOut bytes.Buffer
var cmd *exec.Cmd
endpoint := "unix://" + socketPath
cmd := exec.Command("crictl", "-i", endpoint, "-r", endpoint, "stop", string(containerID))
switch signal {
case "SIGKILL":
cmd = exec.Command("crictl", "-i", endpoint, "-r", endpoint, "stop", "--timeout=0", string(containerID))
case "SIGTERM":
cmd = exec.Command("crictl", "-i", endpoint, "-r", endpoint, "stop", string(containerID))
default:
return errors.Errorf("{%v} signal not supported, use either SIGTERM or SIGKILL", signal)
}
cmd.Stderr = &errOut
if err := cmd.Run(); err != nil {
return errors.Errorf("Unable to run command, err: %v; error output: %v", err, errOut.String())
Expand Down

0 comments on commit 587fd10

Please sign in to comment.