From 6b37b4ed8ddee83a112cdfb556952ba8c76b1b8c Mon Sep 17 00:00:00 2001 From: LiZhenCheng9527 Date: Wed, 21 Feb 2024 11:07:29 +0800 Subject: [PATCH] Performs application delete, regardless of whether the fleet exists Signed-off-by: LiZhenCheng9527 --- pkg/fleet-manager/application/controller.go | 27 ++++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/pkg/fleet-manager/application/controller.go b/pkg/fleet-manager/application/controller.go index f61504cb..00930a24 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)