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

Added --depth flag to get fields recursively upto certain depth #127820

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ak20102763
Copy link
Contributor

@ak20102763 ak20102763 commented Oct 2, 2024

What type of PR is this?

/kind feature

What this PR does / why we need it:

This PR adds new flag --depth to kubectl explain <resource> --recursive command to limit the level up to which fields are recursively explained. Users can now limit the depth of field explanations when using the recursive option, providing more control over the output. It enhances the UX by giving more flexibility.

Which issue(s) this PR fixes:

Fixes kubernetes/kubectl#1659

Special notes for your reviewer:

  1. --depth support added in kubectl/pkg/cmd/explain/explain.go
  2. Depth support added for two and only types of outputs -> plaintext and plaintext-openapiv2
  3. Updated command usage information
  4. Added relevant unit tests
  5. Error handling for invalid --depth inputs

Does this PR introduce a user-facing change?

Added a new `--depth` flag to the `kubectl explain <resource> --recursive` command. This flag allows users to limit the depth of recursive field explanations, providing more control over the output.

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

Example:

When the --depth flag is not used, the entire structure of the resource fields will be recursively explained. For ex:

$ kubectl explain pods.spec.affinity.podAffinity --recursive --output plaintext-openapiv2

KIND:     Pod
VERSION:  v1

RESOURCE: podAffinity <Object>

DESCRIPTION:
     Describes pod affinity scheduling rules (e.g. co-locate this pod in the
     same node, zone, etc. as some other pod(s)).

     Pod affinity is a group of inter pod affinity scheduling rules.

FIELDS:
   preferredDuringSchedulingIgnoredDuringExecution	<[]Object>
      podAffinityTerm	<Object>
         labelSelector	<Object>
            matchExpressions	<[]Object>
               key	<string>
               operator	<string>
               values	<[]string>
            matchLabels	<map[string]string>
         matchLabelKeys	<[]string>
         mismatchLabelKeys	<[]string>
         namespaceSelector	<Object>
            matchExpressions	<[]Object>
               key	<string>
               operator	<string>
               values	<[]string>
            matchLabels	<map[string]string>
         namespaces	<[]string>
         topologyKey	<string>
      weight	<integer>
   requiredDuringSchedulingIgnoredDuringExecution	<[]Object>
      labelSelector	<Object>
         matchExpressions	<[]Object>
            key	<string>
            operator	<string>
            values	<[]string>
         matchLabels	<map[string]string>
      matchLabelKeys	<[]string>
      mismatchLabelKeys	<[]string>
      namespaceSelector	<Object>
         matchExpressions	<[]Object>
            key	<string>
            operator	<string>
            values	<[]string>
         matchLabels	<map[string]string>
      namespaces	<[]string>
      topologyKey	<string>

By using the --depth flag, user can now limit how deep the recursive explanation goes. For ex, setting --depth=2 will limit the output to only two levels of fields

$ kubectl explain pods.spec.affinity.podAffinity --recursive --depth 2 --output plaintext-openapiv2

KIND:     Pod
VERSION:  v1

RESOURCE: podAffinity <Object>

DESCRIPTION:
     Describes pod affinity scheduling rules (e.g. co-locate this pod in the
     same node, zone, etc. as some other pod(s)).

     Pod affinity is a group of inter pod affinity scheduling rules.

FIELDS:
   preferredDuringSchedulingIgnoredDuringExecution	<[]Object>
      podAffinityTerm	<Object>
      weight	<integer>
   requiredDuringSchedulingIgnoredDuringExecution	<[]Object>
      labelSelector	<Object>
      matchLabelKeys	<[]string>
      mismatchLabelKeys	<[]string>
      namespaceSelector	<Object>
      namespaces	<[]string>
      topologyKey	<string>

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. kind/feature Categorizes issue or PR as related to a new feature. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Oct 2, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: ak20102763
Once this PR has been reviewed and has the lgtm label, please assign brianpursley for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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 cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. sig/cli Categorizes an issue or PR as relevant to SIG CLI. labels Oct 2, 2024
@k8s-ci-robot
Copy link
Contributor

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-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Oct 2, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @ak20102763. 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-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Oct 3, 2024
@ak20102763
Copy link
Contributor Author

ak20102763 commented Oct 4, 2024

Hi @ardaguclu / @apelisse, if you think this feature is reasonable to add, can you review this PR and suggest changes?

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 10, 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 Oct 10, 2024
@ak20102763 ak20102763 changed the title --depth flag added to limit depth of recursive field explanation Added --depth flag to get fields recursively upto certain depth Oct 10, 2024
flag usage docs updated

Added depth test cases for plaintext template
@ak20102763
Copy link
Contributor Author

/cc @apelisse

@ak20102763
Copy link
Contributor Author

I guess this is unlikely to get merged because of large code change and potential new flag, though I will keep this PR open in case someone finds this feature interesting in future. Feel free to suggest changes if any 🙂.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. 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/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
Status: Needs Triage
Development

Successfully merging this pull request may close these issues.

kubectl explain --recursive --depth 5
2 participants