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 AzureMachineReconciler to inject AzuremachineService as dependency #1053

Merged
merged 1 commit into from
Dec 16, 2020

Conversation

shysank
Copy link
Contributor

@shysank shysank commented Nov 20, 2020

What type of PR is this?

/kind cleanup

What this PR does / why we need it:
Refactors AzureMachineReconciler to inject AzuremachineService as dependency
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#1047 (partially)

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 AzureMachineReconciler to inject AzuremachineService as dependency

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. 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. labels Nov 20, 2020
@k8s-ci-robot
Copy link
Contributor

Hi @shysank. 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 needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 20, 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. labels Nov 20, 2020
@CecileRobertMichon
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 21, 2020
@shysank
Copy link
Contributor Author

shysank commented Nov 21, 2020

apidiff:

sigs.k8s.io/cluster-api-provider-azure/controllers
  Incompatible changes:
  - AzureMachineReconciler: old is comparable, new is not
  Compatible changes:
  - NewAzureMachineReconciler: added

@CecileRobertMichon
Copy link
Contributor

/retest

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'm not clear that the azureMachineServiceFactory will be set anywhere besides tests. If the ability to inject an azureMachineServiceFactory for testing purposes, perhaps, that can be done simply by having a test within the same package as this struct and set the struct field directly.

controllers/interfaces.go Outdated Show resolved Hide resolved
controllers/azuremachine_controller.go Outdated Show resolved Hide resolved
controllers/azuremachine_controller.go Outdated Show resolved Hide resolved
@shysank
Copy link
Contributor Author

shysank commented Dec 9, 2020

@devigned I've made some small changes based on the feedback I received for a similar refactor here. I've also removed the variadic options to keep it simple. wdyt?

/cc @CecileRobertMichon

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.

lgtm

@CecileRobertMichon wdyt?

import "context"

// Reconciler provides operations for a reconciliation service
type Reconciler interface {
Copy link
Contributor

Choose a reason for hiding this comment

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

this looks very similar to https://github.com/kubernetes-sigs/cluster-api-provider-azure/blob/master/cloud/interfaces.go#L28, I wonder if we should consider combining them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we just make azuremachineService also be of type azure.Service? As in it still does reconcile and delete like other cloud/services except that it is kind of a composite service which orchestrates other individual services?

Copy link
Contributor

@devigned devigned Dec 11, 2020

Choose a reason for hiding this comment

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

If I recall, @shysank made azuremachineService a azure.Service initially. I advised against that because I didn't want anyone to infer the azuremachineService was actually a cloud service, one of the services that lives ./cloud/services.

I think the Service interface is really an abstract concept that overflows the bounds of ./cloud/services. It is a description of the reconcile behavior, reconcile to state or delete.

@CecileRobertMichon do you remember talking about how a reconciler could be a composition of reconiling services? I think this is that pattern is surfacing. azuremachineService is a reconciling service composed of a collection of reconciling services, in some order of operations.

Perhaps, we just use azure.Service for now, and look to lift the interface from the azure package into a more generic package in a refactor.

Sorry if I've going into the bike shed on this one, but I just want to ensure we are making abstractions at the right levels.

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps, we just use azure.Service for now, and look to lift the interface from the azure package into a more generic package in a refactor.

SGTM. When I say combine them, I mostly meant the cloud/services should be a composition of reconcilers. I think the interface should live outside cloud/ as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@devigned @CecileRobertMichon For now, I've made azureMachineReconciler to use azure.service. Filed an issue to move azure.Service outside of cloud/, PTAL.

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.

Overall PR lgtm, I like this second iteration a lot better. Thanks @shysank!

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 11, 2020
@shysank
Copy link
Contributor Author

shysank commented Dec 11, 2020

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

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

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

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

@shysank
Copy link
Contributor Author

shysank commented Dec 16, 2020

@CecileRobertMichon Just noticed that I missed to use createAzureMachineService in Delete method. Sorry, lgtm got removed. PTAL, whenever you get a chance.

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 Dec 16, 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 added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 16, 2020
@k8s-ci-robot k8s-ci-robot merged commit 73ad2c8 into kubernetes-sigs:master Dec 16, 2020
@k8s-ci-robot k8s-ci-robot added this to the v0.4.11 milestone Dec 16, 2020
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/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. 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/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants