Open spkane opened 3 years ago
thanks for the proposal. out of curiosity: are there examples of this from other CLI tools for Kubernetes?
I agree with the idea of this, but want to be consistent in terms of naming of this option for the sake of consistency.
Hello @ahmetb! Seems like this flag -A
is not working as expected, I'm afraid.
I had a fresh KinD installation for testing purposes. It contains only a few deployments, please note the flag -A
:
kubectl get deploy -A
NAMESPACE NAME READY UP-TO-DATE AVAILABLE AGE
kube-system coredns 2/2 2 2 82m
local-path-storage local-path-provisioner 1/1 1 1 82m
This plugin correctly shows tree-like structure when namespace is mentioned explicitly.
kubectl tree deploy coredns -n kube-system
NAMESPACE NAME READY REASON AGE
kube-system Deployment/coredns - 84m
kube-system └─ReplicaSet/coredns-565d847f94 - 84m
kube-system ├─Pod/coredns-565d847f94-66mtj True 84m
kube-system └─Pod/coredns-565d847f94-bgqxs True 84m
Unfortunately this doesn't happen with -A
:
kubectl tree deploy coredns -A
Error: failed to get deploy/coredns: deployments.apps "coredns" not found
Based on on the --help
I recon -A
is to be supported already, isn't?
kubectl tree --help
Show sub-resources of the Kubernetes object
Usage:
kubectl tree KIND NAME [flags]
Examples:
kubectl tree deployment my-app
kubectl tree kservice.v1.serving.knative.dev my-app
Flags:
-A, --all-namespaces query all objects in all API groups, both namespaced and non-namespaced
@HectorB-2020 whats the output for
kubectl get deploy coredns -A
Well, this is interesting: :+1:
kubectl get deploy coredns -A
error: a resource cannot be retrieved by name across all namespaces
In fact this combination is never used with exact name. Usually generic results are filtered with parameters like --selector
or passed through grep
, you know.
On the other hand plain kubectl tree
is not accepted without name.
kubectl tree deploy -A
Error: specify the kubernetes object in KIND NAME or KIND/NAME form
Is there a scenario when -A
should work?
This plugin currently takes a single object and constructs the object hierarchy from there. So if multiple objects with the same KIND/NAME are found while searching all namespaces, we either error out (and force user to qualify by namespace) or pick a namespace for the user (I like to avoid "magic").
Or we can change the tool to print the tree for multiple root objects across different namespaces. Which might be ok.
In this case, we overloaded -A/--all-namespaces
flag to mean "cluster-scoped objects". In hindsight, another flag name could've been better.
Thanks @ahmetb! It's clear now. :100: :+1:
thanks for the proposal. out of curiosity: are there examples of this from other CLI tools for Kubernetes?
I agree with the idea of this, but want to be consistent in terms of naming of this option for the sake of consistency.
I am not aware of equivalent functionality in something like kubectl
. I could imagine this either being a switch or simply being that standard behavior (show all resources in the namespace, plus all related cluster-wide resources).
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.
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: