Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(signal): Adding signal for the crio/containerd runtime #306

Merged
merged 1 commit into from
Mar 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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