From 278125ed163877b1c1ab36876ec2a87c4c662b0f Mon Sep 17 00:00:00 2001 From: Ripolin Date: Wed, 4 Oct 2023 15:51:23 +0200 Subject: [PATCH] Check container is ready and not running before exec a hook Signed-off-by: Ripolin --- internal/hook/wait_exec_hook_handler.go | 6 +++--- internal/hook/wait_exec_hook_handler_test.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/hook/wait_exec_hook_handler.go b/internal/hook/wait_exec_hook_handler.go index 890a8117bd..7b62d38961 100644 --- a/internal/hook/wait_exec_hook_handler.go +++ b/internal/hook/wait_exec_hook_handler.go @@ -126,7 +126,7 @@ func (e *DefaultWaitExecHookHandler) HandleHooks( } for containerName, hooks := range byContainer { - if !isContainerRunning(newPod, containerName) { + if !isContainerReady(newPod, containerName) { podLog.Infof("Container %s is not running: post-restore hooks will not yet be executed", containerName) continue } @@ -243,7 +243,7 @@ func podHasContainer(pod *v1.Pod, containerName string) bool { return false } -func isContainerRunning(pod *v1.Pod, containerName string) bool { +func isContainerReady(pod *v1.Pod, containerName string) bool { if pod == nil { return false } @@ -251,7 +251,7 @@ func isContainerRunning(pod *v1.Pod, containerName string) bool { if cs.Name != containerName { continue } - return cs.State.Running != nil + return cs.Ready } return false diff --git a/internal/hook/wait_exec_hook_handler_test.go b/internal/hook/wait_exec_hook_handler_test.go index 933e5d34df..67813d1ca7 100644 --- a/internal/hook/wait_exec_hook_handler_test.go +++ b/internal/hook/wait_exec_hook_handler_test.go @@ -790,7 +790,7 @@ func TestPodHasContainer(t *testing.T) { } } -func TestIsContainerRunning(t *testing.T) { +func TestIsContainerReady(t *testing.T) { tests := []struct { name string pod *v1.Pod @@ -856,7 +856,7 @@ func TestIsContainerRunning(t *testing.T) { } for _, test := range tests { t.Run(test.name, func(t *testing.T) { - actual := isContainerRunning(test.pod, test.container) + actual := isContainerReady(test.pod, test.container) assert.Equal(t, actual, test.expect) }) }