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

convert subnets and virtualnetworks to ASO #4300

Merged
merged 1 commit into from
Dec 19, 2023

Conversation

nojnhuh
Copy link
Contributor

@nojnhuh nojnhuh commented Nov 20, 2023

What type of PR is this?
/kind cleanup

What this PR does / why we need it: This PR updates the subnets and virtualnetworks services to use ASO.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #3528

Special notes for your reviewer:

This is split into two commits with one for each service. I kept these in the same PR though because converting subnets to ASO before virtualnetworks would have required some gymnastics to get the unit tests in ./controllers to pass that I didn't think were worth ironing out. I intend to squash this into one commit before merging since the unit tests don't pass for the first commit that only updates subnets.

/hold for squash

  • cherry-pick candidate

TODOs:

  • squashed commits
  • includes documentation
  • adds unit tests

Release note:

subnets and virtualnetworks are now managed with ASO

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Nov 20, 2023
Copy link

codecov bot commented Nov 20, 2023

Codecov Report

Attention: 53 lines in your changes are missing coverage. Please review.

Comparison is base (84a5a98) 61.61% compared to head (da0b52d) 61.90%.
Report is 2 commits behind head on main.

Files Patch % Lines
azure/scope/cluster.go 36.00% 16 Missing ⚠️
azure/services/subnets/spec.go 71.05% 11 Missing ⚠️
azure/services/virtualnetworks/spec.go 74.28% 9 Missing ⚠️
azure/services/virtualnetworks/virtualnetworks.go 74.07% 7 Missing ⚠️
azure/services/subnets/subnets.go 53.84% 6 Missing ⚠️
azure/scope/managedcontrolplane.go 73.33% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4300      +/-   ##
==========================================
+ Coverage   61.61%   61.90%   +0.28%     
==========================================
  Files         190      188       -2     
  Lines       18994    18725     -269     
==========================================
- Hits        11704    11591     -113     
+ Misses       6641     6496     -145     
+ Partials      649      638      -11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nojnhuh
Copy link
Contributor Author

nojnhuh commented Nov 21, 2023

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

@nojnhuh
Copy link
Contributor Author

nojnhuh commented Nov 21, 2023

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

}

if !s.IsVNetManaged {
// TODO: change this to terminal error once we add support for handling them
return nil, errors.Errorf("custom vnet was provided but subnet %s is missing", s.Name)
Copy link
Contributor Author

@nojnhuh nojnhuh Nov 21, 2023

Choose a reason for hiding this comment

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

This check enforcing subnets already exist in user-managed vnets has been removed because implementing an equivalent in the ASO framework would get messier than it'd be worth I think.

This check worked before because Parameters used to only be called when CAPZ determined it should manage a resource and was ready to make an API call to Azure, but with ASO Parameters is called even when an ASO resource maps to a user-managed Azure resource. That means this same !s.IsVNetManaged check would be expected to be true for a subnet that already exists in Azure outside of ASO, in which case we should not error because CAPZ still needs to create the ASO proxy resource. I can see if we can rearrange the framework a bit to make this check possible, but I think that will still be net-positive complexity.

As a result, it is now valid not to pre-create all of the subnets in an unmanaged vnet and CAPZ will create and manage missing subnets instead of throwing an error.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that was actually a requested user feature in the past (there might even be an issue for it somewhere)

How do we handle delete for those vnets/subnets?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My archaeology skills led me here, where it seems this was added as a part of a general effort to support BYO vnet: https://github.com/kubernetes-sigs/cluster-api-provider-azure/pull/340/files#diff-6d4bea1a244164bf3d16b025868b878dffcf0c78963b59bad9c189bcee04d35eR87-R90

CAPZ would take full responsibility for any subnet it creates, whether it's part of a managed or unmanaged vnet. So a managed subnet in an unmanaged vnet can be deleted by CAPZ.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

^ But in that same scenario, the unmanaged vnet would not be deleted.

@nojnhuh
Copy link
Contributor Author

nojnhuh commented Nov 21, 2023

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

@nojnhuh
Copy link
Contributor Author

nojnhuh commented Nov 21, 2023

/retest

@nojnhuh
Copy link
Contributor Author

nojnhuh commented Nov 21, 2023

Ready for review!

/retitle convert subnets and virtualnetworks to ASO

@k8s-ci-robot k8s-ci-robot changed the title [WIP] convert subnets and virtualnetworks to ASO convert subnets and virtualnetworks to ASO Nov 21, 2023
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 21, 2023
@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Nov 30, 2023
@nojnhuh
Copy link
Contributor Author

nojnhuh commented Nov 30, 2023

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

@nojnhuh
Copy link
Contributor Author

nojnhuh commented Nov 30, 2023

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

@nojnhuh
Copy link
Contributor Author

nojnhuh commented Nov 30, 2023

/assign @willie-yao @nawazkh

@nojnhuh
Copy link
Contributor Author

nojnhuh commented Dec 1, 2023

/retest

1 similar comment
@nojnhuh
Copy link
Contributor Author

nojnhuh commented Dec 9, 2023

/retest

@nojnhuh
Copy link
Contributor Author

nojnhuh commented Dec 9, 2023

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

Copy link
Contributor

@willie-yao willie-yao left a comment

Choose a reason for hiding this comment

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

Looks good pending a minor comment

@@ -504,7 +492,7 @@ func (s *ManagedControlPlaneScope) ManagedClusterSpec() azure.ASOResourceSpecGet
DNSServiceIP: s.ControlPlane.Spec.DNSServiceIP,
VnetSubnetID: azure.SubnetID(
s.ControlPlane.Spec.SubscriptionID,
s.VNetSpec().ResourceGroupName(),
s.Vnet().ResourceGroup,
s.ControlPlane.Spec.VirtualNetwork.Name,
s.ControlPlane.Spec.VirtualNetwork.Subnet.Name,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should these be also using s.Vnet()? Just to keep things consistent with the line above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

s.Vnet() doesn't define the Subnet, and all the other places using the vnet resource group refer to it like this, so it seems like there's some inconsistency necessary here without some wider refactoring.

Location: privateEndpoint.Location,
CustomNetworkInterfaceName: privateEndpoint.CustomNetworkInterfaceName,
PrivateIPAddresses: privateEndpoint.PrivateIPAddresses,
SubnetID: azure.SubnetID(
s.ControlPlane.Spec.SubscriptionID,
s.VNetSpec().ResourceGroupName(),
s.Vnet().ResourceGroup,
s.ControlPlane.Spec.VirtualNetwork.Name,
s.ControlPlane.Spec.VirtualNetwork.Subnet.Name,
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above ^^

@willie-yao
Copy link
Contributor

/lgtm

@nojnhuh
Copy link
Contributor Author

nojnhuh commented Dec 18, 2023

@CecileRobertMichon This should be ready for a final review.

@CecileRobertMichon
Copy link
Contributor

/lgtm
/approve

@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 Dec 18, 2023
@nojnhuh
Copy link
Contributor Author

nojnhuh commented Dec 18, 2023

squashed!
/hold cancel

@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Dec 18, 2023
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 18, 2023
@nojnhuh
Copy link
Contributor Author

nojnhuh commented Dec 18, 2023

@willie-yao @CecileRobertMichon Resolved conflicts, PTAL.

/hold for squash

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 18, 2023
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

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

LGTM label has been added.

Git tree hash: 04942c0e876eb09cb9087c50d42cadc4e48002b2

@nojnhuh
Copy link
Contributor Author

nojnhuh commented Dec 18, 2023

squashed!
/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 18, 2023
@nawazkh
Copy link
Member

nawazkh commented Dec 19, 2023

/lgtm

1 similar comment
@willie-yao
Copy link
Contributor

/lgtm

@k8s-ci-robot
Copy link
Contributor

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

Test name Commit Details Required Rerun command
pull-cluster-api-provider-azure-windows-custom-builds da0b52d link false /test pull-cluster-api-provider-azure-windows-custom-builds

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.

@nojnhuh
Copy link
Contributor Author

nojnhuh commented Dec 19, 2023

/retest

@k8s-ci-robot k8s-ci-robot merged commit 0f37c5b into kubernetes-sigs:main Dec 19, 2023
27 of 28 checks passed
@nojnhuh nojnhuh deleted the aso-vnets branch December 19, 2023 04:23
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

ASO service: virtualnetworks and subnets
8 participants