Skip to content

Commit

Permalink
fix(appset): prevent app deletion according to policy
Browse files Browse the repository at this point in the history
if appset has the finalizer

Signed-off-by: mikutas <[email protected]>
  • Loading branch information
mikutas committed Feb 29, 2024
1 parent a4b5051 commit 497334b
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions applicationset/controllers/applicationset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,25 @@ func (r *ApplicationSetReconciler) Reconcile(ctx context.Context, req ctrl.Reque

// Do not attempt to further reconcile the ApplicationSet if it is being deleted.
if applicationSetInfo.ObjectMeta.DeletionTimestamp != nil {
deleteAllowed := utils.DefaultPolicy(applicationSetInfo.Spec.SyncPolicy, r.Policy, r.EnablePolicyOverride).AllowDelete()
if !deleteAllowed {
if err := r.removeOwnerReferencesOnDeleteAppSet(ctx, applicationSetInfo); err != nil {
return ctrl.Result{}, err
}
controllerutil.RemoveFinalizer(&applicationSetInfo, argov1alpha1.ResourcesFinalizerName)
if err := r.Update(ctx, &applicationSetInfo); err != nil {
return ctrl.Result{}, err
logCtx.Debugf("DeletionTimestamp set to %s", applicationSetInfo.ObjectMeta.Name)
if controllerutil.ContainsFinalizer(&applicationSetInfo, argov1alpha1.ResourcesFinalizerName) {
deleteAllowed := utils.DefaultPolicy(applicationSetInfo.Spec.SyncPolicy, r.Policy, r.EnablePolicyOverride).AllowDelete()
if !deleteAllowed {
logCtx.Debugf("policy doesn't allow to delete child Applications")
if err := r.removeOwnerReferencesOnDeleteAppSet(ctx, applicationSetInfo); err != nil {
return ctrl.Result{}, err
}
log.Debugf("ownerReferences are removed from child Applications")
controllerutil.RemoveFinalizer(&applicationSetInfo, argov1alpha1.ResourcesFinalizerName)
log.Debugf("finalizer removed from ApplicationSet %s", applicationSetInfo.ObjectMeta.Name)
if err := r.Update(ctx, &applicationSetInfo); err != nil {
return ctrl.Result{}, err
}
} else {
logCtx.Debugf("policy allows to delete child Applications")
}
return ctrl.Result{}, nil
}
return ctrl.Result{}, nil
}

// Log a warning if there are unrecognized generators
Expand Down

0 comments on commit 497334b

Please sign in to comment.