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

Add label filtering (-l) for get commands #2892

Merged
merged 2 commits into from
Mar 29, 2024

Conversation

deszhou
Copy link
Member

@deszhou deszhou commented Mar 22, 2024

What type of PR is this?

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes #2890

Does this PR introduce a user-facing change?:

Add label filtering (-l) for get commands
  • Correct label format output
➜  gwctl get httproutes -l app=backend
NAMESPACE  NAME     HOSTNAMES        PARENT REFS  AGE
default    backend  www.example.com  1            30d
  • Error label format output
➜  gwctl get httproutes -l aps=dsd,adsa,=ds
Unable to find resources that match the label selector "aps=dsd,adsa,=ds": found '=', expected: identifier after ','

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. area/gwctl labels Mar 22, 2024
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 22, 2024
@k8s-ci-robot
Copy link
Contributor

Welcome @yeedove!

It looks like this is your first PR to kubernetes-sigs/gateway-api 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/gateway-api has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Mar 22, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @yeedove. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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/test-infra repository.

@gauravkghildiyal
Copy link
Member

/assign

Copy link
Member

@gauravkghildiyal gauravkghildiyal left a comment

Choose a reason for hiding this comment

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

Thanks @yeedove! This is neat :)

One minor request, can we please have consistent names of the test functions (like TestHTTPRoutesPrinter_LabelSelector) and add a small comment before the test function describing that this is focused only on checking if label based filtering is working fine.

gwctl/cmd/get.go Outdated Show resolved Hide resolved
@@ -364,3 +365,181 @@ EffectivePolicies:
t.Errorf("Unexpected diff\ngot=\n%v\nwant=\n%v\ndiff (-want +got)=\n%v", got, want, diff)
}
}

func TestGatewaysPrinter_LabelSelector(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

This suggestions applies to the rest of the test functions as well.

Lets aim to be very focused on the piece of functionality this function is testing. In this case, since we're mostly concerned with the fact that label based filtering is working, we can try and reduce some of the other pieces of the test. For example:

  1. Maybe lets have only one GatewayClass. All gateways can be for the same GatewayClass.
  2. Lets create a helper function, within the test function like the following:
    gateway := func(name string, labels map[string]string) gatewayv1.Gateway {...}
    
    This function will return the exact same gateway, with only the name and labels varying.
  3. Within the function above, lets try to set the bare minimal set of values within the Gateway resource (of course, it need not be the strict minimal set, but whatever we can cut things down to without much trial and error)

This should really help with:

  1. Readers focusing on what is being tested.
  2. Reduce the impact of unrelated changes affecting this test function.
  3. Some wise people have said that code is a liability, so we should try and minimize when possible.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup, done!

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Mar 28, 2024
@gauravkghildiyal
Copy link
Member

/ok-to-test
/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. lgtm "Looks good to me", indicates that a PR is ready to be merged. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 29, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gauravkghildiyal, yeedove

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 Mar 29, 2024
@gauravkghildiyal
Copy link
Member

/hold

@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 Mar 29, 2024
@gauravkghildiyal
Copy link
Member

/label tide/merge-method-squash

@k8s-ci-robot k8s-ci-robot added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Mar 29, 2024
@gauravkghildiyal
Copy link
Member

/unhold

@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 Mar 29, 2024
@k8s-ci-robot k8s-ci-robot merged commit 209ee40 into kubernetes-sigs:main Mar 29, 2024
8 checks passed
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. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add label filtering (-l) for get commands
3 participants