Skip to content

Commit

Permalink
Performs application delete, regardless of whether the fleet exists
Browse files Browse the repository at this point in the history
Signed-off-by: LiZhenCheng9527 <lizhencheng6@huawei.com>
  • Loading branch information
LiZhenCheng9527 committed Feb 21, 2024
1 parent b4fc885 commit c7b78c3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion e2e/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})
28 changes: 14 additions & 14 deletions pkg/fleet-manager/application/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -315,21 +315,21 @@ 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) {
log := ctrl.LoggerFrom(ctx)

// 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 the attachedcluster
// 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) {
fleetKey := generateFleetKey(app)
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
fleet := &fleetapi.Fleet{}
if err := a.Client.Get(ctx, fleetKey, fleet); err == nil {
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)
Expand Down

0 comments on commit c7b78c3

Please sign in to comment.