Skip to content

Commit c734b8a

Browse files
committed
updates
Signed-off-by: Ahmet Alp Balkan <[email protected]>
1 parent 0484630 commit c734b8a

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

cmd/kubectl-tree/rootcmd.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ var cf *genericclioptions.ConfigFlags
2828

2929
// rootCmd represents the base command when called without any subcommands
3030
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",
3334
Example: " kubectl tree deployment my-app\n" +
3435
" 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,
3738
}
3839

3940
func run(cmd *cobra.Command, args []string) error {
@@ -69,9 +70,13 @@ func run(cmd *cobra.Command, args []string) error {
6970
strings.Join(names, ", "))
7071
}
7172

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{})
7378
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)
7580
}
7681

7782
apiObjects, err := getAllResources(dyn, apis.resources())

cmd/kubectl-tree/tree.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func treeViewInner(prefix string, tbl *uitable.Table, objs objectDirectory, obj
4848

4949
tbl.AddRow(obj.GetNamespace(), fmt.Sprintf("%s%s/%s",
5050
gray.Sprint(printPrefix(prefix)),
51-
gray.Sprint(obj.GetKind()),
51+
obj.GetKind(),
5252
color.New(color.Bold).Sprint(obj.GetName())),
5353
readyColor.Sprint(ready),
5454
readyColor.Sprint(reason))
@@ -66,6 +66,7 @@ func treeViewInner(prefix string, tbl *uitable.Table, objs objectDirectory, obj
6666
}
6767

6868
func printPrefix(p string) string {
69+
// this part is hacky af
6970
if strings.HasSuffix(p, firstElemPrefix) {
7071
p = strings.Replace(p, firstElemPrefix, pipe, strings.Count(p, firstElemPrefix)-1)
7172
} else {

0 commit comments

Comments
 (0)