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: use Service struct field more #871

Merged
merged 1 commit into from
May 25, 2021

Conversation

hidekazuna
Copy link
Contributor

What this PR does / why we need it:

This PR refactored to use gophercloud clients and logger in Service struct instead of function argument.
We can easily log something using s.logger without adding logger to function argument.

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 #

Special notes for your reviewer:

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

TODOs:

  • squashed commits
  • if necessary:
    • includes documentation
    • adds unit tests

/hold

Use gophercloud clients and logger in Service struct instead of function argument.
@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 May 20, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hidekazuna

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 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. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 20, 2021
@sbueringer
Copy link
Member

sbueringer commented May 21, 2021

@hidekazuna Can you elaborate a bit what the advantages are of this approach? In the cluster-api repo there's a similar problem and it's usually solved by handing over "input" structs with the required fields, e.g.: https://github.com/kubernetes-sigs/cluster-api/blob/master/test/framework/machinedeployment_helpers.go#L38-L43

I have to say I don't have a well thought-out opinion yet about the advantages/disadvantages of using "Input" structs versus putting more into structs and using methods. But right now I think I like Input structs more. Let's discuss it a bit what we want. Because after we decide that we will probably refactor a lot of code in this direction over time. (so please let's try to figure that out first before moving on with this PR and other similar refactorings)

@sbueringer
Copy link
Member

@hidekazuna Can you elaborate a bit what the advantages are of this approach? In the cluster-api repo there's a similar problem and it's usually solved by handing over "input" structs with the required fields, e.g.: https://github.com/kubernetes-sigs/cluster-api/blob/master/test/framework/machinedeployment_helpers.go#L38-L43

I have to say I don't have a well thought-out opinion yet about the advantages/disadvantages of using "Input" structs versus putting more into structs and using methods. But right now I think I like Input structs more. Let's discuss it a bit what we want. Because after we decide that we will probably refactor a lot of code in this direction over time.

/cc @vincepri or @fabriziopandini If you have some time, it would be nice if you can provide some context / reasoning behind "Input structs" vs "more fields in structs + using methods instead of funcs"

@hidekazuna
Copy link
Contributor Author

hidekazuna commented May 21, 2021

@sbueringer By using method and struct field which is used almost functions like gophercloud client, Logger, and clusterName, we can more focus on method specific matter, and easy to read.

By the way, as you know, CAPA and CAPZ have scope.

AWS: https://github.com/kubernetes-sigs/cluster-api-provider-aws/tree/main/pkg/cloud/scope
CAPZ: https://github.com/kubernetes-sigs/cluster-api-provider-aws/tree/main/pkg/cloud/scope

Their scope has not only client and logger but also xxCluster or XXMachine etc. Scope seems wider than our Service struct. We would need more time to create scope, so only take scope idea.

@fabriziopandini
Copy link
Member

I can give some context about the CAPI E2E test framework helpers.

The current approach of using input struct derives from the examples in https://onsi.github.io/ginkgo/#global-shared-behaviors and basically supports the idea that a func with many input parameter is hard to read; using input parameters struct the readability improves because each input values is "named" by using the fields in the input struct.

It is also important to notice that funcs in the CAPI E2E test framework helper are basically "standalone", because there is no notion of state that is shared across different function calls.

@sbueringer
Copy link
Member

sbueringer commented May 24, 2021

@hidekazuna
I agree with the current PR.
/lgtm

I don't agree with the idea mentioned here: #870 (comment) to put things like cluster name into the struct just because it's convenient.
I don't see how a cluster name makes sense in our current service abstractions as the services abstract away OpenStack services.

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

I don't agree with the idea mentioned here: #870 (comment) to put things like cluster name into the struct just because it's convenient.
I don't see how a cluster name makes sense in our current service abstractions as the services abstract away OpenStack services.

@sbueringer I understand putting clusterName into struct is not fit for current Service struct purpose: abstract layer using OpenStack services, thanks.

@hidekazuna
Copy link
Contributor Author

/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 May 24, 2021
@k8s-ci-robot k8s-ci-robot merged commit 5281717 into kubernetes-sigs:master May 25, 2021
@hidekazuna hidekazuna deleted the use_logger_field branch May 25, 2021 00:33
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. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants