diff --git a/pkg/action/hooks.go b/pkg/action/hooks.go index 8338b599a..3796b726a 100644 --- a/pkg/action/hooks.go +++ b/pkg/action/hooks.go @@ -48,16 +48,27 @@ func (cfg *Configuration) execHook(rl *release.Release, hook release.HookEvent, if err != nil { return errors.Wrapf(err, "unable to build kubernetes object for %s hook %s", hook, h.Path) } - if _, err := cfg.KubeClient.Create(resources); err != nil { - return errors.Wrapf(err, "warning: Hook %s %s failed", hook, h.Path) - } - // Get the time at which the hook was applied to the cluster + // Record the time at which the hook was applied to the cluster h.LastRun = release.HookExecution{ StartedAt: time.Now(), - Phase: release.HookPhaseUnknown, + Phase: release.HookPhaseRunning, + } + cfg.recordRelease(rl) + + // As long as the implementation of WatchUntilReady does not panic, HookPhaseFailed or HookPhaseSucceeded + // should always be set by this function. If we fail to do that for any reason, then HookPhaseUnknown is + // the most appropriate value to surface. + h.LastRun.Phase = release.HookPhaseUnknown + + // Create hook resources + if _, err := cfg.KubeClient.Create(resources); err != nil { + h.LastRun.CompletedAt = time.Now() + h.LastRun.Phase = release.HookPhaseFailed + return errors.Wrapf(err, "warning: Hook %s %s failed", hook, h.Path) } - // Execute the hook + + // Watch hook resources until they have completed err = cfg.KubeClient.WatchUntilReady(resources, timeout) // Note the time of success/failure h.LastRun.CompletedAt = time.Now() diff --git a/pkg/release/hook.go b/pkg/release/hook.go index 5cec89e3a..96cc4f250 100644 --- a/pkg/release/hook.go +++ b/pkg/release/hook.go @@ -94,6 +94,8 @@ type HookPhase string const ( // HookPhaseUnknown indicates that a hook is in an unknown state HookPhaseUnknown HookPhase = "Unknown" + // HookPhaseRunning indicates that a hook is currently executing + HookPhaseRunning HookPhase = "Running" // HookPhaseSucceeded indicates that hook execution succeeded HookPhaseSucceeded HookPhase = "Succeeded" // HookPhaseFailed indicates that hook execution failed