Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Dev Tooling] generateSubnets should check if subnets are already taken #3706

Merged

Conversation

mrWinston
Copy link
Collaborator

Which issue this PR addresses:

This PR fixes errors like:

Subnet 'maschulz-master' is not valid because its IP address range overlaps with that of an existing subnet in virtual network 'dev-vnet'

when creating a cluster using go run ./hack/cluster create.

What this PR does / why we need it:

Instead of just randomly generating the subnet cidrs, generateSubnets now first retrieves all subnets in the dev-vnet and makes sure that the subnet cidrs don't overlap with any of the preexisting ones.

Is there any documentation that needs to be updated for this PR?

  • No

How do you know this will function as expected in production?

  • This change doesn't affect production.

Copy link
Collaborator

@tsatam tsatam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes LGTM.

Current state of master is broken, you'll need to rebase once #3705 is merged.

Make sure to run make generate and fix the linter errors to pass the other failing checks as well.

pkg/util/cluster/cluster.go Outdated Show resolved Hide resolved
pkg/util/cluster/cluster.go Outdated Show resolved Hide resolved
Copy link

@AldoFusterTurpin AldoFusterTurpin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrWinston Thank you for this. Looks good. I just left some suggestions in case you find them useful. Thanks!

pkg/util/cluster/cluster.go Outdated Show resolved Hide resolved
pkg/util/cluster/cluster.go Outdated Show resolved Hide resolved
pkg/util/cluster/cluster.go Outdated Show resolved Hide resolved
pkg/util/cluster/cluster.go Outdated Show resolved Hide resolved
pkg/util/cluster/cluster.go Outdated Show resolved Hide resolved
@mrWinston mrWinston force-pushed the mrwinston/hotfix-dev-cluster-create-better-subnet-creation branch from f0fdcfd to 858084a Compare July 29, 2024 12:34
@mociarain
Copy link
Collaborator

/azp run ci

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mrWinston mrWinston requested a review from tsatam July 29, 2024 13:46
}

func (c *Cluster) generateSubnets() (vnetPrefix string, masterSubnet string, workerSubnet string, err error) {
// pick a random 23 in range [10.3.0.0, 10.127.255.0], making sure it doesn't
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idea: I wonder if this randomness is actually what shoots us in the foot. What if instead, we got very structured with this.

What if, given that both masters and workers are /24 nets, we adopted a CIDR convention rather than shooting in the dark x many times? I'm thinking something like the 10.3.0.0/ space is entirely dedicated to dev clusters, and we take that a slice at a time:

10.3.0.0/24
10.3.1.0/24
10.3.2.0/24
10.3.3.0/24
10.3.4.0/24
10.3.5.0/24
10.3.6.0/24
...

Now, to find the next "open" subnet, all you have to do is iterate over this CIDR convention, and see if it shows up in the VNet or not, and it supports a scale I think we can easily handle (255 subnets, or 127 clusters per region). Thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was discussed here as a potential follow-up improvement: #3706 (comment)

Copy link
Collaborator

@SudoBrendan SudoBrendan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideas aside, this worked for me on the first try locally, so huge +1 considering this is a critical blocker on local testing, thank you so much for this - I no longer need Tanmay's famous hack:

while ! go run ./hack/cluster create; do echo "failed, trying again"; sleep 10; done;

@@ -345,22 +352,111 @@ func (c *Cluster) Create(ctx context.Context, vnetResourceGroup, clusterName str
return nil
}

func (c *Cluster) generateSubnets() (vnetPrefix string, masterSubnet string, workerSubnet string) {
// pick a random 23 in range [10.3.0.0, 10.127.255.0]
// ipRangesContainCIDR checks, weather any of the ipRanges overlap with the cidr string. In case cidr isn't valid, false is returned.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: weather should be whether

Copy link
Contributor

@jhoreman jhoreman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks for this!

Copy link
Collaborator

@shubhadapaithankar shubhadapaithankar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mociarain mociarain merged commit 0250e2f into master Aug 1, 2024
20 checks passed
@mociarain mociarain deleted the mrwinston/hotfix-dev-cluster-create-better-subnet-creation branch August 1, 2024 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants