@@ -28,12 +28,13 @@ var cf *genericclioptions.ConfigFlags
28
28
29
29
// rootCmd represents the base command when called without any subcommands
30
30
var rootCmd = & cobra.Command {
31
- Use : "kubectl tree" ,
32
- Short : "Show sub-resources of the Kubernetes object" ,
31
+ Use : "kubectl tree" ,
32
+ SilenceUsage : true , // for when RunE returns an error
33
+ Short : "Show sub-resources of the Kubernetes object" ,
33
34
Example : " kubectl tree deployment my-app\n " +
34
35
" kubectl tree kservice.v1.serving.knative.dev my-app" , // TODO add more examples about disambiguation etc
35
- Args : cobra .MinimumNArgs (2 ),
36
- RunE : run ,
36
+ Args : cobra .MinimumNArgs (2 ),
37
+ RunE : run ,
37
38
}
38
39
39
40
func run (cmd * cobra.Command , args []string ) error {
@@ -69,9 +70,13 @@ func run(cmd *cobra.Command, args []string) error {
69
70
strings .Join (names , ", " ))
70
71
}
71
72
72
- obj , err := dyn .Resource (apiRes [0 ].GroupVersionResource ()).Namespace (* cf .Namespace ).Get (name , metav1.GetOptions {})
73
+ ns := * cf .Namespace
74
+ if ns == "" {
75
+ ns = "default" // TODO(ahmetb): how to get current-namespace from kubeconfig?
76
+ }
77
+ obj , err := dyn .Resource (apiRes [0 ].GroupVersionResource ()).Namespace (ns ).Get (name , metav1.GetOptions {})
73
78
if err != nil {
74
- return fmt .Errorf ("failed to get: %w" , err )
79
+ return fmt .Errorf ("failed to get %s/%s : %w" , kind , name , err )
75
80
}
76
81
77
82
apiObjects , err := getAllResources (dyn , apis .resources ())
0 commit comments