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

💎 cloud: Refactor Subnets scope to interface #768

Merged
merged 1 commit into from
Jul 21, 2020

Conversation

cpanato
Copy link
Member

@cpanato cpanato commented Jul 8, 2020

What this PR does / why we need it:
Follow up from #716 , this PR applies the same pattern to Subnets.

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 partially #757

Special notes for your reviewer:

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:

 cloud: Refactor Subnets scope to interface

@k8s-ci-robot k8s-ci-robot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Jul 8, 2020
@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. 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 Jul 8, 2020
@cpanato
Copy link
Member Author

cpanato commented Jul 8, 2020

Opening the PR to get some feedback because I'm not 100% sure if I did that correctly.
Also when all is good will add a few more tests to cover the spec array

cc @CecileRobertMichon @devigned
thanks in advance for taking the time to review this PR.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 8, 2020
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 8, 2020
@cpanato cpanato changed the title 💎 WIP cloud: Refactor Subnets scope to interface WIP 💎 cloud: Refactor Subnets scope to interface Jul 8, 2020
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 8, 2020
@cpanato cpanato changed the title WIP 💎 cloud: Refactor Subnets scope to interface 💎 cloud: Refactor Subnets scope to interface Jul 10, 2020
@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 Jul 10, 2020
@cpanato
Copy link
Member Author

cpanato commented Jul 10, 2020

@CecileRobertMichon done the missing parts and add a few more test cases. PTAL
thanks for your review

Copy link
Contributor

@devigned devigned 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. Just a couple points of feedback.

controllers/azurecluster_reconciler.go Outdated Show resolved Hide resolved
cloud/services/subnets/subnets.go Outdated Show resolved Hide resolved
controllers/azurecluster_reconciler.go Outdated Show resolved Hide resolved
@cpanato cpanato force-pushed the GH-757-subnet branch 2 times, most recently from 14a22de to 1d79586 Compare July 14, 2020 15:16
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, /assign @devigned for another review on the getExisting subnet changes

Copy link
Contributor

@devigned devigned left a comment

Choose a reason for hiding this comment

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

Subnet Reconcile is a little tough to follow. Perhaps, a light bit of refactoring would help.

func (s *Service) Reconcile(ctx context.Context) error {
for i, subnetSpec := range s.Scope.SubnetSpecs() {
existingSubnet, err := s.getExisting(ctx, s.Scope.Vnet().ResourceGroup, subnetSpec)
if err == nil {
Copy link
Contributor

@devigned devigned Jul 14, 2020

Choose a reason for hiding this comment

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

What do you think about the following refactor to clean things up a bit:

for i, subnetSpec := range s.Scope.SubnetSpecs() {
	existingSubnet, err := s.getExisting(ctx, s.Scope.Vnet().ResourceGroup, subnetSpec)
	switch {
		case err != nil && !azure.ResourceNotFound(err):
			// not found
		case err != nil:
			// stuff for existing subnet
		case !s.Scope.Vnet().IsManaged(s.Scope.ClusterName()):  // why does is managed need `s.Scope.ClusterName()`?
			// if the vnet is unmanaged, we expect all subnets to be created as well
		default:
			// stuff to create new subnet
	}

Copy link
Contributor

Choose a reason for hiding this comment

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

Just wanted to call out: "why does is managed need s.Scope.ClusterName()?" Seems odd to have to pass in s.Scope.ClusterName() when calling a func off of hierarchical descendant of s.Scope.

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 it's because IsManaged is on the infra VnetSpec, not the scope itself.
this could also read:

vnet := s.Scope.Vnet() // return type *infrav1.VnetSpec
if !vnet.IsManagedBy(s.Scope.ClusterName()) {
 ...
} 

Copy link
Contributor

Choose a reason for hiding this comment

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

we could change this into s.Scope.IsVnetManaged() though

Agree it seems a bit odd like this

Copy link
Member Author

Choose a reason for hiding this comment

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

made all the requested changes, please take a look again :) thanks for all inputs!

@cpanato
Copy link
Member Author

cpanato commented Jul 17, 2020

@CecileRobertMichon was missing the / :)

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

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Jul 17, 2020
@k8s-ci-robot k8s-ci-robot removed lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Jul 17, 2020
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 Jul 17, 2020
@cpanato
Copy link
Member Author

cpanato commented Jul 17, 2020

Looks like my rebase did went well. Will fix that tomorrow

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 18, 2020
@cpanato
Copy link
Member Author

cpanato commented Jul 18, 2020

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

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.

One more comment based on #806 to fix parallelism in the tests

cloud/services/subnets/subnets_test.go Show resolved Hide resolved
cloud/services/subnets/subnets_test.go 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 Jul 21, 2020
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 21, 2020
@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Jul 21, 2020

@cpanato: The following test failed, say /retest to rerun all failed tests:

Test name Commit Details Rerun command
pull-cluster-api-provider-azure-apidiff 299e266 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.

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

@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, 2020
@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 merged commit eddf931 into kubernetes-sigs:master Jul 21, 2020
@k8s-ci-robot k8s-ci-robot added this to the v0.4.7 milestone Jul 21, 2020
@cpanato cpanato deleted the GH-757-subnet branch July 22, 2020 05:36
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. 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. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants