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

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
@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 4 times, most recently 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

@stevekuznetsov stevekuznetsov force-pushed the skuznets/delegate-resource-creation branch from f265b6f to 6d8ba1a Compare May 14, 2024 22:51
@openshift-ci openshift-ci bot added the area/ci-tooling Indicates the PR includes changes for CI or tooling label May 16, 2024
@stevekuznetsov stevekuznetsov force-pushed the skuznets/delegate-resource-creation branch from b28e521 to 66ac257 Compare June 5, 2024 20:11
Copy link

netlify bot commented Jun 6, 2024

Deploy Preview for hypershift-docs ready!

Name Link
🔨 Latest commit 3e68ee3
🔍 Latest deploy log https://app.netlify.com/sites/hypershift-docs/deploys/6669b8dc4029e5000830c0dc
😎 Deploy Preview https://deploy-preview-4018--hypershift-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@stevekuznetsov stevekuznetsov force-pushed the skuznets/delegate-resource-creation branch from d3f0bbd to c695ed8 Compare June 6, 2024 16:19
@stevekuznetsov
Copy link
Contributor Author

/retest

@sjenning
Copy link
Contributor

sjenning commented Jun 6, 2024

=== RUN   TestAutoscaling/ValidateHostedCluster/EnsureNoCrashingPods
    util.go:533: Container cloud-controller-manager in pod kubevirt-cloud-controller-manager-7cc4ccf9b9-644r2 has a restartCount > 0 (1)

=== RUN   TestCreateCluster/ValidateHostedCluster/EnsureNoCrashingPods
    util.go:533: Container cloud-controller-manager in pod kubevirt-cloud-controller-manager-6d48cd658d-d6k7n has a restartCount > 0 (1)
    util.go:533: Container oauth-apiserver in pod openshift-oauth-apiserver-5c7dd4b5dc-l2s5z has a restartCount > 0 (1)

Seems like a flake but some jobs are passing now (new development)

/retest-required

@sjenning
Copy link
Contributor

sjenning commented Jun 6, 2024

/approve
/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jun 6, 2024
@stevekuznetsov
Copy link
Contributor Author

/retest

@stevekuznetsov stevekuznetsov force-pushed the skuznets/delegate-resource-creation branch from 62120ec to 3daeed6 Compare June 9, 2024 21:12
@stevekuznetsov
Copy link
Contributor Author

/retest

@stevekuznetsov
Copy link
Contributor Author

/hold cancel

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 10, 2024
@stevekuznetsov
Copy link
Contributor Author

/retest

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 12, 2024
@stevekuznetsov stevekuznetsov force-pushed the skuznets/delegate-resource-creation branch from 3daeed6 to 3e68ee3 Compare June 12, 2024 15:03
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 12, 2024
@csrwng
Copy link
Contributor

csrwng commented Jun 12, 2024

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jun 12, 2024
@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 12, 2024
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 3e68ee3 to ee7e223 Compare June 13, 2024 00:37
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Jun 13, 2024
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 13, 2024
@bryan-cox
Copy link
Member

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jun 13, 2024
@openshift-ci-robot
Copy link

/retest-required

Remaining retests: 0 against base HEAD 1f16f14 and 2 for PR HEAD ee7e223 in total

Copy link
Contributor

openshift-ci bot commented Jun 13, 2024

@stevekuznetsov: The following test 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-azure ee7e223 link false /test e2e-azure

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.

@openshift-merge-bot openshift-merge-bot bot merged commit ba61c73 into openshift:main Jun 13, 2024
12 of 13 checks passed
@openshift-bot
Copy link

[ART PR BUILD NOTIFIER]

This PR has been included in build ose-hypershift-container-v4.17.0-202406130611.p0.gba61c73.assembly.stream.el9 for distgit hypershift.
All builds following this will include this PR.

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/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. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants