From 55873c1c37c663847a4abaaa5bf9ecbe20185d31 Mon Sep 17 00:00:00 2001 From: Dylan Murray Date: Tue, 13 Dec 2022 00:45:52 -0500 Subject: [PATCH] Prevent nil panic on exec restore hooks (#5675) * Prevent nil panic on exec restore hooks Signed-off-by: Dylan Murray --- changelogs/unreleased/5675-dymurray | 1 + pkg/controller/restore_controller.go | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 changelogs/unreleased/5675-dymurray diff --git a/changelogs/unreleased/5675-dymurray b/changelogs/unreleased/5675-dymurray new file mode 100644 index 0000000000..a7162e48a2 --- /dev/null +++ b/changelogs/unreleased/5675-dymurray @@ -0,0 +1 @@ +Prevent nil panic on exec restore hooks diff --git a/pkg/controller/restore_controller.go b/pkg/controller/restore_controller.go index 038e971095..9e2eb31d75 100644 --- a/pkg/controller/restore_controller.go +++ b/pkg/controller/restore_controller.go @@ -342,10 +342,12 @@ func (c *restoreController) validateAndComplete(restore *api.Restore, pluginMana } for _, resource := range restoreHooks { for _, h := range resource.RestoreHooks { - for _, container := range h.Init.InitContainers { - err = hook.ValidateContainer(container.Raw) - if err != nil { - restore.Status.ValidationErrors = append(restore.Status.ValidationErrors, err.Error()) + if h.Init != nil { + for _, container := range h.Init.InitContainers { + err = hook.ValidateContainer(container.Raw) + if err != nil { + restore.Status.ValidationErrors = append(restore.Status.ValidationErrors, err.Error()) + } } } }