@@ -85,11 +85,11 @@ func KillContainer(experimentsDetails *experimentTypes.ExperimentDetails, client
8585
8686 switch experimentsDetails .ContainerRuntime {
8787 case "docker" :
88- if err := StopDockerContainer (containerID , experimentsDetails .SocketPath ); err != nil {
88+ if err := StopDockerContainer (containerID , experimentsDetails .SocketPath , experimentsDetails . Signal ); err != nil {
8989 return err
9090 }
9191 case "containerd" , "crio" :
92- if err := StopContainerdContainer (containerID , experimentsDetails .SocketPath ); err != nil {
92+ if err := StopContainerdContainer (containerID , experimentsDetails .SocketPath , experimentsDetails . Signal ); err != nil {
9393 return err
9494 }
9595 default :
@@ -152,10 +152,18 @@ func GetContainerID(experimentsDetails *experimentTypes.ExperimentDetails, clien
152152}
153153
154154//StopContainerdContainer kill the application container
155- func StopContainerdContainer (containerID , socketPath string ) error {
155+ func StopContainerdContainer (containerID , socketPath , signal string ) error {
156156 var errOut bytes.Buffer
157+ var cmd * exec.Cmd
157158 endpoint := "unix://" + socketPath
158- cmd := exec .Command ("crictl" , "-i" , endpoint , "-r" , endpoint , "stop" , string (containerID ))
159+ switch signal {
160+ case "SIGKILL" :
161+ cmd = exec .Command ("crictl" , "-i" , endpoint , "-r" , endpoint , "stop" , "--timeout=0" , string (containerID ))
162+ case "SIGTERM" :
163+ cmd = exec .Command ("crictl" , "-i" , endpoint , "-r" , endpoint , "stop" , string (containerID ))
164+ default :
165+ return errors .Errorf ("{%v} signal not supported, use either SIGTERM or SIGKILL" , signal )
166+ }
159167 cmd .Stderr = & errOut
160168 if err := cmd .Run (); err != nil {
161169 return errors .Errorf ("Unable to run command, err: %v; error output: %v" , err , errOut .String ())
@@ -164,10 +172,10 @@ func StopContainerdContainer(containerID, socketPath string) error {
164172}
165173
166174//StopDockerContainer kill the application container
167- func StopDockerContainer (containerID , socketPath string ) error {
175+ func StopDockerContainer (containerID , socketPath , signal string ) error {
168176 var errOut bytes.Buffer
169177 host := "unix://" + socketPath
170- cmd := exec .Command ("docker" , "--host" , host , "kill" , string (containerID ))
178+ cmd := exec .Command ("docker" , "--host" , host , "kill" , string (containerID ), "--signal" , signal )
171179 cmd .Stderr = & errOut
172180 if err := cmd .Run (); err != nil {
173181 return errors .Errorf ("Unable to run command, err: %v; error output: %v" , err , errOut .String ())
@@ -268,6 +276,7 @@ func GetENV(experimentDetails *experimentTypes.ExperimentDetails, name string) {
268276 experimentDetails .ChaosPodName = Getenv ("POD_NAME" , "" )
269277 experimentDetails .SocketPath = Getenv ("SOCKET_PATH" , "" )
270278 experimentDetails .ContainerRuntime = Getenv ("CONTAINER_RUNTIME" , "" )
279+ experimentDetails .Signal = Getenv ("SIGNAL" , "SIGKILL" )
271280}
272281
273282// Getenv fetch the env and set the default value, if any
0 commit comments