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 gwctl: restructure codebase, add new commands, and enable extensions #3244

Closed

Conversation

gauravkghildiyal
Copy link
Member

@gauravkghildiyal gauravkghildiyal commented Aug 4, 2024

What type of PR is this?
/kind feature

What this PR does / why we need it:

Apologies for the large size of this PR, but it represents a significant step forward in making gwctl more usable and extensible. The updated README.md provides a comprehensive overview of all the latest capabilities.

  • Introduce new command structure and new commands (Highlights: analyze, apply, delete)
  • Implement extensions and validation (think of this like k8s webhooks that operate on a provided input and return validations / modifications)
  • Improve topology visualization and graph generation.
  • Enabled CRUD operations for non-Gateway resources.
  • Better error handling and reporting details to the user

Next steps:

  • Provide a contributions guide to facilitate adding more validations and extensions.
  • Expand unit and integration test coverage. I have added some basic framework for integration tests.

Does this PR introduce a user-facing change?:

Add features analyze, apply, delete and graphing to gwctl. 

/area gwctl

@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/feature Categorizes issue or PR as related to a new feature. area/gwctl labels Aug 4, 2024
@k8s-ci-robot k8s-ci-robot requested a review from mlavacca August 4, 2024 22:19
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 4, 2024
@k8s-ci-robot k8s-ci-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Aug 4, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gauravkghildiyal

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 Aug 4, 2024
@gauravkghildiyal
Copy link
Member Author

/cc @robscott

@k8s-ci-robot k8s-ci-robot requested a review from robscott August 4, 2024 22:25
@gauravkghildiyal gauravkghildiyal force-pushed the gwctl-revamp branch 2 times, most recently from 1e89830 to 8f0d1ca Compare August 5, 2024 03:22
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 7, 2024
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 9, 2024
Copy link
Member

@mlavacca mlavacca left a comment

Choose a reason for hiding this comment

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

Thanks for all the work on this, @gauravkghildiyal!

This PR looks massive and I honestly find the review of such a big piece of code very hard. Since in the PR description you outlined what the PR is about (this is great description) I wonder if it is possible to split this PR into multiple smaller PRs, focused on a specific area of improvement/refactoring. Do you think it's feasible? It'd help a lot the review :)

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 12, 2024
@gauravkghildiyal
Copy link
Member Author

Thanks for all the work on this, @gauravkghildiyal!

This PR looks massive and I honestly find the review of such a big piece of code very hard. Since in the PR description you outlined what the PR is about (this is great description) I wonder if it is possible to split this PR into multiple smaller PRs, focused on a specific area of improvement/refactoring. Do you think it's feasible? It'd help a lot the review :)

Thanks for taking the time to help with this @mlavacca. I totally feel the pain of reviewing a PR like this. I've started with splitting this into individual commits, ordered in a manner to make things easier to review.

Given the number of issues this PR tackles, as I was developing the code, I realized that splitting it into completely independent, atomic PRs would have significantly impacted development time. Obviously, there are tradeoffs to that decision which appear in the form of not-so-easy reviews. I understand that a comprehensive review may be challenging within a reasonable timeframe. I propose we prioritize identifying any obvious "red flags" and rely on the integration tests to verify the overall behaviour. We can continue to improve the codebase iteratively in future PRs.

@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 14, 2024
Copy link
Member

@robscott robscott left a comment

Choose a reason for hiding this comment

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

Thanks @gauravkghildiyal! Partial review from last week, will try to get back to this soon.

fmt.Fprintf(o.IOStreams.Out, "\n")

// Step 1: Parse the files and extract the objects from the files.
infos, err := o.factory.NewBuilder().
Copy link
Member

Choose a reason for hiding this comment

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

Nit: "infos" feels like an overly vague name here, is there something a bit more specific that would work here?

graph, err := topology.NewBuilder(common.NewDefaultGroupKindFetcher(o.factory, common.WithAdditionalResources(sources))).
StartFrom(sources).
UseRelationships(topologygw.AllRelations).
WithMaxDepth(4).
Copy link
Member

Choose a reason for hiding this comment

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

This seems like something that should be configurable?

}

policyManager := policymanager.New(common.NewDefaultGroupKindFetcher(o.factory, common.WithAdditionalResources(sources)))
if err := policyManager.Init(); err != nil { //nolint:govet
Copy link
Member

Choose a reason for hiding this comment

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

Why's the nolint needed here?

topologygw "sigs.k8s.io/gateway-api/gwctl/pkg/topology/gateway"
)

func NewCmd(factory common.Factory, iostreams genericiooptions.IOStreams) *cobra.Command {
Copy link
Member

Choose a reason for hiding this comment

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

Somewhere in this file it would be useful to have a comment describing what the analyze command is trying to achieve.

return fmt.Errorf("%v: %v", info.Source, err)
}

obj, err := helper.Patch(
Copy link
Member

Choose a reason for hiding this comment

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

When I see Patch, I assume this will only update existing options, where I'd expect apply to do an upsert

Comment on lines +57 to +68
case "gatewayclass", "gateawyclasses":
objRef.Group = gatewayv1.GroupVersion.Group
objRef.Kind = "GatewayClass"
objRef.Namespace = ""
case "gateway", "gateways":
objRef.Group = gatewayv1.GroupVersion.Group
objRef.Kind = "Gateway"
case "httproute", "httproutes":
objRef.Group = gatewayv1.GroupVersion.Group
objRef.Kind = "HTTPRoute"
case "service", "services":
objRef.Kind = "Service"
Copy link
Member

Choose a reason for hiding this comment

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

A comment describing why these are the only supported input types would be useful.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 24, 2024
@k8s-ci-robot
Copy link
Contributor

PR needs rebase.

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.

@k8s-ci-robot
Copy link
Contributor

@gauravkghildiyal: 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
pull-gateway-api-crds-validation-3 41f8da8 link true /test pull-gateway-api-crds-validation-3
pull-gateway-api-crds-validation-2 41f8da8 link true /test pull-gateway-api-crds-validation-2
pull-gateway-api-crds-validation-1 41f8da8 link true /test pull-gateway-api-crds-validation-1
pull-gateway-api-crds-validation-5 41f8da8 link true /test pull-gateway-api-crds-validation-5
pull-gateway-api-crds-validation-4 41f8da8 link true /test pull-gateway-api-crds-validation-4

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-sigs/prow repository. I understand the commands that are listed here.

@shaneutt
Copy link
Member

@gauravkghildiyal at this point should we close this and apply it to the new repository, since this is getting moved?

@shaneutt shaneutt added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Sep 18, 2024
@robscott
Copy link
Member

@gauravkghildiyal at this point should we close this and apply it to the new repository, since this is getting moved?

good point, yeah, I think this got missed

@robscott robscott closed this Sep 18, 2024
@gauravkghildiyal
Copy link
Member Author

Thanks Shane, thanks Rob!

I'll archive any other open PRs and issues too, or suggest people reopen them on kubernetes-sigs/gwctl

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/gwctl cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants