Skip to content

Commit 1becaac

Browse files
committed
updates per review suggestions
1 parent 09030dd commit 1becaac

File tree

4 files changed

+49
-45
lines changed

4 files changed

+49
-45
lines changed

docs/deploy/configurations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Currently, you can set only 1 namespace to watch in this flag. See [this Kuberne
117117
| kube-ca-pem-filepath | string | | The file path to the CA to validate webhook callers, when unspecified all webhook callers are permitted. |
118118
| alb-gateway-max-concurrent-reconciles | int | 3 | Maximum number of concurrently running reconcile loops for ALB gateways, if enabled |
119119
| nlb-gateway-max-concurrent-reconciles | int | 3 | Maximum number of concurrently running reconcile loops for NLB gateways, if enabled |
120-
| max-targets-per-instance | int | 0 | Maximum number of targets that will be added to a given ELB instance. The default value of zero will leave the number of targets unlimited |
120+
| max-targets-per-target-group | int | 0 | Maximum number of targets that will be added to a given Target Group. The default value of zero will leave the number of targets unlimited |
121121

122122
### disable-ingress-class-annotation
123123
`--disable-ingress-class-annotation` controls whether to disable new usage of the `kubernetes.io/ingress.class` annotation.

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func main() {
185185
tgbResManager := targetgroupbinding.NewDefaultResourceManager(mgr.GetClient(), cloud.ELBV2(),
186186
podInfoRepo, networkingManager, vpcInfoProvider, multiClusterManager, lbcMetricsCollector,
187187
cloud.VpcID(), controllerCFG.FeatureGates.Enabled(config.EndpointsFailOpen), controllerCFG.EnableEndpointSlices,
188-
mgr.GetEventRecorderFor("targetGroupBinding"), ctrl.Log, controllerCFG.MaxTargetsPerInstance)
188+
mgr.GetEventRecorderFor("targetGroupBinding"), ctrl.Log, controllerCFG.MaxTargetsPerTargetGroup)
189189
backendSGProvider := networking.NewBackendSGProvider(controllerCFG.ClusterName, controllerCFG.BackendSecurityGroup,
190190
cloud.VpcID(), cloud.EC2(), mgr.GetClient(), controllerCFG.DefaultTags, nlbGatewayEnabled || albGatewayEnabled, ctrl.Log.WithName("backend-sg-provider"))
191191
sgResolver := networking.NewDefaultSecurityGroupResolver(cloud.EC2(), cloud.VpcID())

pkg/config/controller_config.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +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"
37+
flagMaxTargetsPerTargetGroup = "max-targets-per-target-group"
3838
defaultLogLevel = "info"
3939
defaultMaxConcurrentReconciles = 3
4040
defaultMaxExponentialBackoffDelay = time.Second * 1000
@@ -44,7 +44,7 @@ const (
4444
defaultEnableEndpointSlices = true
4545
defaultDisableRestrictedSGRules = false
4646
defaultLbStabilizationMonitorInterval = time.Second * 120
47-
defaultMaxTargetsPerInstance = 0
47+
defaultMaxTargetsPerTargetGroup = 0
4848
)
4949

5050
var (
@@ -135,8 +135,8 @@ type ControllerConfig struct {
135135
// LBStabilizationMonitorInterval specifies the duration of interval to monitor the load balancer state for stabilization
136136
LBStabilizationMonitorInterval time.Duration
137137

138-
// MaxTargetsPerInstance limits the number of targets that will be added to an ELB instance
139-
MaxTargetsPerInstance int
138+
// MaxTargetsPerTargetGroup limits the number of targets that will be added to an ELB instance
139+
MaxTargetsPerTargetGroup int
140140

141141
FeatureGates FeatureGates
142142
}
@@ -182,7 +182,7 @@ func (cfg *ControllerConfig) BindFlags(fs *pflag.FlagSet) {
182182
"Disable the usage of restricted security group rules")
183183
fs.StringToStringVar(&cfg.ServiceTargetENISGTags, flagServiceTargetENISGTags, nil,
184184
"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,
185+
fs.IntVar(&cfg.MaxTargetsPerTargetGroup, flagMaxTargetsPerTargetGroup, defaultMaxTargetsPerTargetGroup,
186186
"Maximum number of targets that can be added to an ELB instance. Use this to prevent TargetGroup quotas being exceeded from blocking reconciliation.")
187187
cfg.FeatureGates.BindFlags(fs)
188188
cfg.AWSConfig.BindFlags(fs)

pkg/targetgroupbinding/resource_manager.go

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,23 @@ func NewDefaultResourceManager(k8sClient client.Client, elbv2Client services.ELB
4848
podInfoRepo k8s.PodInfoRepo, networkingManager networking.NetworkingManager,
4949
vpcInfoProvider networking.VPCInfoProvider, multiClusterManager MultiClusterManager, metricsCollector lbcmetrics.MetricCollector,
5050
vpcID string, failOpenEnabled bool, endpointSliceEnabled bool,
51-
eventRecorder record.EventRecorder, logger logr.Logger, maxTargetsPerInstance int) *defaultResourceManager {
51+
eventRecorder record.EventRecorder, logger logr.Logger, maxTargetsPerTargetGroup int) *defaultResourceManager {
5252

5353
targetsManager := NewCachedTargetsManager(elbv2Client, logger)
5454
endpointResolver := backend.NewDefaultEndpointResolver(k8sClient, podInfoRepo, failOpenEnabled, endpointSliceEnabled, logger)
5555
return &defaultResourceManager{
56-
k8sClient: k8sClient,
57-
targetsManager: targetsManager,
58-
endpointResolver: endpointResolver,
59-
networkingManager: networkingManager,
60-
eventRecorder: eventRecorder,
61-
logger: logger,
62-
vpcID: vpcID,
63-
vpcInfoProvider: vpcInfoProvider,
64-
podInfoRepo: podInfoRepo,
65-
maxTargetsPerInstance: maxTargetsPerInstance,
66-
multiClusterManager: multiClusterManager,
67-
metricsCollector: metricsCollector,
56+
k8sClient: k8sClient,
57+
targetsManager: targetsManager,
58+
endpointResolver: endpointResolver,
59+
networkingManager: networkingManager,
60+
eventRecorder: eventRecorder,
61+
logger: logger,
62+
vpcID: vpcID,
63+
vpcInfoProvider: vpcInfoProvider,
64+
podInfoRepo: podInfoRepo,
65+
maxTargetsPerTargetGroup: maxTargetsPerTargetGroup,
66+
multiClusterManager: multiClusterManager,
67+
metricsCollector: metricsCollector,
6868

6969
invalidVpcCache: cache.NewExpiring(),
7070
invalidVpcCacheTTL: defaultTargetsCacheTTL,
@@ -77,18 +77,18 @@ var _ ResourceManager = &defaultResourceManager{}
7777

7878
// default implementation for ResourceManager.
7979
type defaultResourceManager struct {
80-
k8sClient client.Client
81-
targetsManager TargetsManager
82-
endpointResolver backend.EndpointResolver
83-
networkingManager networking.NetworkingManager
84-
eventRecorder record.EventRecorder
85-
logger logr.Logger
86-
vpcInfoProvider networking.VPCInfoProvider
87-
podInfoRepo k8s.PodInfoRepo
88-
maxTargetsPerInstance int
89-
multiClusterManager MultiClusterManager
90-
metricsCollector lbcmetrics.MetricCollector
91-
vpcID string
80+
k8sClient client.Client
81+
targetsManager TargetsManager
82+
endpointResolver backend.EndpointResolver
83+
networkingManager networking.NetworkingManager
84+
eventRecorder record.EventRecorder
85+
logger logr.Logger
86+
vpcInfoProvider networking.VPCInfoProvider
87+
podInfoRepo k8s.PodInfoRepo
88+
maxTargetsPerTargetGroup int
89+
multiClusterManager MultiClusterManager
90+
metricsCollector lbcmetrics.MetricCollector
91+
vpcID string
9292

9393
invalidVpcCache *cache.Expiring
9494
invalidVpcCacheTTL time.Duration
@@ -243,8 +243,10 @@ func (m *defaultResourceManager) reconcileWithIPTargetType(ctx context.Context,
243243
return "", "", false, ctrlerrors.NewErrorWithMetrics(controllerName, "update_tracked_ip_targets_error", err, m.metricsCollector)
244244
}
245245

246-
eligibleTargetsCount := m.getMaxNewTargets(len(unmatchedEndpoints), len(targets), tgbScopedLogger)
247-
unmatchedEndpoints = unmatchedEndpoints[:eligibleTargetsCount]
246+
if m.maxTargetsPerTargetGroup != 0 {
247+
eligibleTargetsCount := m.getMaxNewTargets(len(unmatchedEndpoints), len(targets), tgbScopedLogger)
248+
unmatchedEndpoints = unmatchedEndpoints[:eligibleTargetsCount]
249+
}
248250

249251
if err := m.registerPodEndpoints(ctx, tgb, unmatchedEndpoints); err != nil {
250252
return "", "", false, ctrlerrors.NewErrorWithMetrics(controllerName, "register_pod_endpoint_error", err, m.metricsCollector)
@@ -347,8 +349,10 @@ func (m *defaultResourceManager) reconcileWithInstanceTargetType(ctx context.Con
347349
return "", "", false, ctrlerrors.NewErrorWithMetrics(controllerName, "update_tracked_instance_targets_error", err, m.metricsCollector)
348350
}
349351

350-
eligibleTargetsCount := m.getMaxNewTargets(len(unmatchedEndpoints), len(targets), tgbScopedLogger)
351-
unmatchedEndpoints = unmatchedEndpoints[:eligibleTargetsCount]
352+
if m.maxTargetsPerTargetGroup != 0 {
353+
eligibleTargetsCount := m.getMaxNewTargets(len(unmatchedEndpoints), len(targets), tgbScopedLogger)
354+
unmatchedEndpoints = unmatchedEndpoints[:eligibleTargetsCount]
355+
}
352356

353357
if err := m.registerNodePortEndpoints(ctx, tgb, unmatchedEndpoints); err != nil {
354358
return "", "", false, ctrlerrors.NewErrorWithMetrics(controllerName, "update_node_port_endpoints_error", err, m.metricsCollector)
@@ -814,14 +818,14 @@ func isVPCNotFoundError(err error) bool {
814818
}
815819

816820
func (m *defaultResourceManager) getMaxNewTargets(newTargetCount int, currentTargetCount int, tgbScopedLogger logr.Logger) (maxAdditions int) {
817-
if m.maxTargetsPerInstance > 0 && newTargetCount+currentTargetCount > m.maxTargetsPerInstance {
818-
maxAdditions = m.maxTargetsPerInstance - currentTargetCount
819-
tgbScopedLogger.Info("Limiting target additions due to max-targets-per-instance configuration",
820-
"currentTargets", currentTargetCount,
821-
"maxTargetsPerInstance", m.maxTargetsPerInstance,
822-
"proposedAdditions", newTargetCount)
823-
return maxAdditions
824-
}
821+
if newTargetCount+currentTargetCount > m.maxTargetsPerTargetGroup {
822+
maxAdditions = m.maxTargetsPerTargetGroup - currentTargetCount
823+
tgbScopedLogger.Info("Limiting target additions due to max-targets-per-instance configuration",
824+
"currentTargets", currentTargetCount,
825+
"maxTargetsPerTargetGroup", m.maxTargetsPerTargetGroup,
826+
"proposedAdditions", newTargetCount)
827+
return maxAdditions
828+
}
825829

826-
return newTargetCount
830+
return newTargetCount
827831
}

0 commit comments

Comments
 (0)