-
Notifications
You must be signed in to change notification settings - Fork 204
OTA-1531: [1/x] cvo: refactor option processing #1184
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
OTA-1531: [1/x] cvo: refactor option processing #1184
Conversation
@petr-muller: This pull request explicitly references no jira issue. In response to this:
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 openshift-eng/jira-lifecycle-plugin repository. |
fb3e267
to
4f68e05
Compare
/hold Should wait until branching at least |
/retest-required |
/skip |
/hold cancel |
@petr-muller: This pull request references OTA-1531 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.20.0" version, but no target version was set. In response to this:
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 openshift-eng/jira-lifecycle-plugin repository. |
@petr-muller: This pull request references OTA-1531 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.20.0" version, but no target version was set. In response to this:
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 openshift-eng/jira-lifecycle-plugin repository. |
1 similar comment
@petr-muller: This pull request references OTA-1531 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.20.0" version, but no target version was set. In response to this:
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 openshift-eng/jira-lifecycle-plugin repository. |
Extract option validation to a new `ValidateAndComplete()` method, and run it separate from `Run()` through cobra `PreRunE`
Refactor the code to be consistent with how the other options are processed. The `NewControllerContext` is a method on `Options` struct, so it does not make sense to pass it some options through the struct, and some options through method parameters. I went further and separated the validation (performed with all other validation) from conversion, resulting in two smaller methods instead one larger one. The result is slightly less efficient but more readable.
4f68e05
to
40257c9
Compare
@@ -511,7 +517,7 @@ func (o *Options) NewControllerContext(cb *ClientBuilder, alwaysEnableCapabiliti | |||
o.PromQLTarget, | |||
o.InjectClusterIdIntoPromQL, | |||
o.UpdateService, | |||
alwaysEnableCapabilities, | |||
stringsToCapabilities(o.AlwaysEnableCapabilities), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the main point of the change - all other o.Members
are passed into NewControllerContext
via Options
, and the method relies on their earlier validation. Treating one Options
member in a different way makes the interface messy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: petr-muller, wking 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 |
@petr-muller: The following test failed, say
Full PR test history. Your PR dashboard. 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-sigs/prow repository. I understand the commands that are listed here. |
/label no-qe |
c410434
into
openshift:main
[ART PR BUILD NOTIFIER] Distgit: cluster-version-operator |
Extract option validation to a new
ValidateAndComplete()
method, and run it separate fromRun()
through cobraPreRunE
feature.Refactor the
AlwaysEnabledCapabilities
processing to be consistent with how the other options are processed. TheNewControllerContext
is a method onOptions
struct, so it does not make sense to pass it some options through the struct, and some options through method parameters. I went further and separated the validation (performed with all other validation) from conversion, resulting in two smaller methods instead one larger one. The result is slightly less efficient but more readable.The reason to do this refactor is that I need to clean up the
NewControllerContext
constructor. I will need to do some changes around, and removing the explicit pass of one option-originated argument (while all others are passed by beingOptions
members) will make the resulting code less messy. The reasoning for the changes:NewControllerContext
to consume AlwaysEnabledCapabilities from the structRun
could generally rely on running with "all options were validated" assumptionThe reason for this refactor is that I need to clean up the
NewControllerContext
constructor and theContext
structure so that they do not become messy after the changes needed for OTA-1531. Check out #1182 for the probe coarse implementation of the full thing.