Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Checks for Fleet Existence During Application Deletion #605

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 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,9 +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) {
if err := a.deleteResourcesInMemberClusters(ctx, app, fleet); err != nil {
return ctrl.Result{}, errors.Wrapf(err, "failed to delete rollout resource in cluster")
// 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 {
log.Error(err, "failed to find fleet", "fleet", fleetKey)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please check network / server error, and return

} else {
if deleteErr := a.deleteResourcesInMemberClusters(ctx, app, fleet); deleteErr != nil {
return ctrl.Result{}, errors.Wrapf(deleteErr, "failed to delete rollout resource in member clusters")
}
}

controllerutil.RemoveFinalizer(app, ApplicationFinalizer)
Expand Down
Loading