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

HOSTEDCP-1542: cmd/cluster: refactor to remove example fixtures #4018

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

stevekuznetsov
Copy link
Contributor

The goal of this refactor is to reduce the complexity in the command-line tooling. Overall, the changes here remove duplicative structures that copied data around and co-locate the logic with the data, instead of first aggregating all data into one uber-structure and then conditionally acting on that structure. These refactors have a number of benefits:

  • locality of behavior: in the past, it was very difficult if not impossible to determine where a value was used, as it would be bound to a flag in one package, copied around between container structs a couple of times, then have some generic logic act on the presence or absence of the value to e.g. change a field on the HostedCluster. Simply reading the generic logic was often not enough to understand what was going on, as many of the conditional branches in the example fixture code could only ever trigger for one specific platform, and you'd never know unless you traced how the example options uber-struct had its fields set in every provider.
  • clear go-to-definition: as a knock-on effect of the above, now there's one structure that holds a command-line flag and it's trivial to use the LSP when determining where that flag is used and how
  • composability: as exemplified in the KubeVirt NodePool code, we are able to compose commands as necessary. When commands re-use the same arguments with the same flags and the same validation logic, there's no need to copy things around and re-implement anything; by localizing flag binding, validation and option completion, we gain small, composable parts that we can use to build larger commands with

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label May 10, 2024
@openshift-ci-robot
Copy link

openshift-ci-robot commented May 10, 2024

@stevekuznetsov: This pull request references HOSTEDCP-1542 which is a valid jira issue.

In response to this:

The goal of this refactor is to reduce the complexity in the command-line tooling. Overall, the changes here remove duplicative structures that copied data around and co-locate the logic with the data, instead of first aggregating all data into one uber-structure and then conditionally acting on that structure. These refactors have a number of benefits:

  • locality of behavior: in the past, it was very difficult if not impossible to determine where a value was used, as it would be bound to a flag in one package, copied around between container structs a couple of times, then have some generic logic act on the presence or absence of the value to e.g. change a field on the HostedCluster. Simply reading the generic logic was often not enough to understand what was going on, as many of the conditional branches in the example fixture code could only ever trigger for one specific platform, and you'd never know unless you traced how the example options uber-struct had its fields set in every provider.
  • clear go-to-definition: as a knock-on effect of the above, now there's one structure that holds a command-line flag and it's trivial to use the LSP when determining where that flag is used and how
  • composability: as exemplified in the KubeVirt NodePool code, we are able to compose commands as necessary. When commands re-use the same arguments with the same flags and the same validation logic, there's no need to copy things around and re-implement anything; by localizing flag binding, validation and option completion, we gain small, composable parts that we can use to build larger commands with

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.

@openshift-ci openshift-ci bot requested review from davidvossel and nirarg May 10, 2024 19:15
@openshift-ci openshift-ci bot added area/cli Indicates the PR includes changes for CLI area/hypershift-operator Indicates the PR includes changes for the hypershift operator and API - outside an OCP release area/testing Indicates the PR includes changes for e2e testing and removed do-not-merge/needs-area labels May 10, 2024
Copy link
Contributor

openshift-ci bot commented May 10, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: stevekuznetsov
Once this PR has been reviewed and has the lgtm label, please assign sjenning for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

@stevekuznetsov stevekuznetsov force-pushed the skuznets/delegate-resource-creation branch 4 times, most recently from ac7ac9d to 7e710d2 Compare May 10, 2024 20:54
@stevekuznetsov stevekuznetsov force-pushed the skuznets/delegate-resource-creation branch 3 times, most recently from fd587fa to 2a2731c Compare May 14, 2024 17:53
The goal of this refactor is to reduce the complexity in the
command-line tooling. Overall, the changes here remove duplicative
structures that copied data around and co-locate the logic with the
data, instead of first aggregating all data into one uber-structure and
then conditionally acting on that structure. These refactors have a
number of benefits:

 - locality of behavior: in the past, it was very difficult if not
   impossible to determine where a value was used, as it would be bound
   to a flag in one package, copied around between container structs a
   couple of times, then have some generic logic act on the presence or
   absence of the value to e.g. change a field on the HostedCluster.
   Simply reading the generic logic was often not enough to understand
   what was going on, as many of the conditional branches in the example
   fixture code could only ever trigger for one specific platform, and
   you'd never know unless you traced how the example options
   uber-struct had its fields set in every provider.
 - clear go-to-definition: as a knock-on effect of the above, now
   there's *one* structure that holds a command-line flag and it's
   trivial to use the LSP when determining where that flag is used and
   how
 - composability: as exemplified in the KubeVirt NodePool code, we are
   able to compose commands as necessary. When commands re-use the same
   arguments with the same flags and the same validation logic, there's
   no need to copy things around and re-implement anything; by
   localizing flag binding, validation and option completion, we gain
   small, composable parts that we can use to build larger commands with

Signed-off-by: Steve Kuznetsov <[email protected]>
We only bind flags in one routine now; breaking out explicitly the set
of flags that should only be exposed to developers in the `hypershift`
CLI. The net effect of this change is to expose `--base-domain-prefix`
and `--external-dns-domain` to users of `hcp`.

This change also shows how to change the defaults in an option set for a
command - the `hcp create cluster` command has a unique default for the
control plane availability policy, and its now evident that this is the
case since it has to be done explicitly after building the default set
of options.

Signed-off-by: Steve Kuznetsov <[email protected]>
@stevekuznetsov stevekuznetsov force-pushed the skuznets/delegate-resource-creation branch from 9725406 to f265b6f Compare May 14, 2024 18:37
Copy link
Contributor

@davidvossel davidvossel left a comment

Choose a reason for hiding this comment

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

kubevirt parts look accurate

When the test time out in Prow, the test infra sends us a SIGINT and
gives us a grace period to handle it, do cleanup, etc. There's no need
for us to do our own timeout, which causes panics and leads to corrupt
jUnit outpout.

Signed-off-by: Steve Kuznetsov <[email protected]>
@openshift-ci openshift-ci bot added the area/ci-tooling Indicates the PR includes changes for CI or tooling label May 16, 2024
Copy link
Contributor

openshift-ci bot commented May 16, 2024

@stevekuznetsov: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-kubevirt-aws-ovn b28e521 link true /test e2e-kubevirt-aws-ovn
ci/prow/e2e-azure b28e521 link false /test e2e-azure
ci/prow/e2e-aws b28e521 link true /test e2e-aws

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ci-tooling Indicates the PR includes changes for CI or tooling area/cli Indicates the PR includes changes for CLI area/hypershift-operator Indicates the PR includes changes for the hypershift operator and API - outside an OCP release area/testing Indicates the PR includes changes for e2e testing jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants