Skip to content

Commit 8313c91

Browse files
committed
preempt pod readiness gate changes by clearing check point
1 parent 01fac95 commit 8313c91

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

pkg/targetgroupbinding/resource_manager.go

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,18 @@ func (m *defaultResourceManager) reconcileWithIPTargetType(ctx context.Context,
173173
needNetworkingRequeue = true
174174
}
175175

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 {
177188
// Set to an empty checkpoint, to ensure that no matter what we try to reconcile atleast one more time.
178189
// Consider this ordering of events (without using this method of overriding the checkpoint)
179190
// 1. Register some pod IP, don't update TGB checkpoint.
@@ -353,19 +364,13 @@ func (m *defaultResourceManager) updateTargetHealthPodConditionForPod(ctx contex
353364
return false, nil
354365
}
355366

356-
targetHealthCondStatus := corev1.ConditionUnknown
357367
var reason, message string
358368
if targetHealth != nil {
359-
if string(targetHealth.State) == string(elbv2types.TargetHealthStateEnumHealthy) {
360-
targetHealthCondStatus = corev1.ConditionTrue
361-
} else {
362-
targetHealthCondStatus = corev1.ConditionFalse
363-
}
364-
365369
reason = string(targetHealth.Reason)
366370
message = awssdk.ToString(targetHealth.Description)
367371
}
368-
needFurtherProbe := targetHealthCondStatus != corev1.ConditionTrue
372+
373+
targetHealthCondStatus, needFurtherProbe := m.calculateReadinessGateTransition(pod, targetHealthCondType, targetHealth)
369374

370375
existingTargetHealthCond, hasExistingTargetHealthCond := pod.GetPodCondition(targetHealthCondType)
371376
// we skip patch pod if it matches current computed status/reason/message.
@@ -415,6 +420,21 @@ func (m *defaultResourceManager) updateTargetHealthPodConditionForPod(ctx contex
415420
return needFurtherProbe, nil
416421
}
417422

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+
418438
// updatePodAsHealthyForDeletedTGB updates pod's targetHealth condition as healthy when deleting a TGB
419439
// if the pod has readiness Gate.
420440
func (m *defaultResourceManager) updatePodAsHealthyForDeletedTGB(ctx context.Context, tgb *elbv2api.TargetGroupBinding) error {

0 commit comments

Comments
 (0)