Skip to content

Commit 459bfdb

Browse files
committed
Flush the TG target health cache when the API rejects a target registration. This happens when the target becomes unavailable for some reason, flushing the cache will force a refresh on the next cycle.
1 parent cac3133 commit 459bfdb

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

pkg/alb/tg/targetgroup.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,8 @@ func (t *TargetGroup) registerTargets(additions util.AWSStringSlice, rOpts *Reco
385385
}
386386

387387
if _, err := albelbv2.ELBV2svc.RegisterTargets(in); err != nil {
388+
// Flush the cached health of the TG so that on the next iteration it will get fresh data, these change often
389+
albelbv2.ELBV2svc.CacheDelete(albelbv2.DescribeTargetGroupTargetsForArnCache, *t.CurrentARN())
388390
return err
389391
}
390392

pkg/aws/albelbv2/elbv2.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ const (
2828
deleteTargetGroupReattemptSleep int = 10
2929
// Maximum attempts should be made to delete a target group
3030
deleteTargetGroupReattemptMax int = 10
31+
32+
DescribeTargetGroupTargetsForArnCache string = "ELBV2-DescribeTargetGroupTargetsForArn"
3133
)
3234

3335
type ELBV2API interface {
3436
elbv2iface.ELBV2API
37+
CacheDelete(string, string)
3538
ClusterLoadBalancers(*albrgt.Resources) ([]*elbv2.LoadBalancer, error)
3639
ClusterTargetGroups(*albrgt.Resources) (map[string][]*elbv2.TargetGroup, error)
3740
UpdateTags(arn *string, old util.ELBv2Tags, new util.ELBv2Tags) error
@@ -311,9 +314,15 @@ func (e *ELBV2) DescribeListenersForLoadBalancer(loadBalancerArn *string) ([]*el
311314
return listeners, nil
312315
}
313316

317+
// CacheDelete deletes an item from the cache
318+
func (e *ELBV2) CacheDelete(cache, key string) {
319+
cacheKey := cache + "." + key
320+
e.cache.Delete(cacheKey)
321+
}
322+
314323
// DescribeTargetGroupTargetsForArn looks up target group targets by an ARN.
315324
func (e *ELBV2) DescribeTargetGroupTargetsForArn(arn *string, targets ...[]*elbv2.TargetDescription) (result util.AWSStringSlice, err error) {
316-
cache := "ELBV2-DescribeTargetGroupTargetsForArn"
325+
cache := DescribeTargetGroupTargetsForArnCache
317326
key := cache + "." + *arn
318327
item := e.cache.Get(key)
319328

0 commit comments

Comments
 (0)