From 24209e6f473da93ec62f1f0a139b19cfdd889020 Mon Sep 17 00:00:00 2001 From: Acto Team <97862925+hoyhbx@users.noreply.github.com> Date: Tue, 28 Jun 2022 04:47:10 -0500 Subject: [PATCH] fix: crash if targetContainer does not exist (#292) Signed-off-by: hoyhbx --- k8sutils/redis.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/k8sutils/redis.go b/k8sutils/redis.go index 1f6c70591..e2ee8e820 100644 --- a/k8sutils/redis.go +++ b/k8sutils/redis.go @@ -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()) }