@@ -82,17 +82,38 @@ func (e *DefaultWaitExecHookHandler) HandleHooks(
8282 return nil
8383 }
8484
85+ var errors []error
8586 // If hooks are defined for a container that does not exist in the pod log a warning and discard
8687 // those hooks to avoid waiting for a container that will never become ready. After that if
8788 // there are no hooks left to be executed return immediately.
88- for containerName := range byContainer {
89+ // Discarded hooks must be recorded as failed in the hook tracker, otherwise the tracker
90+ // will never reach completion and the restore finalizer will poll forever waiting on hooks
91+ // that can never run.
92+ for containerName , hooks := range byContainer {
8993 if ! podHasContainer (pod , containerName ) {
90- log .Warningf ("Pod %s does not have container %s: discarding post-restore exec hooks" , kube .NamespaceAndName (pod ), containerName )
94+ discardErr := fmt .Errorf ("pod %s does not have container %s: discarding post-restore exec hooks" , kube .NamespaceAndName (pod ), containerName )
95+ log .Warning (discardErr )
96+ for i , hook := range hooks {
97+ hookLog := log .WithFields (
98+ logrus.Fields {
99+ "hookSource" : hook .HookSource ,
100+ "hookType" : "exec" ,
101+ "hookPhase" : "post" ,
102+ "hookName" : hook .HookName ,
103+ "container" : hook .Hook .Container ,
104+ },
105+ )
106+ errTracker := multiHookTracker .Record (restoreName , pod .Namespace , pod .Name , hook .Hook .Container , hook .HookSource , hook .HookName , HookPhase ("" ), i , true , discardErr )
107+ if errTracker != nil {
108+ hookLog .WithError (errTracker ).Warn ("Error recording the discarded hook in hook tracker" )
109+ }
110+ }
111+ errors = append (errors , discardErr )
91112 delete (byContainer , containerName )
92113 }
93114 }
94115 if len (byContainer ) == 0 {
95- return nil
116+ return errors
96117 }
97118
98119 // Every hook in every container can have its own wait timeout. Rather than setting up separate
@@ -108,8 +129,6 @@ func (e *DefaultWaitExecHookHandler) HandleHooks(
108129 }
109130 waitStart := time .Now ()
110131
111- var errors []error
112-
113132 // The first time this handler is called after a container starts running it will execute all
114133 // pending hooks for that container. Subsequent invocations of this handler will never execute
115134 // hooks in that container. It uses the byContainer map to keep track of which containers have
0 commit comments