From a1cc9e822c50211a007a353420c796eeea2235f7 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 --- e2e/suite_test.go | 2 +- pkg/fleet-manager/application/controller.go | 27 ++++++++++++--------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/e2e/suite_test.go b/e2e/suite_test.go index a1644087..982d21f1 100644 --- a/e2e/suite_test.go +++ b/e2e/suite_test.go @@ -96,8 +96,8 @@ var _ = ginkgo.SynchronizedBeforeSuite(func() []byte { gomega.Expect(secretCreateErr).ShouldNot(gomega.HaveOccurred()) attachedCreateErr := resources.CreateAttachedCluster(kuratorClient, attachedcluster) - gomega.Expect(attachedCreateErr).ShouldNot(gomega.HaveOccurred()) resources.WaitAttachedClusterFitWith(kuratorClient, namespace, memberClusterName, func(attachedCluster *clusterv1a1.AttachedCluster) bool { return attachedCluster.Status.Ready }) + gomega.Expect(attachedCreateErr).ShouldNot(gomega.HaveOccurred()) }) diff --git a/pkg/fleet-manager/application/controller.go b/pkg/fleet-manager/application/controller.go index f61504cb..0fa7101d 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 cluster") } - 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)