Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c7b78c3

Browse files
committedFeb 21, 2024·
Performs application delete, regardless of whether the fleet exists
Signed-off-by: LiZhenCheng9527 <[email protected]>
1 parent b4fc885 commit c7b78c3

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed
 

‎e2e/suite_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ var _ = ginkgo.SynchronizedBeforeSuite(func() []byte {
9696
gomega.Expect(secretCreateErr).ShouldNot(gomega.HaveOccurred())
9797

9898
attachedCreateErr := resources.CreateAttachedCluster(kuratorClient, attachedcluster)
99-
gomega.Expect(attachedCreateErr).ShouldNot(gomega.HaveOccurred())
10099
resources.WaitAttachedClusterFitWith(kuratorClient, namespace, memberClusterName, func(attachedCluster *clusterv1a1.AttachedCluster) bool {
101100
return attachedCluster.Status.Ready
102101
})
102+
gomega.Expect(attachedCreateErr).ShouldNot(gomega.HaveOccurred())
103103
})

‎pkg/fleet-manager/application/controller.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func (a *ApplicationManager) Reconcile(ctx context.Context, req ctrl.Request) (_
150150

151151
// Handle deletion reconciliation loop.
152152
if app.DeletionTimestamp != nil {
153-
return a.reconcileDelete(ctx, app, fleet)
153+
return a.reconcileDelete(ctx, app)
154154
}
155155

156156
// Handle normal loop.
@@ -315,21 +315,21 @@ func (a *ApplicationManager) reconcileSyncStatus(ctx context.Context, app *appli
315315
return nil
316316
}
317317

318-
func (a *ApplicationManager) reconcileDelete(ctx context.Context, app *applicationapi.Application, fleet *fleetapi.Fleet) (ctrl.Result, error) {
319-
log := ctrl.LoggerFrom(ctx)
320-
318+
// Handling Application Deletion Based on Fleet Availability
319+
// When deleting an application, the approach taken depends on whether the managing fleet can be retrieved:
320+
// If the fleet is available:
321+
// Application will be removed
322+
// Resources related to the application will then be deleted from the attachedcluster
323+
// If the fleet cannot be retrieved:
324+
// Only the application object itself will be removed
325+
// Related resources in any cluster will be left intact
326+
func (a *ApplicationManager) reconcileDelete(ctx context.Context, app *applicationapi.Application) (ctrl.Result, error) {
321327
fleetKey := generateFleetKey(app)
322-
if err := a.Client.Get(ctx, fleetKey, fleet); err != nil {
323-
if apierrors.IsNotFound(err) {
324-
log.Info("delete failed, fleet does not exist", "fleet", fleetKey)
325-
return ctrl.Result{RequeueAfter: fleetmanager.RequeueAfter}, nil
328+
fleet := &fleetapi.Fleet{}
329+
if err := a.Client.Get(ctx, fleetKey, fleet); err == nil {
330+
if deleteErr := a.deleteResourcesInMemberClusters(ctx, app, fleet); deleteErr != nil {
331+
return ctrl.Result{}, errors.Wrapf(deleteErr, "failed to delete rollout resource in cluster")
326332
}
327-
log.Error(err, "delete failed, fleet does not found", "fleet", fleetKey)
328-
return ctrl.Result{}, err
329-
}
330-
331-
if deleteErr := a.deleteResourcesInMemberClusters(ctx, app, fleet); deleteErr != nil {
332-
return ctrl.Result{}, errors.Wrapf(deleteErr, "failed to delete rollout resource in cluster")
333333
}
334334

335335
controllerutil.RemoveFinalizer(app, ApplicationFinalizer)

0 commit comments

Comments
 (0)
Please sign in to comment.