diff --git a/pkg/fleet-manager/application/controller.go b/pkg/fleet-manager/application/controller.go index f61504cb..f423a93c 100644 --- a/pkg/fleet-manager/application/controller.go +++ b/pkg/fleet-manager/application/controller.go @@ -150,7 +150,7 @@ func (a *ApplicationManager) Reconcile(ctx context.Context, req ctrl.Request) (_ // Handle deletion reconciliation loop. if app.DeletionTimestamp != nil { - return a.reconcileDelete(ctx, app, fleet) + return a.reconcileDelete(ctx, app) } // Handle normal loop. @@ -315,21 +315,24 @@ func (a *ApplicationManager) reconcileSyncStatus(ctx context.Context, app *appli return nil } -func (a *ApplicationManager) reconcileDelete(ctx context.Context, app *applicationapi.Application, fleet *fleetapi.Fleet) (ctrl.Result, error) { +// Handling Application Deletion Based on Fleet Availability. +// When deleting an application, the approach taken depends on whether the managing fleet can be retrieved. +// If the fleet is available: +// Application will be removed +// Resources related to the application will then be deleted from fleet clusters +// If the fleet cannot be retrieved: +// Only the application object itself will be removed +// Related resources in any cluster will be left intact +func (a *ApplicationManager) reconcileDelete(ctx context.Context, app *applicationapi.Application) (ctrl.Result, error) { log := ctrl.LoggerFrom(ctx) - fleetKey := generateFleetKey(app) + fleet := &fleetapi.Fleet{} if err := a.Client.Get(ctx, fleetKey, fleet); err != nil { - if apierrors.IsNotFound(err) { - log.Info("delete failed, fleet does not exist", "fleet", fleetKey) - return ctrl.Result{RequeueAfter: fleetmanager.RequeueAfter}, nil + log.Error(err, "failed to find fleet", "fleet", fleetKey) + } else { + if deleteErr := a.deleteResourcesInMemberClusters(ctx, app, fleet); deleteErr != nil { + return ctrl.Result{}, errors.Wrapf(deleteErr, "failed to delete rollout resource in member clusters") } - log.Error(err, "delete failed, fleet does not found", "fleet", fleetKey) - return ctrl.Result{}, err - } - - if deleteErr := a.deleteResourcesInMemberClusters(ctx, app, fleet); deleteErr != nil { - return ctrl.Result{}, errors.Wrapf(deleteErr, "failed to delete rollout resource in cluster") } controllerutil.RemoveFinalizer(app, ApplicationFinalizer)