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

kubectl explain --output plaintext #113146

Merged

Conversation

alexzielenski
Copy link
Contributor

@alexzielenski alexzielenski commented Oct 18, 2022

What type of PR is this?

/kind feature

What this PR does / why we need it:

Implements plaintext output for kubectl explain to be similar to the current output with the same amount or more information (still does not display new v3 fields, forthcoming).

Special notes for your reviewer:

Depends on #113024

Does this PR introduce a user-facing change?

Adds alpha --output plaintext protected by environment variable `KUBECTL_EXPLAIN_OPENAPIV3`

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

- [KEP]: https://github.com/kubernetes/enhancements/tree/master/keps/sig-cli/3515-kubectl-explain-openapiv3

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. 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. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Oct 18, 2022
@k8s-ci-robot k8s-ci-robot added the sig/cli Categorizes an issue or PR as relevant to SIG CLI. label Oct 18, 2022
@k8s-ci-robot
Copy link
Contributor

@alexzielenski: This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

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 needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Oct 18, 2022
@alexzielenski
Copy link
Contributor Author

/cc @apelisse @seans3

@apelisse
Copy link
Member

I think you can rebase this branch now that its dependency has merged.

@apelisse
Copy link
Member

A test would be nice for the benchmark, but looks good otherwise.

@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 Oct 26, 2022
@alexzielenski alexzielenski changed the title [WIP] kubectl explain --output plaintext kubectl explain --output plaintext Oct 31, 2022
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 31, 2022
Copy link
Member

@apelisse apelisse left a comment

Choose a reason for hiding this comment

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

Generally lgtm.

I must say the template code is a little too black-magicky to be even properly throughly reviewed, but we have tests, we're not exposing this to users at all yet, we know we can make it simpler by exposing some of these as functions but we also need to be careful about that, so I think it's good for now.

@brianpursley
Copy link
Member

brianpursley commented Nov 3, 2022

It would be nice to have some unit tests for the functions defined in funcs.go.

Also, I hate to nitpick, but when you say "to exactly model the current output", it is similar, but not really exact. Is this intentional? For example some of the indentation is different, and some of the types are different (better actually). But because you said exactly, I wanted to point out that it is not really exact in case it matters.

~/go/src/k8s.io/kubernetes (explain-output-plaintext)* $ KUBECTL_EXPLAIN_OPENAPIV3=true go run cmd/kubectl/kubectl.go explain pod
KIND:       Pod
VERSION:    v1

DESCRIPTION:
    Pod is a collection of containers that can run on a host. This resource is
    created by clients and scheduled onto hosts.
    
FIELDS:
  apiVersion	<string>
    APIVersion defines the versioned schema of this representation of an object.
    Servers should convert recognized schemas to the latest internal value, and
    may reject unrecognized values. More info:
    https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources

  kind	<string>
    Kind is a string value representing the REST resource this object
    represents. Servers may infer this from the endpoint the client submits
    requests to. Cannot be updated. In CamelCase. More info:
    https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds

  metadata	<ObjectMeta>
    Standard object's metadata. More info:
    https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata

  spec	<PodSpec>
    Specification of the desired behavior of the pod. More info:
    https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status

  status	<PodStatus>
    Most recently observed status of the pod. This data may not be up to date.
    Populated by the system. Read-only. More info:
    https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status


~/go/src/k8s.io/kubernetes (explain-output-plaintext)* $ go run cmd/kubectl/kubectl.go explain pod
KIND:     Pod
VERSION:  v1

DESCRIPTION:
     Pod is a collection of containers that can run on a host. This resource is
     created by clients and scheduled onto hosts.

FIELDS:
   apiVersion	<string>
     APIVersion defines the versioned schema of this representation of an
     object. Servers should convert recognized schemas to the latest internal
     value, and may reject unrecognized values. More info:
     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources

   kind	<string>
     Kind is a string value representing the REST resource this object
     represents. Servers may infer this from the endpoint the client submits
     requests to. Cannot be updated. In CamelCase. More info:
     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds

   metadata	<Object>
     Standard object's metadata. More info:
     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata

   spec	<Object>
     Specification of the desired behavior of the pod. More info:
     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status

   status	<Object>
     Most recently observed status of the pod. This data may not be up to date.
     Populated by the system. Read-only. More info:
     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status

@alexzielenski
Copy link
Contributor Author

Thanks Brian for pointing out the inconsistency. Yes the goal is not to be byte-for-byte exact. I've modified the description to the following:

Implements plaintext output for kubectl explain to be similar to the current output with the same amount or more information

Hopefully that explains the goal better.

@apelisse
Copy link
Member

apelisse commented Nov 3, 2022

/approve

Let's squash some of these commits, and also giving a chance for other people to take a look.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alexzielenski, apelisse

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 Nov 3, 2022
@alexzielenski
Copy link
Contributor Author

alexzielenski commented Nov 3, 2022

squashed, added unit tests for funcs

v2 package at 86% coverage

@apelisse
Copy link
Member

apelisse commented Nov 3, 2022

Thanks Alex, leaving a little bit more time for people to chime in. Will merge by EOD otherwise.

@apelisse
Copy link
Member

apelisse commented Nov 4, 2022

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 4, 2022
@apelisse
Copy link
Member

apelisse commented Nov 4, 2022

I've played with it and it works great! Tested against CRDs too, that really opens-up a lot of possible exciting improvements!

was making my own which was uncached
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 4, 2022
@apelisse
Copy link
Member

apelisse commented Nov 4, 2022

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 4, 2022
@k8s-ci-robot k8s-ci-robot merged commit b0cbf71 into kubernetes:master Nov 4, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.26 milestone Nov 4, 2022
@alexzielenski alexzielenski deleted the explain-output-plaintext branch November 16, 2022 18:49
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 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. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cli Categorizes an issue or PR as relevant to SIG CLI. 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.

None yet

4 participants