@@ -109,6 +109,13 @@ func (r *Reconciler) reconcileApprovalRequestObj(ctx context.Context, approvalRe
109109 return r .handleDelete (ctx , approvalReqObj , isClusterScoped )
110110 }
111111
112+ // Check if the approval request is already approved or rejected - stop reconciliation if so
113+ approvedCond := meta .FindStatusCondition (approvalReqObj .GetApprovalRequestStatus ().Conditions , string (placementv1beta1 .ApprovalRequestConditionApproved ))
114+ if approvedCond != nil && approvedCond .Status == metav1 .ConditionTrue {
115+ klog .V (2 ).InfoS ("ApprovalRequest has been approved, stopping reconciliation" , "approvalRequest" , approvalReqRef )
116+ return ctrl.Result {}, nil
117+ }
118+
112119 // Add finalizer if not present
113120 if ! controllerutil .ContainsFinalizer (obj , metricCollectorFinalizer ) {
114121 controllerutil .AddFinalizer (obj , metricCollectorFinalizer )
@@ -119,13 +126,6 @@ func (r *Reconciler) reconcileApprovalRequestObj(ctx context.Context, approvalRe
119126 klog .V (2 ).InfoS ("Added finalizer to ApprovalRequest" , "approvalRequest" , approvalReqRef )
120127 }
121128
122- // Check if the approval request is approved
123- approvedCond := meta .FindStatusCondition (approvalReqObj .GetApprovalRequestStatus ().Conditions , string (placementv1beta1 .ApprovalRequestConditionApproved ))
124- if approvedCond != nil && approvedCond .Status == metav1 .ConditionTrue {
125- klog .V (2 ).InfoS ("ApprovalRequest has been approved, skipping" , "approvalRequest" , approvalReqRef )
126- return ctrl.Result {}, nil
127- }
128-
129129 // Get the UpdateRun (ClusterStagedUpdateRun or StagedUpdateRun)
130130 spec := approvalReqObj .GetApprovalRequestSpec ()
131131 updateRunName := spec .TargetUpdateRun
@@ -190,13 +190,13 @@ func (r *Reconciler) reconcileApprovalRequestObj(ctx context.Context, approvalRe
190190 klog .V (2 ).InfoS ("Successfully ensured MetricCollector resources" , "approvalRequest" , approvalReqRef , "clusters" , clusterNames )
191191
192192 // Check workload health and approve if all workloads are healthy
193- result , err := r .checkWorkloadHealthAndApprove (ctx , approvalReqObj , clusterNames , updateRunName , stageName )
194- if err != nil {
193+ if err := r .checkWorkloadHealthAndApprove (ctx , approvalReqObj , clusterNames , updateRunName , stageName ); err != nil {
195194 klog .ErrorS (err , "Failed to check workload health" , "approvalRequest" , approvalReqRef )
196- return ctrl.Result {RequeueAfter : 30 * time .Second }, err
195+ return ctrl.Result {RequeueAfter : 15 * time .Second }, err
197196 }
198197
199- return result , nil
198+ // Requeue after 15 seconds to check again (will stop if approved in next reconciliation)
199+ return ctrl.Result {RequeueAfter : 15 * time .Second }, nil
200200}
201201
202202// ensureMetricCollectorResources creates the Namespace, MetricCollector, CRP, and ResourceOverrides
@@ -360,7 +360,7 @@ func (r *Reconciler) checkWorkloadHealthAndApprove(
360360 approvalReqObj placementv1beta1.ApprovalRequestObj ,
361361 clusterNames []string ,
362362 updateRunName , stageName string ,
363- ) (ctrl. Result , error ) {
363+ ) error {
364364 obj := approvalReqObj .(client.Object )
365365 approvalReqRef := klog .KObj (obj )
366366
@@ -370,12 +370,12 @@ func (r *Reconciler) checkWorkloadHealthAndApprove(
370370 workloadTrackerList := & placementv1beta1.WorkloadTrackerList {}
371371 if err := r .Client .List (ctx , workloadTrackerList ); err != nil {
372372 klog .ErrorS (err , "Failed to list WorkloadTracker" , "approvalRequest" , approvalReqRef )
373- return ctrl. Result {}, fmt .Errorf ("failed to list WorkloadTracker: %w" , err )
373+ return fmt .Errorf ("failed to list WorkloadTracker: %w" , err )
374374 }
375375
376376 if len (workloadTrackerList .Items ) == 0 {
377377 klog .V (2 ).InfoS ("No WorkloadTracker found, skipping health check" , "approvalRequest" , approvalReqRef )
378- return ctrl. Result {}, nil
378+ return nil
379379 }
380380
381381 // Use the first WorkloadTracker (assuming there's only one)
@@ -384,7 +384,7 @@ func (r *Reconciler) checkWorkloadHealthAndApprove(
384384
385385 if len (workloadTracker .Workloads ) == 0 {
386386 klog .V (2 ).InfoS ("WorkloadTracker has no workloads defined, skipping health check" , "approvalRequest" , approvalReqRef )
387- return ctrl. Result {}, nil
387+ return nil
388388 }
389389
390390 // MetricCollectorReport name is same as MetricCollector name
@@ -426,7 +426,7 @@ func (r *Reconciler) checkWorkloadHealthAndApprove(
426426 "cluster" , clusterName ,
427427 "report" , metricCollectorName ,
428428 "namespace" , reportNamespace )
429- return ctrl. Result {}, fmt .Errorf ("failed to get MetricCollectorReport for cluster %s: %w" , clusterName , err )
429+ return fmt .Errorf ("failed to get MetricCollectorReport for cluster %s: %w" , clusterName , err )
430430 }
431431
432432 klog .V (2 ).InfoS ("Found MetricCollectorReport" ,
@@ -500,7 +500,7 @@ func (r *Reconciler) checkWorkloadHealthAndApprove(
500500 approvalReqObj .SetApprovalRequestStatus (* status )
501501 if err := r .Client .Status ().Update (ctx , obj ); err != nil {
502502 klog .ErrorS (err , "Failed to approve ApprovalRequest" , "approvalRequest" , approvalReqRef )
503- return ctrl. Result {}, fmt .Errorf ("failed to approve ApprovalRequest: %w" , err )
503+ return fmt .Errorf ("failed to approve ApprovalRequest: %w" , err )
504504 }
505505
506506 klog .InfoS ("Successfully approved ApprovalRequest" , "approvalRequest" , approvalReqRef )
@@ -509,17 +509,16 @@ func (r *Reconciler) checkWorkloadHealthAndApprove(
509509 klog .V (2 ).InfoS ("ApprovalRequest already approved" , "approvalRequest" , approvalReqRef )
510510 }
511511
512- // Stop reconciliation since we're approved
513- return ctrl. Result {}, nil
512+ // Approval successful or already approved
513+ return nil
514514 }
515515
516- // Not all workloads are healthy yet, requeue
517- klog .V (2 ).InfoS ("Not all workloads are healthy yet, will requeue " ,
516+ // Not all workloads are healthy yet, log details and return nil (reconcile will requeue)
517+ klog .V (2 ).InfoS ("Not all workloads are healthy yet" ,
518518 "approvalRequest" , approvalReqRef ,
519519 "unhealthyDetails" , unhealthyDetails )
520520
521- // Requeue after 30 seconds to check again
522- return ctrl.Result {RequeueAfter : 30 * time .Second }, nil
521+ return nil
523522}
524523
525524// handleDelete handles the deletion of an ApprovalRequest or ClusterApprovalRequest
0 commit comments