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

fix(kubectl): explain crds whose resource name is the same as builtin objects #89505

Merged
merged 1 commit into from Apr 21, 2020

Conversation

knight42
Copy link
Member

@knight42 knight42 commented Mar 26, 2020

What type of PR is this?
/kind bug

What this PR does / why we need it:
Currently, if the resource name of a custom resource is the same as one of builtin objects(like knative Service and core Service), kubectl explain fails to find the correct resource even a distinguishable short name is given.

Which issue(s) this PR fixes:

Fixes kubernetes/kubectl#749

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

Explain CRDs whose resource name are the same as builtin objects 

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@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/bug Categorizes issue or PR as related to a bug. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 26, 2020
@k8s-ci-robot
Copy link
Contributor

Hi @knight42. Thanks for your PR.

I'm waiting for a kubernetes 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.

@k8s-ci-robot k8s-ci-robot added area/kubectl sig/cli Categorizes an issue or PR as relevant to SIG CLI. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Mar 26, 2020
@knight42
Copy link
Member Author

/assign @apelisse

@seans3
Copy link
Contributor

seans3 commented Mar 26, 2020

/ok-to-test

@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. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 26, 2020
Copy link
Contributor

@seans3 seans3 left a comment

Choose a reason for hiding this comment

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

It would be nice to add a unit test to show this works as expected.

@seans3
Copy link
Contributor

seans3 commented Mar 26, 2020

/priority important-soon

@k8s-ci-robot k8s-ci-robot added priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. and removed needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Mar 26, 2020
@knight42
Copy link
Member Author

@seans3 I have updated the tests to show that SplitAndParseResourceRequest would return the resource name with group appended, but explain short name would require a mock apiserver, not sure how to verify it in the tests.

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. area/test sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/testing Categorizes an issue or PR as relevant to SIG Testing. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Mar 31, 2020
@knight42
Copy link
Member Author

/assign @deads2k

@knight42
Copy link
Member Author

knight42 commented Mar 31, 2020

@seans3 I managed to add an e2e test to verify that kubectl explain works as expected, could you take a look?

Copy link
Contributor

@soltysh soltysh left a comment

Choose a reason for hiding this comment

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

Please also squash your changes into a single commit to start with.
/assign

}
// Only returning the resource name is not enough. CRDs may have the same resource name.
// TODO(knight42): not sure whether we need to speicfy the version here.
return fmt.Sprintf("%s.%s", singular, gvr.Group), fieldsPath, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

why not changing this and return GroupVersionResource, fieldsPath and error here?

Copy link
Contributor

Choose a reason for hiding this comment

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

How this will work in the situation where I specify --api-version that is different than what you discovered here? Should there be an error in explain flow? I'd expect one.

Copy link
Member Author

Choose a reason for hiding this comment

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

How this will work in the situation where I specify --api-version that is different than what you discovered here

I would like to respect the given apiVersion, since users are likely to know what they are doing if they specify --api-version explicitly.

Copy link
Member Author

Choose a reason for hiding this comment

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

why not changing this and return GroupVersionResource, fieldsPath and error here?

fixed

@soltysh
Copy link
Contributor

soltysh commented Apr 8, 2020

@knight42 pls ping me on slack when you update this.

@knight42
Copy link
Member Author

knight42 commented Apr 9, 2020

/test pull-kubernetes-conformance-kind-ga-only-parallel

1 similar comment
@knight42
Copy link
Member Author

knight42 commented Apr 9, 2020

/test pull-kubernetes-conformance-kind-ga-only-parallel

Copy link
Contributor

@soltysh soltysh left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 20, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: knight42, soltysh

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 Apr 20, 2020
@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

2 similar comments
@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

@knight42
Copy link
Member Author

/test pull-kubernetes-e2e-gce

@k8s-ci-robot k8s-ci-robot merged commit 4362bf7 into kubernetes:master Apr 21, 2020
@k8s-ci-robot k8s-ci-robot added this to the v1.19 milestone Apr 21, 2020
@knight42 knight42 deleted the fix/kubectl-explain-crd branch April 21, 2020 08:54
@@ -120,6 +126,11 @@ var _ = SIGDescribe("CustomResourcePublishOpenAPI [Privileged:ClusterAdmin]", fu
framework.Failf("%v", err)
}

ginkgo.By("kubectl explain works for CR with the same resource name as built-in object")
if err := verifyKubectlExplain(f.Namespace.Name, customServiceShortName+".spec", `(?s)DESCRIPTION:.*Specification of CustomService.*FIELDS:.*dummy.*<string>.*Dummy property`); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

this modified a conformance test and introduced a test that has been flaking. This needs to be done in a non-conformance test first to demonstrate the test is stable.

Copy link
Member Author

Choose a reason for hiding this comment

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

@liggitt should I remove this test from the conformance tests first?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, revert the conformance test to its previous state and isolate the new test in a non-conformance e2e test (marked as flaky until the test has been deflaked)

@knight42 knight42 restored the fix/kubectl-explain-crd branch April 27, 2020 03:35
@knight42 knight42 deleted the fix/kubectl-explain-crd branch May 29, 2020 12:17
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/kubectl area/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. 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. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/cli Categorizes an issue or PR as relevant to SIG CLI. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kubectl explain: shows the wrong resource
8 participants