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 <[email protected]>
  • Loading branch information
LiZhenCheng9527 committed Feb 27, 2024
1 parent b4fc885 commit 4acac35
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 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,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)
Expand Down

0 comments on commit 4acac35

Please sign in to comment.