-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Update pods with readinessGate as healthy for deleted TGB #2524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,7 @@ func NewDefaultResourceManager(k8sClient client.Client, elbv2Client services.ELB | |
logger: logger, | ||
vpcID: vpcID, | ||
vpcInfoProvider: vpcInfoProvider, | ||
podInfoRepo: podInfoRepo, | ||
|
||
targetHealthRequeueDuration: defaultTargetHealthRequeueDuration, | ||
} | ||
|
@@ -76,6 +77,7 @@ type defaultResourceManager struct { | |
eventRecorder record.EventRecorder | ||
logger logr.Logger | ||
vpcInfoProvider networking.VPCInfoProvider | ||
podInfoRepo k8s.PodInfoRepo | ||
vpcID string | ||
|
||
targetHealthRequeueDuration time.Duration | ||
|
@@ -98,6 +100,9 @@ func (m *defaultResourceManager) Cleanup(ctx context.Context, tgb *elbv2api.Targ | |
if err := m.networkingManager.Cleanup(ctx, tgb); err != nil { | ||
return err | ||
} | ||
if err := m.updatePodAsHealthyForDeletedTGB(ctx, tgb); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
|
@@ -325,6 +330,34 @@ func (m *defaultResourceManager) updateTargetHealthPodConditionForPod(ctx contex | |
return needFurtherProbe, nil | ||
} | ||
|
||
// updatePodAsHealthyForDeletedTGB updates pod's targetHealth condition as healthy when deleting a TGB | ||
// if the pod has readiness Gate. | ||
func (m *defaultResourceManager) updatePodAsHealthyForDeletedTGB(ctx context.Context, tgb *elbv2api.TargetGroupBinding) error { | ||
targetHealthCondType := BuildTargetHealthPodConditionType(tgb) | ||
|
||
allPodKeys := m.podInfoRepo.ListKeys(ctx) | ||
for _, podKey := range allPodKeys { | ||
pod, exists, err := m.podInfoRepo.Get(ctx, podKey) | ||
if err != nil { | ||
return err | ||
} | ||
if !exists { | ||
return errors.New("couldn't find podInfo for ready endpoint") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should just |
||
} | ||
if pod.HasAnyOfReadinessGates([]corev1.PodConditionType{targetHealthCondType}) { | ||
targetHealth := &elbv2sdk.TargetHealth{ | ||
State: awssdk.String(elbv2sdk.TargetHealthStateEnumHealthy), | ||
Description: awssdk.String("Target Group Binding is deleted"), | ||
} | ||
_, err := m.updateTargetHealthPodConditionForPod(ctx, pod, targetHealth, targetHealthCondType) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (m *defaultResourceManager) deregisterTargets(ctx context.Context, tgARN string, targets []TargetInfo) error { | ||
sdkTargets := make([]elbv2sdk.TargetDescription, 0, len(targets)) | ||
for _, target := range targets { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should check for pod's namespace here as well.
Since in theory you can have two targetGroupBinding in two namespace.
In practice, with our default Ingress/Service implementation, the TGB's name is same as TargetGroup's name and will be unique across namespaces.
but this will impact user created targetGroupBinding.
we can fix it in future versions as the impact is minimal