Skip to content

Commit

Permalink
Address code review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
  • Loading branch information
alexmt committed Dec 17, 2023
1 parent f3874a6 commit 230db9b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 0 additions & 1 deletion controller/appcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,6 @@ func (ctrl *ApplicationController) finalizeApplicationDeletion(app *appv1.Applic
return nil
}
logCtx.Infof("Successfully deleted %d resources", len(objs))
logCtx.Infof("Resource entries removed from undefined cluster")
app.UnSetCascadedDeletion()
return ctrl.updateFinalizers(app)
}
Expand Down
12 changes: 11 additions & 1 deletion controller/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ func (ctrl *ApplicationController) cleanupPostDeleteHooks(liveObjs map[kube.Reso
healthOverrides := lua.ResourceHealthOverrides(resourceOverrides)

pendingDeletionCount := 0
aggregatedHealth := health.HealthStatusHealthy
var hooks []*unstructured.Unstructured
for _, obj := range liveObjs {
if !isPostDeleteHook(obj) {
continue
Expand All @@ -126,8 +128,15 @@ func (ctrl *ApplicationController) cleanupPostDeleteHooks(liveObjs map[kube.Reso
if err != nil {
return false, err
}
if health.IsWorse(aggregatedHealth, hookHealth.Status) {
aggregatedHealth = hookHealth.Status
}
hooks = append(hooks, obj)
}

for _, obj := range hooks {
for _, policy := range hook.DeletePolicies(obj) {
if policy == common.HookDeletePolicyHookFailed && hookHealth.Status == health.HealthStatusDegraded || policy == common.HookDeletePolicyHookSucceeded && hookHealth.Status == health.HealthStatusHealthy {
if policy == common.HookDeletePolicyHookFailed && aggregatedHealth == health.HealthStatusDegraded || policy == common.HookDeletePolicyHookSucceeded && aggregatedHealth == health.HealthStatusHealthy {
pendingDeletionCount++
if obj.GetDeletionTimestamp() != nil {
continue
Expand All @@ -139,6 +148,7 @@ func (ctrl *ApplicationController) cleanupPostDeleteHooks(liveObjs map[kube.Reso
}
}
}

}
if pendingDeletionCount > 0 {
logCtx.Infof("Waiting for %d post-delete hooks to be deleted", pendingDeletionCount)
Expand Down
2 changes: 2 additions & 0 deletions docs/user-guide/resource_hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and after a Sync operation. Hooks can also be run if a Sync operation fails at a
Kubernetes rolling update strategy.
* Using a `PostSync` hook to run integration and health checks after a deployment.
* Using a `SyncFail` hook to run clean-up or finalizer logic if a Sync operation fails. _`SyncFail` hooks are only available starting in v1.2_
* Using a `PostDelete` hook to run clean-up or finalizer logic after an all Application resources are deleted. Please note that
`PostDelete` hooks are only deleted if delete policy matches to the aggregated deletion hooks status and not garbage collected after the application is deleted.

## Usage

Expand Down

0 comments on commit 230db9b

Please sign in to comment.