Skip to content

Commit

Permalink
Fix to the number of required SGs on configure
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertLucian committed Jun 15, 2021
1 parent b0fc893 commit 0068a7d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
11 changes: 8 additions & 3 deletions pkg/lib/aws/servicequotas.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ func (c *Client) VerifyNetworkQuotas(
requiredVPCs int,
availabilityZones strset.Set,
numNodeGroups int,
netAdditionOfNodeGroups int,
longestCIDRWhiteList int,
clusterAlreadyExists bool,
) error {
Expand Down Expand Up @@ -328,7 +329,7 @@ func (c *Client) VerifyNetworkQuotas(
}

// check security groups quota
requiredSecurityGroups := requiredSecurityGroups(numNodeGroups)
requiredSecurityGroups := requiredSecurityGroups(netAdditionOfNodeGroups, clusterAlreadyExists)
sgs, err := c.DescribeSecurityGroups()
if err != nil {
return err
Expand All @@ -345,8 +346,9 @@ func (c *Client) VerifyNetworkQuotas(
func (c *Client) VerifyNetworkQuotasOnConfigure(
availabilityZones strset.Set,
numNodeGroups int,
netAdditionOfNodeGroups int,
longestCIDRWhiteList int) error {
return c.VerifyNetworkQuotas(0, false, false, 0, availabilityZones, numNodeGroups, longestCIDRWhiteList, true)
return c.VerifyNetworkQuotas(0, false, false, 0, availabilityZones, numNodeGroups, netAdditionOfNodeGroups, longestCIDRWhiteList, true)
}

func requiredRulesForNodeGroupSecurityGroup(numAZs, whitelistLength int) int {
Expand All @@ -366,7 +368,10 @@ func requiredRulesForControlPlaneSecurityGroup(numNodeGroups int) int {
return 2 * (numNodeGroups + 1)
}

func requiredSecurityGroups(numNodeGroups int) int {
func requiredSecurityGroups(numNodeGroups int, clusterAlreadyExists bool) int {
if clusterAlreadyExists {
return numNodeGroups
}
// each node group requires a security group
return _baseNumberOfSecurityGroups + numNodeGroups
}
5 changes: 3 additions & 2 deletions pkg/types/clusterconfig/cluster_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,7 @@ func (cc *Config) ValidateOnInstall(awsClient *aws.Client) error {
requiredVPCs = 1
}
longestCIDRWhiteList := libmath.MaxInt(len(cc.APILoadBalancerCIDRWhiteList), len(cc.OperatorLoadBalancerCIDRWhiteList))
if err := awsClient.VerifyNetworkQuotas(1, cc.NATGateway != NoneNATGateway, cc.NATGateway == HighlyAvailableNATGateway, requiredVPCs, strset.FromSlice(cc.AvailabilityZones), len(cc.NodeGroups), longestCIDRWhiteList, false); err != nil {
if err := awsClient.VerifyNetworkQuotas(1, cc.NATGateway != NoneNATGateway, cc.NATGateway == HighlyAvailableNATGateway, requiredVPCs, strset.FromSlice(cc.AvailabilityZones), len(cc.NodeGroups), len(cc.NodeGroups), longestCIDRWhiteList, false); err != nil {
// Skip AWS errors, since some regions (e.g. eu-north-1) do not support this API
if !aws.IsAWSError(err) {
return err
Expand Down Expand Up @@ -1126,8 +1126,9 @@ func (cc *Config) ValidateOnConfigure(awsClient *aws.Client, oldConfig Config, e
ngsToBeRemoved := cc.getRemovedNodeGroups(oldConfig)

tempMaxNodeGroupCount := len(cc.NodeGroups) + len(ngsToBeRemoved)
tempNetAdditionOfNodeGroupCount := tempMaxNodeGroupCount - len(oldConfig.NodeGroups)
longestCIDRWhiteList := libmath.MaxInt(len(cc.APILoadBalancerCIDRWhiteList), len(cc.OperatorLoadBalancerCIDRWhiteList))
if err := awsClient.VerifyNetworkQuotasOnConfigure(strset.FromSlice(cc.AvailabilityZones), tempMaxNodeGroupCount, longestCIDRWhiteList); err != nil {
if err := awsClient.VerifyNetworkQuotasOnConfigure(strset.FromSlice(cc.AvailabilityZones), tempMaxNodeGroupCount, tempNetAdditionOfNodeGroupCount, longestCIDRWhiteList); err != nil {
// Skip AWS errors, since some regions (e.g. eu-north-1) do not support this API
if !aws.IsAWSError(err) {
return ConfigureChanges{}, errors.Wrap(err, NodeGroupsKey)
Expand Down

0 comments on commit 0068a7d

Please sign in to comment.