@@ -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 member clusters" )
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