mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-08-25 16:46:19 +00:00
prevent panic when the restore hook init container command annotation is empty (#10371)
* prevent panic when the restore hook init container command annotation is empty Signed-off-by: samay43 <samayrbhat43@gmail.com> * add changelog entry Signed-off-by: samay43 <samayrbhat43@gmail.com> --------- Signed-off-by: samay43 <samayrbhat43@gmail.com> Co-authored-by: Daniel Jiang <daniel.jiang@broadcom.com>
This commit is contained in:
@@ -0,0 +1 @@
|
||||
prevent panic when the restore hook init container command annotation is empty
|
||||
@@ -365,6 +365,12 @@ func getPodExecHookFromAnnotations(annotations map[string]string, phase HookPhas
|
||||
|
||||
func parseStringToCommand(commandValue string) []string {
|
||||
var command []string
|
||||
// An empty command means the container image's own entrypoint should be used.
|
||||
// Callers that require a command already return early; getInitContainerFromAnnotation
|
||||
// deliberately allows this case, so return nil rather than indexing an empty string.
|
||||
if commandValue == "" {
|
||||
return nil
|
||||
}
|
||||
// check for json array
|
||||
if commandValue[0] == '[' {
|
||||
if err := json.Unmarshal([]byte(commandValue), &command); err != nil {
|
||||
|
||||
@@ -1287,6 +1287,25 @@ func TestGetInitContainerFromAnnotations(t *testing.T) {
|
||||
podRestoreHookInitContainerCommandAnnotationKey: "[foobarbaz",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "should use the image's default entrypoint when the command annotation is empty",
|
||||
expectNil: false,
|
||||
expected: builder.ForContainer("restore-init1", "busy-box").Result(),
|
||||
inputAnnotations: map[string]string{
|
||||
podRestoreHookInitContainerImageAnnotationKey: "busy-box",
|
||||
podRestoreHookInitContainerNameAnnotationKey: "restore-init",
|
||||
podRestoreHookInitContainerCommandAnnotationKey: "",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "should use the image's default entrypoint when the command annotation is missing",
|
||||
expectNil: false,
|
||||
expected: builder.ForContainer("restore-init1", "busy-box").Result(),
|
||||
inputAnnotations: map[string]string{
|
||||
podRestoreHookInitContainerImageAnnotationKey: "busy-box",
|
||||
podRestoreHookInitContainerNameAnnotationKey: "restore-init",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
|
||||
Reference in New Issue
Block a user