Skip to content

Commit 9c74844

Browse files
committed
Initial testing
1 parent f6558da commit 9c74844

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

pkg/config/controller_config.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const (
3434
flagBackendSecurityGroup = "backend-security-group"
3535
flagEnableEndpointSlices = "enable-endpoint-slices"
3636
flagDisableRestrictedSGRules = "disable-restricted-sg-rules"
37+
flagMaxTargetsPerInstance = "max-targets-per-instance"
3738
defaultLogLevel = "info"
3839
defaultMaxConcurrentReconciles = 3
3940
defaultMaxExponentialBackoffDelay = time.Second * 1000
@@ -43,6 +44,7 @@ const (
4344
defaultEnableEndpointSlices = true
4445
defaultDisableRestrictedSGRules = false
4546
defaultLbStabilizationMonitorInterval = time.Second * 120
47+
defaultMaxTargetsPerInstance = 0
4648
)
4749

4850
var (
@@ -133,6 +135,9 @@ type ControllerConfig struct {
133135
// LBStabilizationMonitorInterval specifies the duration of interval to monitor the load balancer state for stabilization
134136
LBStabilizationMonitorInterval time.Duration
135137

138+
// MaxTargetsPerInstance limits the number of targets that will be added to an ELB instance
139+
MaxTargetsPerInstance int
140+
136141
FeatureGates FeatureGates
137142
}
138143

@@ -177,6 +182,8 @@ func (cfg *ControllerConfig) BindFlags(fs *pflag.FlagSet) {
177182
"Disable the usage of restricted security group rules")
178183
fs.StringToStringVar(&cfg.ServiceTargetENISGTags, flagServiceTargetENISGTags, nil,
179184
"AWS Tags, in addition to cluster tags, for finding the target ENI security group to which to add inbound rules from NLBs")
185+
fs.IntVar(&cfg.MaxTargetsPerInstance, flagMaxTargetsPerInstance, defaultMaxTargetsPerInstance,
186+
"Maximum number of targets that can be added to an ELB instance. Use this to prevent TargetGroup quotas being exceeded from blocking reconciliation.")
180187
cfg.FeatureGates.BindFlags(fs)
181188
cfg.AWSConfig.BindFlags(fs)
182189
cfg.RuntimeConfig.BindFlags(fs)

pkg/targetgroupbinding/targets_manager.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const (
1818
defaultTargetsCacheTTL = 5 * time.Minute
1919
defaultRegisterTargetsChunkSize = 200
2020
defaultDeregisterTargetsChunkSize = 200
21+
maxTargetsPerInstance = 500
2122
)
2223

2324
// TargetsManager is an abstraction around ELBV2's targets API.
@@ -80,7 +81,16 @@ type targetsCacheItem struct {
8081

8182
func (m *cachedTargetsManager) RegisterTargets(ctx context.Context, tgb *elbv2api.TargetGroupBinding, targets []elbv2types.TargetDescription) error {
8283
tgARN := tgb.Spec.TargetGroupARN
83-
targetsChunks := chunkTargetDescriptions(targets, m.registerTargetsChunkSize)
84+
sampledTargets := targets
85+
86+
m.logger.Info("Number of targets", len(targets), "registering a subset per max-targets-per-instance", maxTargetsPerInstance)
87+
if maxTargetsPerInstance > 0 && len(targets) > maxTargetsPerInstance {
88+
m.logger.Info("Max number of targets exceeded", len(targets), "registering a subset per max-targets-per-instance", maxTargetsPerInstance)
89+
m.logger.Info("Max number of targets exceeded", len(targets), "registering a subset per max-targets-per-instance", maxTargetsPerInstance)
90+
sampledTargets = targets[:maxTargetsPerInstance]
91+
}
92+
93+
targetsChunks := chunkTargetDescriptions(sampledTargets, m.registerTargetsChunkSize)
8494
for _, targetsChunk := range targetsChunks {
8595
req := &elbv2sdk.RegisterTargetsInput{
8696
TargetGroupArn: aws.String(tgARN),

0 commit comments

Comments
 (0)