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

💎 Refactor public IP service to get Spec from scope #716

Merged

Conversation

CecileRobertMichon
Copy link
Contributor

@CecileRobertMichon CecileRobertMichon commented Jun 18, 2020

What this PR does / why we need it: Following up from #713, this is a proof of concept with the Public IPs service to stop using a mix of spec + scope in services as input for Reconcile() and Delete().

Before:

type OldService interface {
	Reconcile(ctx context.Context, spec interface{}) error
	Delete(ctx context.Context, spec interface{}) error
}

https://github.com/CecileRobertMichon/cluster-api-provider-azure/blob/06d0321be5fefd840ea1742b9c16a7ce72b98378/cloud/interfaces.go#L34-L37

After:

type Service interface {
	Reconcile(ctx context.Context) error
	Delete(ctx context.Context) error
}

https://github.com/CecileRobertMichon/cluster-api-provider-azure/blob/06d0321be5fefd840ea1742b9c16a7ce72b98378/cloud/interfaces.go#L27-L30

Instead of taking cluster scope or machine scope types as input, each service will have its own scope interface that explicitly defines what information getters the service needs that the passed in scope (either AzureCluster or AzureMachine) needs to implement: https://github.com/CecileRobertMichon/cluster-api-provider-azure/blob/06d0321be5fefd840ea1742b9c16a7ce72b98378/cloud/services/publicips/service.go#L22-L25

This only changes the Pubic IP service while keep all other services intact (renamed the interface to OldService). The idea is to facilitate review and focus on the concept rather than on each service's details. Once I get reviewer consensus, I will proceed to refactor all the other services by opening a PR for each one. This following PRs will be smaller as this one does most of the heavy lifting in machine scope and cluster scope.

/hold
/cc @devigned @alexeldeib @justaugustus @nader-ziada
Would love to get your thoughts on this approach.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Partially addresses #110 , #627 and #609

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:

Refactor public IP service to get Spec from scope
Update mockgen to 8a3d595

@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. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. 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 18, 2020
@CecileRobertMichon CecileRobertMichon changed the title [WIP] 💎 Refactor public IP service to get Spec from scope [WIP] 💎 Refactor public IP service to get Spec from scope Jun 18, 2020
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. area/provider/azure Issues or PRs related to azure provider sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. labels Jun 18, 2020
Copy link
Contributor

@nader-ziada nader-ziada left a comment

Choose a reason for hiding this comment

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

I like the approach in general 👍 but was a little confused about a couple of things when I tried to follow the code flow

cloud/interfaces.go Outdated Show resolved Hide resolved
cloud/scope/machine.go Outdated Show resolved Hide resolved
cloud/scope/machine.go Outdated Show resolved Hide resolved
controllers/azuremachine_reconciler.go Show resolved Hide resolved
cloud/services/publicips/service.go Show resolved Hide resolved
cloud/scope/machine.go Outdated Show resolved Hide resolved
@CecileRobertMichon
Copy link
Contributor Author

@nader-ziada

Instead of taking cluster scope or machine scope types as input, each service will have its own scope interface that explicitly defines what information getters the service needs that the passed in scope (either AzureCluster or AzureMachine) needs to implement: https://github.com/CecileRobertMichon/cluster-api-provider-azure/blob/06d0321be5fefd840ea1742b9c16a7ce72b98378/cloud/services/publicips/service.go#L22-L25

Basically, PublicIPScope is a more precise, targetted scope interface, that defines what info the public IP service needs. Both ClusterScope and MachineScope (and maybe MachinePool in the future once it supports public IPs per instance) implement PublicIPScope. This is to allow reusing the same public IP reconcile service for different public IPs, eg. the Public LB public IP and each VM's IP when allocatePublicIP is set to true. This also makes sure that the passed in "scope" has all the required getter funcs implemented rather that making assumptions on the content of cluster scope or machine scope. Does that make sense?

@nader-ziada
Copy link
Contributor

@CecileRobertMichon makes sense, I get it now 👍

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.

I like the inversion of control from the call site of the reconcile function to the reconciler being dependent on the data in the scope. It feels like this is more in the spirt of a reconciliation loop.

cloud/services/groups/service.go Outdated Show resolved Hide resolved
@nader-ziada
Copy link
Contributor

sorry for all the conflicts :(

@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 22, 2020
@CecileRobertMichon
Copy link
Contributor Author

sorry for all the conflicts :(

No worries!! I knew what I was getting into 😄

@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 22, 2020
@CecileRobertMichon
Copy link
Contributor Author

@alexeldeib would love your thoughts on this approach when you have a second. I think this achieves what we discussed in #627:

  • makes sharing for e.g. machine/machinepool and cluster/managedcluster possible
  • The services shouldn't care about what type they're reconciling against; just the Azure stuff involved.
  • The dependencies on scope are explicit.

@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jun 23, 2020
@k8s-ci-robot
Copy link
Contributor

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

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

@nader-ziada
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 26, 2020
@alexeldeib
Copy link
Contributor

/lgtm

definitely happy with inverting control and slimming down scope per service 👍

@CecileRobertMichon
Copy link
Contributor Author

/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 Jun 29, 2020
@k8s-ci-robot k8s-ci-robot merged commit 5fb8ce3 into kubernetes-sigs:master Jun 29, 2020
@k8s-ci-robot k8s-ci-robot added this to the v0.5 milestone Jun 29, 2020
@CecileRobertMichon CecileRobertMichon deleted the public-ips-scope branch July 9, 2021 18:39
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.

5 participants