Skip to content

Commit 24209e6

Browse files
authored
fix: crash if targetContainer does not exist (#292)
Signed-off-by: hoyhbx <hoyhbx@gmail.com>
1 parent 8433cb4 commit 24209e6

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

k8sutils/redis.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,12 @@ func executeCommand(cr *redisv1beta1.RedisCluster, cmd []string, podName string)
274274
config, err := generateK8sConfig()
275275
if err != nil {
276276
logger.Error(err, "Could not find pod to execute")
277+
return
277278
}
278279
targetContainer, pod := getContainerID(cr, podName)
279280
if targetContainer < 0 {
280281
logger.Error(err, "Could not find pod to execute")
282+
return
281283
}
282284

283285
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)
290292
exec, err := remotecommand.NewSPDYExecutor(config, "POST", req.URL())
291293
if err != nil {
292294
logger.Error(err, "Failed to init executor")
295+
return
293296
}
294297

295298
err = exec.Stream(remotecommand.StreamOptions{
@@ -299,6 +302,7 @@ func executeCommand(cr *redisv1beta1.RedisCluster, cmd []string, podName string)
299302
})
300303
if err != nil {
301304
logger.Error(err, "Could not execute command", "Command", cmd, "Output", execOut.String(), "Error", execErr.String())
305+
return
302306
}
303307
logger.Info("Successfully executed the command", "Command", cmd, "Output", execOut.String())
304308
}

0 commit comments

Comments
 (0)