Skip to content

Commit 8fda896

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

File tree

1 file changed

+31
-14
lines changed

1 file changed

+31
-14
lines changed

pkg/targetgroupbinding/resource_manager.go

Lines changed: 31 additions & 14 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,7 @@ func (m *defaultResourceManager) updateTargetHealthPodConditionForPod(ctx contex
353364
return false, nil
354365
}
355366

356-
targetHealthCondStatus := corev1.ConditionUnknown
357-
var reason, message string
358-
if targetHealth != nil {
359-
if string(targetHealth.State) == string(elbv2types.TargetHealthStateEnumHealthy) {
360-
targetHealthCondStatus = corev1.ConditionTrue
361-
} else {
362-
targetHealthCondStatus = corev1.ConditionFalse
363-
}
364-
365-
reason = string(targetHealth.Reason)
366-
message = awssdk.ToString(targetHealth.Description)
367-
}
368-
needFurtherProbe := targetHealthCondStatus != corev1.ConditionTrue
367+
reason, message, targetHealthCondStatus, needFurtherProbe := m.calculateReadinessGateTransition(pod, targetHealthCondType, targetHealth)
369368

370369
existingTargetHealthCond, hasExistingTargetHealthCond := pod.GetPodCondition(targetHealthCondType)
371370
// we skip patch pod if it matches current computed status/reason/message.
@@ -415,6 +414,24 @@ func (m *defaultResourceManager) updateTargetHealthPodConditionForPod(ctx contex
415414
return needFurtherProbe, nil
416415
}
417416

417+
func (m *defaultResourceManager) calculateReadinessGateTransition(pod k8s.PodInfo, targetHealthCondType corev1.PodConditionType, targetHealth *elbv2types.TargetHealth) (string, string, corev1.ConditionStatus, bool) {
418+
var reason, message string
419+
if !pod.HasAnyOfReadinessGates([]corev1.PodConditionType{targetHealthCondType}) {
420+
return reason, message, corev1.ConditionTrue, false
421+
}
422+
targetHealthCondStatus := corev1.ConditionUnknown
423+
if targetHealth != nil {
424+
if string(targetHealth.State) == string(elbv2types.TargetHealthStateEnumHealthy) {
425+
targetHealthCondStatus = corev1.ConditionTrue
426+
} else {
427+
targetHealthCondStatus = corev1.ConditionFalse
428+
}
429+
reason = string(targetHealth.Reason)
430+
message = awssdk.ToString(targetHealth.Description)
431+
}
432+
return reason, message, targetHealthCondStatus, targetHealthCondStatus != corev1.ConditionTrue
433+
}
434+
418435
// updatePodAsHealthyForDeletedTGB updates pod's targetHealth condition as healthy when deleting a TGB
419436
// if the pod has readiness Gate.
420437
func (m *defaultResourceManager) updatePodAsHealthyForDeletedTGB(ctx context.Context, tgb *elbv2api.TargetGroupBinding) error {

0 commit comments

Comments
 (0)