kubernetes / kubectl

Issue tracker and mirror of kubectl code
Apache License 2.0
2.75k stars 894 forks source link

Add optional full yaml paths to `kubectl explain` output #1604

Open spkane opened 1 month ago

spkane commented 1 month ago

What would you like to be added: It would be GREAT if there was a way to get kubectl explain to output the full yaml path for each entry, especially when --recursive is set.

So, output that looks like this today:

  metadata  <ObjectMeta>
    annotations <map[string]string>
    managedFields   <[]ManagedFieldsEntry>
      apiVersion    <string>
      fieldsType    <string>

might look like this:

  metadata  <ObjectMeta>      [metadata]
    annotations <map[string]string>      [metadata.annotations]
    managedFields   <[]ManagedFieldsEntry>      [metadata.managedFields]
      apiVersion    <string>      [metadata.managedFields.apiVersion]
      fieldsType    <string>      [metadata.managedFields.apiVersion]

Why is this needed:

In addition to using kubectl explain to find out what a field is for and what type it expects, it could be very useful in determining where in the YAML structure a section belongs. With this change, running something like the following would make it much clearer WHERE the section belongs in the YAML manifest.

$ kubectl explain pod --recursive=true | grep preferredDuringSchedulingIgnoredDuringExecution

        preferredDuringSchedulingIgnoredDuringExecution <[]PreferredSchedulingTerm>    
  [spec.affinity.nodeAffinity.preferredDuringSchedulingIgnoredDuringExecution]
        preferredDuringSchedulingIgnoredDuringExecution <[]WeightedPodAffinityTerm>    
  [mspec.affinity.podAffinity.preferredDuringSchedulingIgnoredDuringExecution]
        preferredDuringSchedulingIgnoredDuringExecution <[]WeightedPodAffinityTerm>    
  [mspec.affinity.podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecution]
k8s-ci-robot commented 1 month ago

This issue is currently awaiting triage.

SIG CLI takes a lead on issue triage for this repo, but any Kubernetes member can accept issues by applying the triage/accepted label.

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](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes-sigs/prow](https://github.com/kubernetes-sigs/prow/issues/new?title=Prow%20issue:) repository.