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

Add support to use different subnets in different node pools #1411

Merged
merged 2 commits into from
Jul 21, 2021

Conversation

fiunchinho
Copy link
Contributor

@fiunchinho fiunchinho commented Jun 4, 2021

What type of PR is this?

/kind feature

What this PR does / why we need it:
It allows to define several different subnets for nodes, not just one. Then we can specify the subnet to use when creating AzureMachines or AzureMachinePools.

Which issue(s) this PR fixes:
Fixes #664
Fixes #1362

Special notes for your reviewer:
I kept the role field in the subnets. I think it's still useful to see that a subnet is for control-plane or for the nodes.

I've added a new SubnetName field , but if it's empty, capz will try to find the right subnet to use. This makes the code work with some already existing scenarios.

Please confirm that if this PR changes any image versions, then that's the sole change this PR makes.

TODOs:

  • squashed commits
  • includes documentation
  • adds unit tests

Release note:

Add support to use different subnets in different node pools

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/feature Categorizes issue or PR as related to a new feature. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jun 4, 2021
@k8s-ci-robot k8s-ci-robot added area/provider/azure Issues or PRs related to azure provider sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 4, 2021
@k8s-ci-robot
Copy link
Contributor

Hi @fiunchinho. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jun 4, 2021
api/v1alpha4/azuremachine_types.go Outdated Show resolved Hide resolved
api/v1alpha4/azuremachine_types.go Outdated Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 10, 2021
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 16, 2021
@fiunchinho fiunchinho force-pushed the multiple-subnets branch 2 times, most recently from be95c69 to 24246df Compare June 16, 2021 14:25
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 16, 2021
@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 17, 2021
@fiunchinho fiunchinho force-pushed the multiple-subnets branch 2 times, most recently from 673484f to c0ca96f Compare June 29, 2021 15:12
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jun 29, 2021
var nodeSubnetFound bool
var nodeSubnetCounter int
for i := range c.Spec.NetworkSpec.Subnets {
if c.Spec.NetworkSpec.Subnets[i].Role == SubnetNode {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

To keep the same spirit as before, we only require users to specify subnet name and role when specifying subnets. The rest of the fields will be defaulted. That's why we need DefaultNodeSubnetCIDRPattern, so we can generate different cidrs for different subnets.


// SubnetName selects the Subnet where the VM will be placed
// +optional
SubnetName string `json:"subnetName,omitempty"`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This field is optional so that the code keeps working with existing manifests. In the future we may think about changing it to be required?

Copy link
Contributor

Choose a reason for hiding this comment

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

should we add validation to make it required when there is more than one subnet specified? otherwise it could be ambiguous

Copy link
Contributor Author

@fiunchinho fiunchinho Jul 19, 2021

Choose a reason for hiding this comment

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

@fiunchinho fiunchinho force-pushed the multiple-subnets branch 2 times, most recently from 3a9c884 to 130bf20 Compare July 19, 2021 14:23
@fiunchinho
Copy link
Contributor Author

/test pull-cluster-api-provider-azure-e2e-windows

@fiunchinho
Copy link
Contributor Author

/test pull-cluster-api-provider-azure-e2e

@fiunchinho
Copy link
Contributor Author

@shysank @CecileRobertMichon I believe I addressed all the comments, please take a look, thank you!!

Copy link
Contributor

@CecileRobertMichon CecileRobertMichon left a comment

Choose a reason for hiding this comment

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

Could you please add some docs about this in https://capz.sigs.k8s.io/topics/custom-vnet.html ?

}
}

// If Nat Gateway is not enabled, then the NIC needs to reference the LB to get outbound traffic.
Copy link
Contributor

@shysank shysank Jul 20, 2021

Choose a reason for hiding this comment

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

Yes, make sense. Thanks for the detailed explanation. Is it possible to abstract the details in machineScope.Subnet(), and perhaps add a method Subnet.IsNatGatewayEnabled() so that we can do something like m.Subnet().IsNatGatewayEnabled()

azure/scope/cluster.go Outdated Show resolved Hide resolved
ID: azure.NatGatewayID(s.Scope.SubscriptionID(), s.Scope.ResourceGroup(), natGatewaySpec.Name),
Name: natGatewaySpec.Name,
NatGatewayIP: infrav1.PublicIPSpec{
Name: *(*natGatewayToCreate.NatGatewayPropertiesFormat.PublicIPAddresses)[0].ID,
Copy link
Contributor

Choose a reason for hiding this comment

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

We'll either need to create a new field ID for public ip spec, or not set it. There was an issue reported for this: #1525

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed it so that it uses the name instead of the ID.

// SetSubnetName defaults the AzureMachine subnet name defined when empty to the name of the subnet with role 'node' where there is only one of them.
// Note: this logic exists only for purposes of ensuring backwards compatibility for old clusters created without the `subnetName` field being set, and should be removed in the future.
Copy link
Contributor

Choose a reason for hiding this comment

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

IIUC, this also handles setting subnet name for control plane nodes. Unless, we are planning to implement multiple subnets for cp nodes, this is cannot be removed, I think.

Copy link
Contributor Author

@fiunchinho fiunchinho Jul 21, 2021

Choose a reason for hiding this comment

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

The plan would be to make the subnetName field to be mandatory. Once that happens, this logic is not needed anymore. The same applies for both control-plane and node subnets.

I will tweak the comment a bit, because it only refers to node subnets, and as you mentioned, it also applies to the control-plane subnet.

@fiunchinho fiunchinho force-pushed the multiple-subnets branch 2 times, most recently from d54fdd9 to b0db456 Compare July 21, 2021 10:45
@fiunchinho
Copy link
Contributor Author

/test pull-cluster-api-provider-azure-e2e

@k8s-ci-robot
Copy link
Contributor

@fiunchinho: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Rerun command
pull-cluster-api-provider-azure-apidiff 0f4a838 link /test pull-cluster-api-provider-azure-apidiff

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@fiunchinho
Copy link
Contributor Author

Could you please add some docs about this in https://capz.sigs.k8s.io/topics/custom-vnet.html ?

I added some docs, PTAL.

@shysank
Copy link
Contributor

shysank commented Jul 21, 2021

/lgtm Awesome work @fiunchinho! Thanks for being patient with the reviews!

@CecileRobertMichon
Copy link
Contributor

/label tide/merge-method-squash

@k8s-ci-robot k8s-ci-robot added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Jul 21, 2021
Copy link
Contributor

@CecileRobertMichon CecileRobertMichon left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

thanks for leaving the code cleaner than you found it 🧹

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 21, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: CecileRobertMichon

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 21, 2021
@k8s-ci-robot k8s-ci-robot merged commit e1faf08 into kubernetes-sigs:master Jul 21, 2021
@k8s-ci-robot k8s-ci-robot added this to the v0.5.1 milestone Jul 21, 2021
@fiunchinho fiunchinho deleted the multiple-subnets branch July 22, 2021 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/provider/azure Issues or PRs related to azure provider cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
5 participants