Skip to content

Commit 7bae2c6

Browse files
Performs application delete, regardless of whether the fleet exists
Signed-off-by: LiZhenCheng9527 <lizhencheng6@huawei.com>
1 parent b4fc885 commit 7bae2c6

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

e2e/suite_test.go

Lines changed: 1 addition & 1 deletion
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

Lines changed: 15 additions & 12 deletions
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,24 @@ 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) {
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 fleet clusters
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) {
319327
log := ctrl.LoggerFrom(ctx)
320-
321328
fleetKey := generateFleetKey(app)
329+
fleet := &fleetapi.Fleet{}
322330
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
331+
log.Error(err, "failed to find fleet", "fleet", fleetKey)
332+
} else {
333+
if deleteErr := a.deleteResourcesInMemberClusters(ctx, app, fleet); deleteErr != nil {
334+
return ctrl.Result{}, errors.Wrapf(deleteErr, "failed to delete rollout resource in cluster")
326335
}
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")
333336
}
334337

335338
controllerutil.RemoveFinalizer(app, ApplicationFinalizer)

0 commit comments

Comments
 (0)