Skip to content

Commit

Permalink
Add new feature gate to remove subnets minimal count restirction
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryhe1999 committed Oct 18, 2023
1 parent 631041d commit c78d2ca
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/config/feature_gates.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
SubnetsClusterTagCheck Feature = "SubnetsClusterTagCheck"
NLBHealthCheckAdvancedConfig Feature = "NLBHealthCheckAdvancedConfig"
NLBSecurityGroup Feature = "NLBSecurityGroup"
ALBSingleSubnet Feature = "ALBSingleSubnet"
)

type FeatureGates interface {
Expand Down Expand Up @@ -58,6 +59,7 @@ func NewFeatureGates() FeatureGates {
SubnetsClusterTagCheck: true,
NLBHealthCheckAdvancedConfig: true,
NLBSecurityGroup: true,
ALBSingleSubnet: false,
},
}
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/ingress/model_build_load_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ func (t *defaultModelBuildTask) buildLoadBalancerSubnetMappings(ctx context.Cont
networking.WithSubnetsResolveLBType(elbv2model.LoadBalancerTypeApplication),
networking.WithSubnetsResolveLBScheme(scheme),
networking.WithSubnetsClusterTagCheck(t.featureGates.Enabled(config.SubnetsClusterTagCheck)),
networking.WithALBSingleSubnet(t.featureGates.Enabled(config.ALBSingleSubnet)),
)
if err != nil {
return nil, err
Expand All @@ -233,6 +234,7 @@ func (t *defaultModelBuildTask) buildLoadBalancerSubnetMappings(ctx context.Cont
chosenSubnets, err := t.subnetsResolver.ResolveViaNameOrIDSlice(ctx, chosenSubnetNameOrIDs,
networking.WithSubnetsResolveLBType(elbv2model.LoadBalancerTypeApplication),
networking.WithSubnetsResolveLBScheme(scheme),
networking.WithALBSingleSubnet(t.featureGates.Enabled(config.ALBSingleSubnet)),
)
if err != nil {
return nil, err
Expand Down
12 changes: 12 additions & 0 deletions pkg/networking/subnet_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ type SubnetsResolveOptions struct {
AvailableIPAddressCount int64
// whether to check the cluster tag
SubnetsClusterTagCheck bool
// Disable subnet minimal count restriction
ALBSingleSubnet bool
}

// ApplyOptions applies slice of SubnetsResolveOption.
Expand Down Expand Up @@ -95,6 +97,13 @@ func WithSubnetsClusterTagCheck(SubnetsClusterTagCheck bool) SubnetsResolveOptio
}
}

// WithALBSingleSubnet generate an option that foncigure ALBSingleSubnet
func WithALBSingleSubnet(ALBSingleSubnet bool) SubnetsResolveOption {
return func(opts *SubnetsResolveOptions) {
opts.ALBSingleSubnet = ALBSingleSubnet
}
}

// SubnetsResolver is responsible for resolve EC2 Subnets for Load Balancers.
type SubnetsResolver interface {
// ResolveViaDiscovery resolve subnets by auto discover matching subnets.
Expand Down Expand Up @@ -364,6 +373,9 @@ func (r *defaultSubnetsResolver) validateSubnetsMinimalCount(subnets []*ec2sdk.S
// computeSubnetsMinimalCount returns the minimal count requirement for subnets.
func (r *defaultSubnetsResolver) computeSubnetsMinimalCount(subnetLocale subnetLocaleType, resolveOpts SubnetsResolveOptions) int {
minimalCount := 1
if resolveOpts.ALBSingleSubnet {
return minimalCount
}
if resolveOpts.LBType == elbv2model.LoadBalancerTypeApplication && subnetLocale == subnetLocaleTypeAvailabilityZone {
minimalCount = 2
}
Expand Down

0 comments on commit c78d2ca

Please sign in to comment.