@@ -114,12 +114,11 @@ type KustomizationReconciler struct {
114114
115115 // Feature gates
116116
117- AdditiveCELDependencyCheck bool
118- AllowExternalArtifact bool
119- CancelHealthCheckOnNewRevision bool
120- FailFast bool
121- GroupChangeLog bool
122- StrictSubstitutions bool
117+ AdditiveCELDependencyCheck bool
118+ AllowExternalArtifact bool
119+ FailFast bool
120+ GroupChangeLog bool
121+ StrictSubstitutions bool
123122}
124123
125124func (r * KustomizationReconciler ) Reconcile (ctx context.Context , req ctrl.Request ) (result ctrl.Result , retErr error ) {
@@ -271,6 +270,19 @@ func (r *KustomizationReconciler) Reconcile(ctx context.Context, req ctrl.Reques
271270 return ctrl.Result {RequeueAfter : r .DependencyRequeueInterval }, nil
272271 }
273272
273+ // Handle health check cancellation.
274+ if qes := new (runtimeCtrl.QueueEventSource ); errors .As (reconcileErr , & qes ) {
275+ conditions .MarkFalse (obj ,
276+ meta .ReadyCondition ,
277+ meta .HealthCheckCanceledReason ,
278+ "New reconciliation triggered by %s/%s/%s" , qes .Kind , qes .Namespace , qes .Name )
279+ ctrl .LoggerFrom (ctx ).Info ("New reconciliation triggered, canceling health checks" , "trigger" , qes )
280+ r .event (obj , revision , originRevision , eventv1 .EventSeverityInfo ,
281+ fmt .Sprintf ("Health checks canceled due to new reconciliation triggered by %s/%s/%s" ,
282+ qes .Kind , qes .Namespace , qes .Name ), nil )
283+ return ctrl.Result {}, nil
284+ }
285+
274286 // Broadcast the reconciliation failure and requeue at the specified retry interval.
275287 if reconcileErr != nil {
276288 log .Error (reconcileErr , fmt .Sprintf ("Reconciliation failed after %s, next try in %s" ,
@@ -504,6 +516,11 @@ func (r *KustomizationReconciler) reconcile(
504516 isNewRevision ,
505517 drifted ,
506518 changeSet .ToObjMetadataSet ()); err != nil {
519+
520+ if errors .Is (err , & runtimeCtrl.QueueEventSource {}) {
521+ return err
522+ }
523+
507524 obj .Status .History .Upsert (checksum , time .Now (), time .Since (reconcileStart ), meta .HealthCheckFailedReason , historyMeta )
508525 conditions .MarkFalse (obj , meta .ReadyCondition , meta .HealthCheckFailedReason , "%s" , err )
509526 return err
@@ -990,43 +1007,15 @@ func (r *KustomizationReconciler) checkHealth(ctx context.Context,
9901007 }
9911008
9921009 // Check the health with a default timeout of 30sec shorter than the reconciliation interval.
993- healthCtx := ctx
994- if r .CancelHealthCheckOnNewRevision {
995- // Create a cancellable context for health checks that monitors for new revisions
996- var cancel context.CancelFunc
997- healthCtx , cancel = context .WithCancel (ctx )
998- defer cancel ()
999-
1000- // Start monitoring for new revisions to allow early cancellation
1001- go func () {
1002- ticker := time .NewTicker (5 * time .Second )
1003- defer ticker .Stop ()
1004-
1005- for {
1006- select {
1007- case <- healthCtx .Done ():
1008- return
1009- case <- ticker .C :
1010- // Get the latest source artifact
1011- latestSrc , err := r .getSource (ctx , obj )
1012- if err == nil && latestSrc .GetArtifact () != nil {
1013- if newRevision := latestSrc .GetArtifact ().Revision ; newRevision != revision {
1014- const msg = "New revision detected during health check, cancelling"
1015- r .event (obj , revision , originRevision , eventv1 .EventSeverityInfo , msg , nil )
1016- ctrl .LoggerFrom (ctx ).Info (msg , "current" , revision , "new" , newRevision )
1017- cancel ()
1018- return
1019- }
1020- }
1021- }
1022- }
1023- }()
1024- }
1010+ healthCtx := runtimeCtrl .GetInterruptContext (ctx )
10251011 if err := manager .WaitForSetWithContext (healthCtx , toCheck , ssa.WaitOptions {
10261012 Interval : 5 * time .Second ,
10271013 Timeout : obj .GetTimeout (),
10281014 FailFast : r .FailFast ,
10291015 }); err != nil {
1016+ if is , err := runtimeCtrl .IsObjectEnqueued (ctx ); is {
1017+ return err
1018+ }
10301019 conditions .MarkFalse (obj , meta .ReadyCondition , meta .HealthCheckFailedReason , "%s" , err )
10311020 conditions .MarkFalse (obj , meta .HealthyCondition , meta .HealthCheckFailedReason , "%s" , err )
10321021 return fmt .Errorf ("health check failed after %s: %w" , time .Since (checkStart ).String (), err )
@@ -1223,12 +1212,12 @@ func (r *KustomizationReconciler) event(obj *kustomizev1.Kustomization,
12231212 reason = r
12241213 }
12251214
1226- eventtype := "Normal"
1215+ eventType := corev1 . EventTypeNormal
12271216 if severity == eventv1 .EventSeverityError {
1228- eventtype = "Warning"
1217+ eventType = corev1 . EventTypeWarning
12291218 }
12301219
1231- r .EventRecorder .AnnotatedEventf (obj , metadata , eventtype , reason , msg )
1220+ r .EventRecorder .AnnotatedEventf (obj , metadata , eventType , reason , msg )
12321221}
12331222
12341223func (r * KustomizationReconciler ) finalizeStatus (ctx context.Context ,
0 commit comments