Coder Social home page Coder Social logo

ahmetb / kubectl-tree Goto Github PK

View Code? Open in Web Editor NEW
2.9K 23.0 118.0 2.65 MB

kubectl plugin to browse Kubernetes object hierarchies as a tree 🎄 (star the repo if you are using)

License: Apache License 2.0

Go 100.00%
kubectl-plugin kubectl-plugins kubectl

kubectl-tree's Introduction

kubectl tree logo

kubectl tree

A kubectl plugin to explore ownership relationships between Kubernetes objects through ownersReferences on the objects.

The kubectl lineage plugin is very similar to kubectl tree, but it understands logical relationships between some API objects without needing ownerReferences.

Installation

Use krew plugin manager to install:

kubectl krew install tree
kubectl tree --help

Demo

Example (Deployment):

example Kubernetes deployment object hierarchy

Example (Knative Service):

example Kubernetes object hierarchy with Knative Service

Example (Agones Fleet):

example Kubernetes object hierarchy with Agones Fleet

Flags

By default, the plugin will only search "namespaced" objects in the same namespace as the specified object.

You can use the -A or --all-namespaces flag to search namespaced and non-namespaced objects in all namespaces.

Author

Ahmet Alp Balkan @ahmetb.

Special acknowledgement: This tool is heavily inspired by @nimakaviani's knative-inspect as it's a generalized version of it.

License

Apache 2.0. See LICENSE.


This is not an official Google project.

kubectl-tree's People

Contributors

ahmetb avatar andidog avatar bergerx avatar eriner avatar feloy avatar ferhatelmas avatar iboonox avatar makkes avatar rajatjindal avatar ryysud avatar sammcj avatar shihyuho avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kubectl-tree's Issues

Query resources in current namespace by default

This came up in #9, #14 and #16.

Right now (v0.3.x) we are querying ALL objects in ALL api groups (without any namespace limitation). This has several problems:

  • fails to query api X, because user has access to X in namespace1, but not in namespace2
  • takes too long to enumerate all APIs across all namespaces (#16)

From controller examples like Kubernetes Deployment, Knative, Agones, etc. it's fair to assume that resources don't often create child resources in other namespaces.

Proposed solution

When kubectl tree is querying child objects of a specified object:

  • we should query only "namespaced" objects in the same namespace as the specified object as the new default
  • we should offer --all-namespaces option to retain the current behavior (e.g. query all objects in all API groups –both namespaced and non-namespaced)

This addresses:

  • slowness when used with large clusters with too many objects
  • allow an escape hatch for the current behavior to still exist
  • allow plugin to work when user has (full-) access to only some namespaces

It would likely work by refactorying query method to be namespace-scoped (query only namespaced APIs in the specified namespace) OR global-scoped (query both namespaced & non-namespaced APIs without specifying a namespace limitation, i.e. what we do today).

plugin doesn't work with latest kubectl?

My kubectl version is:

Client Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.3", GitCommit:"06ad960bfd03b39c8310aaf92d1e7c12ce618213", GitTreeState:"clean", BuildDate:"2020-02-13T18:08:14Z", GoVersion:"go1.13.8", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.2", GitCommit:"59603c6e503c87169aea6106f57b9f242f64df89", GitTreeState:"clean", BuildDate:"2020-01-18T23:22:30Z", GoVersion:"go1.13.5", Compiler:"gc", Platform:"linux/amd64"}

kubectl krew install tree looked like it completed with no errors.

Attempting to run the plugin results in:

❯ kubectl tree                                                                                                                                                                                                                                                                                                                                                                       
Error: unknown command "tree" for "kubectl"
Run 'kubectl --help' for usage.

K8s version is 1.17.2. Krew appears to be functioning properly.

Windows support

The special utf chars used in the tree aren’t available on Windows. need to set simpler ascii alternatives for windows.

I think colors will work thanks to fatih/colors pkg used.

Then it needs some hands on testing/validation.

Could not find the cluster-scoped resource

We are developing a Custom Controller and creating resources with the cluster-scoped CR set to OwnerReference, but kubectl tree doesn't work as bellow:

$ kubectl api-resources
NAME                              SHORTNAMES   APIGROUP                       NAMESPACED   KIND
samples                                        sample.example.org             false        Sample

$ kubectl tree samples sample -A
Error: failed to get samples/sample: the server could not find the requested resource

Error on listing resources

I would like to execute:
k tree deployment grafana

but I get error:

Error: error while querying api objects: listing resources failed (monitoring.kiali.io/v1alpha1, Resource=monitoringdashboards): monitoringdashboards.monitoring.kiali.io is forbidden: User "developer" cannot list resource "monitoringdashboards" in API group "monitoring.kiali.io" in the namespace "grafanaoperator"

I would expect right tree will appear (as the abovementioned object is not part of the tree afaik)

Either way even dispalying partially tree would be more useful

"kubectl tree" not working for Kubeflow profiles (not namespaced)

Maybe I am doing something horrrably wrong here (please correct me if so), or there seems to be a problem for getting the graph from a Kubeflow profiles CRD.

❯ kubectl tree profiles my-kubeflow-user
No resources are owned by this object through ownerReferences.

This resoruce look slike as follows (removed not necessary parts):

❯ kubectl get profiles my-kubeflow-user -o yaml
apiVersion: kubeflow.org/v1
kind: Profile
metadata:
  name: my-kubeflow-user
spec:
  owner:
    kind: User
    name: [email protected]

This resource then creates e.g. a namespace:

❯ kubectl get ns my-kubeflow-user -o yaml
apiVersion: v1
kind: Namespace
metadata:
  annotations:
    owner: [email protected]
  labels:
    app.kubernetes.io/part-of: kubeflow-profile
    istio-injection: enabled
  name: my-kubeflow-user
  ownerReferences:
  - apiVersion: kubeflow.org/v1
    blockOwnerDeletion: true
    controller: true
    kind: Profile
    name: my-kubeflow-user
    uid: c39a1fbe-7805-4696-85a6-1234f902cc2b
status:
  phase: Active

Maybe it is because it is a CRD, or because it is not namespaced?

Add label-selector to mitigate workload and data volume

This tool may not be applicable to large clusters as it lists all resources within the cluster. We can address this by filtering resources based on labels. It would alleviate the workload and reduce the transmitted data volume from the kube-api.

e.g:

$ kubectl tree hazelcast hz --selector='app.kubernetes.io/instance=hz'                                   ✔ │ 11:28:09 PM  
NAMESPACE  NAME                                  READY  REASON  STATUS   AGE
default    Hazelcast/hz                          -              -        30s
default    ├─Role/hz                             -              -        30s
default    ├─RoleBinding/hz                      -              -        30s
default    ├─Secret/hz                           -              -        30s
default    ├─Service/hz                          -              -        30s
default    │ └─EndpointSlice/hz-t7b2k            -              -        30s
default    ├─ServiceAccount/hz                   -              -        30s
default    └─StatefulSet/hz                      -              -        30s
default      ├─ControllerRevision/hz-7855bcc97c  -              -        30s
default      ├─Pod/hz-0                          True           Current  30s
default      ├─Pod/hz-1                          True           Current  30s
default      └─Pod/hz-2                          True           Current  30s

Duplicate tree items, if a resource has two owners.

One of my child CRDs has two ownerRefs.

Unfortunately this results in a duplication:

NAMESPACE  NAME                                                                          READY  REASON  AGE
cluster    ClusterStack/clusterstack                                                     -              24m
cluster    ├─ClusterStackRelease/hellopa-apalla-1-26-v6                                  True           24m
cluster    │ └─HellopaClusterStackRelease/hellopa-apalla-1-26-v6                         -              24m
cluster    │   ├─HellopaNodeImageRelease/hellopa-apalla-1-26-controlplaneamd64hcloud-v5  -              24m
cluster    │   └─HellopaNodeImageRelease/hellopa-apalla-1-26-workeramd64hcloud-v5        -              24m
cluster    └─HellopaClusterStackRelease/hellopa-apalla-1-26-v6                           -              24m
cluster      ├─HellopaNodeImageRelease/hellopa-apalla-1-26-controlplaneamd64hcloud-v5    -              24m
cluster      └─HellopaNodeImageRelease/hellopa-apalla-1-26-workeramd64hcloud-v5          -              24m

HellopaClusterStackRelease/hellopa-apalla-1-26-v6 and the two children are twice in the tree.

The tool linage does not duplicate the children of this object:

k lineage -n cluster --exclude-types events clusterstacks clusterstack

NAME                                                                                 READY   STATUS   AGE
ClusterStack/clusterstack                                                            -                27m
├── ClusterStackRelease/hellopa-apalla-1-26-v6                                       True             27m
│   └── HellopaClusterStackRelease/hellopa-apalla-1-26-v6                            -                27m
│       ├── HellopaNodeImageRelease/hellopa-apalla-1-26-controlplaneamd64hcloud-v5   -                27m
│       └── HellopaNodeImageRelease/hellopa-apalla-1-26-workeramd64hcloud-v5         -                27m
└── HellopaClusterStackRelease/hellopa-apalla-1-26-v6                                -                27m

i think it is better to not show the children twice.

Command reports ambiguous kind that's not ambiguous

$ k tree kubegres my-db
Error: ambiguous kind "kubegres". use one of these as the KIND disambiguate: [kubegres.v1.kubegres.reactive-tech.io, kubegres.v1.kubegres.reactive-tech.io]

The two kinds listed are exactly the same.

Getting "can't have a plugin without specifying file operations"

(⎈ |dev-1:default)➜  ~ kubectl krew install tree
Updated the local copy of plugin index.
F1030 15:38:17.757783   13221 root.go:52] failed to load plugin "tree" from the index: platform ({Head: URI:https://github.com/ahmetb/kubectl-tree/releases/download/v0.4.0/kubectl-tree_v0.4.0_darwin_amd64.tar.gz Sha256:c90dd260212b7da7163f12a27269923dedaeb17667616d990aa7ddbee31d2364 Selector:&LabelSelector{MatchLabels:map[string]string{arch: amd64,os: darwin,},MatchExpressions:[],} Files:[] Bin:kubectl-tree}) is badly constructed: can't have a plugin without specifying file operations

CR always report no resources

root@gyliu-dev21:~# kubectl get opreg -n ibm-common-services
NAME             AGE   PHASE     CREATED AT
common-service   27h   Running   2021-02-18T09:19:27Z
root@gyliu-dev21:~# kubectl tree opreg common-service -n ibm-common-services
No resources are owned by this object through ownerReferences.

How can I enable the tree can also works with a CR?

Have to disambiguate between deployment APIs is cumbersome

$ kubectl tree deploy nginx
Error: ambiguous kind "deploy". use one of these as the KIND disambiguate: [deployments.v1beta1.extensions, deployments.v1.apps]

This is because both extensions/v1beta1 and apps/v1 are returned as "preferred" API resources from the kube-apiserver. Maybe we use filter to eliminate one.

auth client doesn't work with oidc

Gives me the following error when running the command:

± |master ✗ | → kubectl-tree kservice.v1.serving.knative.dev echo
Error: failed to construct dynamic client: no Auth Provider found for name "oidc"

Doesn't take into account cluster.proxy-url

When I use clusters described with a proxy-url in kubeconfig:

- cluster:
    certificate-authority-data: DATA+OMITTED
    proxy-url: http://localhost:9000
    server: ...

I end up getting a timeout to another IP:

Error: failed to get deploy/echoserver: Get "https://XXX/apis/apps/v1/namespaces/default/deployments/echoserver": dial tcp 104.43.X.X:443: i/o timeout

Would it be possible to have this field honoured? Or a workaround?

Thanks

Cannot run with viewer role

In querying APIs, failed to list secret and cannot show the result.

When I try to run kubectl tree with viewer role, got the following error:

Error: error while querying api objects: listing resources failed (/v1, Resource=secrets): 
secrets is forbidden: User "[email protected]" cannot list resource "secrets" in API group "" at the cluster scope: Required "container.secrets.list" permission.

Plugin won't install on newer macs with Apple Silicon / M1 processor

When trying to install this plug in my Macbook air (with M1 processor) I get the following error:

kubectl krew install tree
Updated the local copy of plugin index.
Updated the local copy of plugin index "kvaps".
Installing plugin: tree
W0829 14:09:37.491565   12970 install.go:164] failed to install plugin "tree": plugin "tree" does not offer installation for this platform
F0829 14:09:37.491618   12970 root.go:79] failed to install some plugins: [tree]: plugin "tree" does not offer installation for this platform

Would it be possible to to add a darwin/arm64 build target?

Pods missing in tree

Hi,

thanks for you work 💪

I have a fresh installed k8s cluster installed with k3d and when lauching kubectl-tree, my pods are not listed except the pause one :

$ kubectl tree service k3d-demo
NAMESPACE  NAME                                              READY  REASON  AGE
k3d-demo   Service/k3d-demo                                  -              124m
k3d-demo   └─DaemonSet/svclb-k3d-demo                        -              124m
k3d-demo     ├─ControllerRevision/svclb-k3d-demo-6b8cb54945  -              124m
k3d-demo     └─Pod/svclb-k3d-demo-4bggv                      True           124m

here is the pods running :

$ kubectl get po
NAME                                   READY   STATUS    RESTARTS   AGE
svclb-k3d-demo-4bggv                   1/1     Running   0          128m
k3d-demo-deployment-7b78fd74d5-nlmwc   1/1     Running   0          128m
k3d-demo-deployment-7b78fd74d5-p7dmk   1/1     Running   0          128m
k3d-demo-deployment-7b78fd74d5-9rtbd   1/1     Running   0          128m

here is an inspect of one of the missing pod :

$ kubectl describe pods/k3d-demo-deployment-7b78fd74d5-nlmwc
Name:         k3d-demo-deployment-7b78fd74d5-nlmwc
Namespace:    k3d-demo
Priority:     0
Node:         YYYYY/ZZZZZZZZZZZ
Start Time:   Wed, 08 Jan 2020 14:05:43 +0100
Labels:       app=k3d-demo
              app.kubernetes.io/managed-by=skaffold-v1.1.0
              pod-template-hash=7b78fd74d5
              skaffold.dev/builder=local
              skaffold.dev/cleanup=true
              skaffold.dev/deployer=kubectl
              skaffold.dev/docker-api-version=1.29
              skaffold.dev/run-id=9e3afc5c-d0af-47a9-b210-67199a7c9df4
              skaffold.dev/tag-policy=git-commit
              skaffold.dev/tail=true
Annotations:  <none>
Status:       Running
IP:           XX.XX.XX.XX
IPs:
  IP:           XX.XX.XX.XX
Controlled By:  ReplicaSet/k3d-demo-deployment-7b78fd74d5
Containers:
  k3d-demo:
    Container ID:   docker://3b81a0f0d1e8e81726ef987b3983d414e8d7a892e49cd426decd0f26c592685a
    Image:          containous/whoami
    Image ID:       docker-pullable://containous/whoami@sha256:c0d68a0f9acde95c5214bd057fd3ff1c871b2ef12dae2a9e2d2a3240fdd9214b
    Port:           80/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Wed, 08 Jan 2020 14:05:46 +0100
    Ready:          True
    Restart Count:  0
    Limits:
      cpu:     500m
      memory:  128Mi
    Requests:
      cpu:        10m
      memory:     32Mi
    Environment:  <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-4bbnq (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  default-token-4bbnq:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-4bbnq
    Optional:    false
QoS Class:       Burstable
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:          <none>

I expect my pods listed under ControllerRevision/svclb-k3d-demo-6b8cb54945 but I may be wrong. What do you think ?

Regards

ARM support

Any chance we might be able to get ARM support for this plugin? I'm running a cluster on a few Raspberry Pi 4s and would love to include this in my demos/presentations! 👍

support for custom columns

Hi, first of all, thanks for this great tool!

I have been using it with different operators that we have built and sometimes these operators have additional information that might be of interest to show in the tree. But that would apply for kubernetes native objects also, e.g to show extra information in another column.

Would it make sense to add some configuration mechanism to configure kubectl tree to show these additional columns with configured values? heavily inspired by CRD additionalPrinterColumns? and also bringing its limitations where it won't support arrays or structures other than basic ones.

for example:

  additionalPrinterColumns:
  - JSONPath: .status.readyReplicas
    name: Ready
    type: string
  - JSONPath: .status.reason
    name: Reason
    type: string

assuming the customApp has .status.reason this would result in:

NAMESPACE  NAME                                      READY     REASON    AGE  READY
default    CustomApp/blueprint                       -         Updated   47h
default    ├─Deployment/blueprint                    -                   47h   1
default    │ └─ReplicaSet/blueprint-5d56cc7c4f       -                   47h
default    │   └─Pod/blueprint-5d56cc7c4f-hmbjr      True                47h
default    ├─PodDisruptionBudget/blueprint           -                   47h
default    └─Service/blueprint                       -                   47h
default      └─EndpointSlice/blueprint-wkjd2         -                   47h

and question would be where this additional config of kubectl-tree would live in 🙂

Add --watch support

It would be awesome to deploy some big resource (say Knative Service) and then kubectl tree --watch it to see how things get ready.

The alternative would be watch kubectl tree, but then we lose colors. So maybe an alternative would be a way to always have colors, even when not a TTY?

Support PV/PVC/StorageClass?

Hi,

Just curious about kubectl-tree support PV/PVC/StorageClass. I upgraded to latest version (0.4.3) but seems no luck.

$ k get pvc
NAME                      STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
prometheus-alertmanager   Bound    pvc-f80a052c-5778-46b2-9aef-7932c02e7517   2Gi        RWO            standard       19h
prometheus-server         Bound    pvc-d5bed05a-cc57-4c80-91b1-cba8fcd7e706   8Gi        RWO            standard       19h

$ k get pv
NAME                                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                             STORAGECLASS   REASON   AGE
pvc-d5bed05a-cc57-4c80-91b1-cba8fcd7e706   8Gi        RWO            Delete           Bound    default/prometheus-server         standard                19h
pvc-f80a052c-5778-46b2-9aef-7932c02e7517   2Gi        RWO            Delete           Bound    default/prometheus-alertmanager   standard                19h

$ k tree pvc prometheus-alertmanager
No resources are owned by this object through ownerReferences.

$ k tree --version
kubectl version v0.4.3

$ k version
WARNING: This version information is deprecated and will be replaced with the output from kubectl version --short.  Use --output=yaml|json to get the full version.
Client Version: version.Info{Major:"1", Minor:"25", GitVersion:"v1.25.4", GitCommit:"872a965c6c6526caa949f0c6ac028ef7aff3fb78", GitTreeState:"clean", BuildDate:"2022-11-09T13:28:30Z", GoVersion:"go1.19.3", Compiler:"gc", Platform:"darwin/arm64"}
Kustomize Version: v4.5.7
Server Version: version.Info{Major:"1", Minor:"25", GitVersion:"v1.25.0", GitCommit:"a866cbe2e5bbaa01cfd5e969aa3e033f3282a8a2", GitTreeState:"clean", BuildDate:"2022-09-01T23:34:08Z", GoVersion:"go1.19", Compiler:"gc", Platform:"linux/arm64"}

Show parents/ancestors option

Hi, thank you for the great plugin!

This is a feature request/idea: how about offering an option to show resource parents/ancestors (i.e.: reverse hierarchy).
It's extremely useful when you have many CRDs and are confused which CR has others.

certificate signed by unknown authority error

I'm having certificate problems using this tool. Guessing it is because it's not loading local ca-bundle or something like that?

$ k tree app pt-sak-consumer
Error: failed to fetch api groups from kubernetes: Get https://apiserver.xxx.no:14125/api?timeout=32s: x509: certificate signed by unknown authority

Linux/aarch64 : plugin "tree" does not offer installation for this platform

Hello,

I'd like to know how to compile kubectl-tree for Linux/aarch64 , please help !

ubuntu@n9:~$ microk8s.kubectl krew install tree
Updated the local copy of plugin index.
Installing plugin: tree
W0927 17:14:41.405917  492079 install.go:164] failed to install plugin "tree": plugin "tree" does not offer installation for this platform
failed to install some plugins: [tree]: plugin "tree" does not offer installation for this platform

ubuntu@n9:~$ uname -m
aarch64

ubuntu@n9:~$ uname
Linux

Explore ownership between built-in and custom resources

I do have a custom cluster-scoped resource CISKubeBenchReport that I'm associating with a built-in Node object. However, when I run $ kubectl tree node <node name> I cannot see such relationship displayed.

My objects, stripped out of nonessential properties, look as follows:

apiVersion: v1
kind: Node
metadata:
  name: minikube
  resourceVersion: "1666012"
  selfLink: /api/v1/nodes/minikube
  uid: 5d411e05-920b-4e56-a1c3-44da5bd7f12b
apiVersion: aquasecurity.github.io/v1alpha1
kind: CISKubeBenchReport
metadata:
  name: minikube-1594903596
  ownerReferences:
  - apiVersion: v1
    controller: false
    kind: Node
    name: minikube
    uid: 5d411e05-920b-4e56-a1c3-44da5bd7f12b
  resourceVersion: "1666246"
  selfLink: /apis/aquasecurity.github.io/v1alpha1/ciskubebenchreports/minikube-1594903596
  uid: d0e9598b-9372-4915-a4af-8d1c92710817
$ kubectl tree node minikube
No resources are owned by this object through ownerReferences.

Is there anything that I'm missing in my onwerReferences config or is that kubectl-tree that cannot handle such config?

Add a flag to support a list of condition types

The current implementation only supports a condition with type Ready. However it could be great to support additional condition types that can be used on custom resource types.

As an example,

kubectl tree customresource --ready-cond-types=Ready,Processed,Scheduled....`

Enhancement: Add cli switch to search all ALL un-namespaced objects (can be used in addition to the -n switch)

I am working with a controller that manages a CRD which creates a namespace and then creates some additional resources in that namespace. With the current options, I am forced to search all namespaces to get the complete list of resources that this CRD resource owns.

  • A default search doesn't find anything (even though there is one non-namespaced child resource)
$ kubectl tree requests.project.example.com request-test

No resources are owned by this object through ownerReferences.
  • A single namespace search finds some of the resources, but does not list the one non-namespaced child resource.
$ kubectl tree requests.project.example.com request-test -n request-test

NAMESPACE     NAME                              READY  REASON  AGE
              Request/request-test              -              10m
request-test  ├─LimitRange/pod-resource-limits  -              10m
request-test  ├─ResourceQuota/pod-count         -              10m
request-test  └─RoleBinding/admin               -              10m
  • A search of all the namespaces finally finds all of the child resources, but it is overkill for what is actually needed.
$ kubectl tree requests.project.example.com request-test -A

NAMESPACE     NAME                              READY  REASON  AGE
              Request/request-test              -              6m48s
request-test  ├─LimitRange/pod-resource-limits  -              6m48s
              ├─Namespace/request-test          -              6m48s
request-test  ├─ResourceQuota/pod-count         -              6m48s
request-test  └─RoleBinding/admin               -              6m47s

It would be great to add a cli option like -C/--cluster-resources that could be used to specifically request that non-namespaced resources be checked. This should make it possible to find everything, without performing a overly broad search possible, using something like this:

$ kubectl tree requests.project.example.com request-test -n request-test -C

NAMESPACE     NAME                              READY  REASON  AGE
              Request/request-test              -              6m48s
request-test  ├─LimitRange/pod-resource-limits  -              6m48s
              ├─Namespace/request-test          -              6m48s
request-test  ├─ResourceQuota/pod-count         -              6m48s
request-test  └─RoleBinding/admin               -              6m47s

kubectl tree command doesn't work for Statefulsets

My kubectl tree sts node-bsc-03 command returns this:

NAMESPACE       NAME                                         READY  REASON  AGE
aws-blockchain  StatefulSet/node-bsc-03                      -              5d2h
aws-blockchain  ├─ControllerRevision/node-bsc-03-67ccb4f6cb  -              18h
aws-blockchain  ├─ControllerRevision/node-bsc-03-6b894df967  -              5d2h
aws-blockchain  ├─ControllerRevision/node-bsc-03-86f487dbb4  -              5d2h
aws-blockchain  ├─Pod/node-bsc-03-0                          True           5d2h
aws-blockchain  │ └─CiliumEndpoint/node-bsc-03-0             -              5d2h
aws-blockchain  └─Pod/node-bsc-03-1                          True           23m
aws-blockchain    └─CiliumEndpoint/node-bsc-03-1             -              23m

...although I'm pretty sure node-bsc-03-0 and node-bsc-03-1 are not booted from the same ControllerRevision objects.

If I run kubectl get sts node-bsc-03 -oyaml I can see the status:

status:
  availableReplicas: 2
  collisionCount: 0
  currentReplicas: 1
  currentRevision: node-bsc-03-6b894df967
  observedGeneration: 5
  readyReplicas: 2
  replicas: 2
  updateRevision: node-bsc-03-6b894df967
  updatedReplicas: 1

...after which it seems that the whole output of kubectl tree sts command is either wrongly sorted or something else is happening. Any clue?

Long execution time

I tried running kubectl-tree (after modifying the code so that 403 errors are ignored). It took long time for the plugin to print the result.

I0106 13:19:41.260134   50748 query.go:45] all goroutines have returned in 7m53.641176705s

Continued discussion from #14

Fails if privileges are limited

In a production environment, users usually have limited privileges. In this case kubectl tree <kind> <name> fails with

Error: error while querying api objects: listing resources failed (<GVK>): <kind> is forbidden

I would suggest to print a warning for 403s but continue processing otherwise.

EDIT: Just saw there is already #55 for this. Please merge.

Feature Request: List resources in a scope

It will be great if we can list all of the resources in a scope - namespace/cluster without the need of specifying each resource
e.g.
List all of the resources within my-namespace

kubectl tree namespace my-namespace

List all of the resources within my-cluster

kubectl tree cluster my-cluster

The specified cluster name should be similar to the context name.

FYI I don't mind contributing this feature :)

is it feasible for kubectl-tree to produce json output?

Hi! I'm from a visual project called Kui (https://github.com/IBM/kui) that aims at assisting command-line tool with visualization. I found kubectl-tree very useful to, for example, make connection in a soup of my kubernetes resources, and I'm interested in using Kui to add more visual help to kubectl-tree. So I'm wondering if it's feasible for kubect-tree to produce maybe json model that's easier for Kui to consume. Thanks!

add --version option

goreleaser passes gitinfo through version stamps, we should be able to add an
option with this. I'm debating between a 'version' subcommand vs --version.
However, 'version' would be admittedly the only subcommand ever, so that feels
odd.

Support label selectors

The tree command currently requires you to specify a single resource to use as the root. It would be helpful to instead be able to use a label selector (like kubectl get -l) and then build trees from each of the resources that match that selector.

Feature Request: List all containers (if --containers flag given)

It would be great to list all containers for each Pod if --containers flag passed. Couldn't find a similar issue, so dropping this idea.

$ kubectl tree deployment foo

NAMESPACE  NAME                          READY  REASON  AGE
aa         Deployment/foo                -              21h
aa         └─ReplicaSet/foo-6f67dcc579   -              10m
aa           └─Pod/foo-6f67dcc579-znb55  True           10m

But we probably have to include a new column called RUNNING if aforementioned flag passed. (Not so sure about this) Like the following:

$ kubectl tree deployment foo --containers

NAMESPACE  NAME                              READY  RUNNING  REASON  AGE
aa         Deployment/foo                    -      -                21h
aa         └─ReplicaSet/foo-6f67dcc579       -      -                10m
aa           └─Pod/foo-6f67dcc579-znb55      True   -                10m
aa             └─Container/first-container   -      True
aa             └─Container/second-container  -      True

I've tried to pass pods into KIND to check whether it works:

$ kubectl tree pods foo-6f67dcc579-znb55
Error: ambiguous kind "pods". use one of these as the KIND disambiguate: [pods.v1., pods.v1beta1.metrics.k8s.io]

$ kubectl tree pods.v1 foo-6f67dcc579-znb55
Error: could not find api kind "pods.v1"

$ k api-resources | grep "pod"
pods                           po        v1                      true         Pod

But no luck. So decided to file an issue for further discussing. Thoughts?

cc @anilmisirlioglu @Abdulsametileri

Add more examples to readme

First use case that comes to mind is from Agones. Paging @markmandel to kindly provide one. :) If I can get access to cluster I can shoot the screenshot myself too, otherwise (using iterm2 on mac, a window screenshot):

PS1="$(echo;echo)$(tput setaf 3)\$ $(tput sgr0)"

Completed Pods are coloured red

Hi,

when I create a CronJob with the following spec:

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: sleepy
spec:
  schedule: "*/2 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: resting
            image: busybox
            command: ["/bin/sleep"]
            args: ["3"]
          restartPolicy: Never

and when I use kubectl tree after a Job was created and has successful completed the Reason PodCompleted will be coloured red. I assume (without looking in the code) that the Reason is always coloured red if the Pod is not ready? For me red means normally some kind of a failure what about changing the colour of the Reason PodCompleted to green (or something similar)?

 kubectl tree cronjob sleepy
NAMESPACE  NAME                    READY  REASON        AGE
default    CronJob/sleepy          -                    62s
default    └─Job/me-sleep          -                    9s
default      └─Pod/me-sleep-qkhxm  False  PodCompleted  9s

Tree backwards

Hi!

This is a feature request: Obtain the complete tree to which the indicated object belongs.

Thanks!

Manual Install for WSL

I did manual install for the krew and it seemed to work but again when installing this plugin I hit the same issue with path and permission denied.
How can I compile/install this bin in my WSL?

Updated the local copy of plugin index. Installing plugin: tree W0506 11:06:06.719951 6465 install.go:138] failed to install plugin "tree": install failed: failed while moving files to the installation directory: could not rename/copy directory "/tmp/krew-temp-move234479147" to "/home/user_name/.krew/store/tree/v0.4.0": rename /tmp/krew-temp-move234479147 /home/user_name/.krew/store/tree/v0.4.0: permission denied F0506 11:06:06.735376 6465 root.go:77] failed to install some plugins: [tree]: install failed: failed while moving files to the installation directory: could not rename/copy directory "/tmp/krew-temp-move234479147" to "/home/user_name/.krew/store/tree/v0.4.0": rename /tmp/krew-temp-move234479147 /home/user_name/.krew/store/tree/v0.4.0: permission denied

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.