Skip to content
Snippets Groups Projects
Unverified Commit 24209e6f authored by Acto Team's avatar Acto Team Committed by GitHub
Browse files

fix: crash if targetContainer does not exist (#292)


Signed-off-by: default avatarhoyhbx <hoyhbx@gmail.com>
parent 8433cb41
No related branches found
No related tags found
No related merge requests found
......@@ -274,10 +274,12 @@ func executeCommand(cr *redisv1beta1.RedisCluster, cmd []string, podName string)
config, err := generateK8sConfig()
if err != nil {
logger.Error(err, "Could not find pod to execute")
return
}
targetContainer, pod := getContainerID(cr, podName)
if targetContainer < 0 {
logger.Error(err, "Could not find pod to execute")
return
}
req := generateK8sClient().CoreV1().RESTClient().Post().Resource("pods").Name(podName).Namespace(cr.Namespace).SubResource("exec")
......@@ -290,6 +292,7 @@ func executeCommand(cr *redisv1beta1.RedisCluster, cmd []string, podName string)
exec, err := remotecommand.NewSPDYExecutor(config, "POST", req.URL())
if err != nil {
logger.Error(err, "Failed to init executor")
return
}
err = exec.Stream(remotecommand.StreamOptions{
......@@ -299,6 +302,7 @@ func executeCommand(cr *redisv1beta1.RedisCluster, cmd []string, podName string)
})
if err != nil {
logger.Error(err, "Could not execute command", "Command", cmd, "Output", execOut.String(), "Error", execErr.String())
return
}
logger.Info("Successfully executed the command", "Command", cmd, "Output", execOut.String())
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment