Skip to content

Commit

Permalink
Check container is ready and not running before exec a hook
Browse files Browse the repository at this point in the history
Signed-off-by: Ripolin <[email protected]>
  • Loading branch information
Ripolin committed Oct 4, 2023
1 parent 7f73aca commit 278125e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions internal/hook/wait_exec_hook_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -243,15 +243,15 @@ 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
}
for _, cs := range pod.Status.ContainerStatuses {
if cs.Name != containerName {
continue
}
return cs.State.Running != nil
return cs.Ready
}

return false
Expand Down
4 changes: 2 additions & 2 deletions internal/hook/wait_exec_hook_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
})
}
Expand Down

0 comments on commit 278125e

Please sign in to comment.