@@ -173,7 +173,18 @@ func (m *defaultResourceManager) reconcileWithIPTargetType(ctx context.Context,
173
173
needNetworkingRequeue = true
174
174
}
175
175
176
- if len (unmatchedEndpoints ) > 0 || len (unmatchedTargets ) > 0 || needNetworkingRequeue {
176
+ preflightNeedFurtherProbe := false
177
+ for _ , endpointAndTarget := range matchedEndpointAndTargets {
178
+ _ , localPreflight := m .calculateReadinessGateTransition (endpointAndTarget .endpoint .Pod , targetHealthCondType , endpointAndTarget .target .TargetHealth )
179
+ if localPreflight {
180
+ preflightNeedFurtherProbe = true
181
+ break
182
+ }
183
+ }
184
+
185
+ // Any change that we perform should reset the checkpoint.
186
+ // TODO - How to make this cleaner?
187
+ if len (unmatchedEndpoints ) > 0 || len (unmatchedTargets ) > 0 || needNetworkingRequeue || containsPotentialReadyEndpoints || preflightNeedFurtherProbe {
177
188
// Set to an empty checkpoint, to ensure that no matter what we try to reconcile atleast one more time.
178
189
// Consider this ordering of events (without using this method of overriding the checkpoint)
179
190
// 1. Register some pod IP, don't update TGB checkpoint.
@@ -353,19 +364,13 @@ func (m *defaultResourceManager) updateTargetHealthPodConditionForPod(ctx contex
353
364
return false , nil
354
365
}
355
366
356
- targetHealthCondStatus := corev1 .ConditionUnknown
357
367
var reason , message string
358
368
if targetHealth != nil {
359
- if string (targetHealth .State ) == string (elbv2types .TargetHealthStateEnumHealthy ) {
360
- targetHealthCondStatus = corev1 .ConditionTrue
361
- } else {
362
- targetHealthCondStatus = corev1 .ConditionFalse
363
- }
364
-
365
369
reason = string (targetHealth .Reason )
366
370
message = awssdk .ToString (targetHealth .Description )
367
371
}
368
- needFurtherProbe := targetHealthCondStatus != corev1 .ConditionTrue
372
+
373
+ targetHealthCondStatus , needFurtherProbe := m .calculateReadinessGateTransition (pod , targetHealthCondType , targetHealth )
369
374
370
375
existingTargetHealthCond , hasExistingTargetHealthCond := pod .GetPodCondition (targetHealthCondType )
371
376
// we skip patch pod if it matches current computed status/reason/message.
@@ -415,6 +420,21 @@ func (m *defaultResourceManager) updateTargetHealthPodConditionForPod(ctx contex
415
420
return needFurtherProbe , nil
416
421
}
417
422
423
+ func (m * defaultResourceManager ) calculateReadinessGateTransition (pod k8s.PodInfo , targetHealthCondType corev1.PodConditionType , targetHealth * elbv2types.TargetHealth ) (corev1.ConditionStatus , bool ) {
424
+ if ! pod .HasAnyOfReadinessGates ([]corev1.PodConditionType {targetHealthCondType }) {
425
+ return corev1 .ConditionTrue , false
426
+ }
427
+ targetHealthCondStatus := corev1 .ConditionUnknown
428
+ if targetHealth != nil {
429
+ if string (targetHealth .State ) == string (elbv2types .TargetHealthStateEnumHealthy ) {
430
+ targetHealthCondStatus = corev1 .ConditionTrue
431
+ } else {
432
+ targetHealthCondStatus = corev1 .ConditionFalse
433
+ }
434
+ }
435
+ return targetHealthCondStatus , targetHealthCondStatus != corev1 .ConditionTrue
436
+ }
437
+
418
438
// updatePodAsHealthyForDeletedTGB updates pod's targetHealth condition as healthy when deleting a TGB
419
439
// if the pod has readiness Gate.
420
440
func (m * defaultResourceManager ) updatePodAsHealthyForDeletedTGB (ctx context.Context , tgb * elbv2api.TargetGroupBinding ) error {
0 commit comments