Skip to content

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 3 commits into from
Mar 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions pkg/targetgroupbinding/resource_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func NewDefaultResourceManager(k8sClient client.Client, elbv2Client services.ELB
logger: logger,
vpcID: vpcID,
vpcInfoProvider: vpcInfoProvider,
podInfoRepo: podInfoRepo,

targetHealthRequeueDuration: defaultTargetHealthRequeueDuration,
}
Expand All @@ -76,6 +77,7 @@ type defaultResourceManager struct {
eventRecorder record.EventRecorder
logger logr.Logger
vpcInfoProvider networking.VPCInfoProvider
podInfoRepo k8s.PodInfoRepo
vpcID string

targetHealthRequeueDuration time.Duration
Expand All @@ -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
}

Expand Down Expand Up @@ -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)
Copy link
Collaborator

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

if err != nil {
return err
}
if !exists {
return errors.New("couldn't find podInfo for ready endpoint")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should just continue if pod not found.
we can fix it in future versions as it's rare to trigger and won't cause much defect.

}
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 {
Expand Down