Skip to content

Commit 9954230

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

File tree

6 files changed

+34
-4
lines changed

6 files changed

+34
-4
lines changed

README.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,37 @@
33
A kubectl plugin to explore ownership relationships between Kubernetes objects
44
through ownersReferences on them.
55

6+
## Installation
7+
8+
> **NOTE:** This is still not working as I'm packaging it for Krew.
9+
10+
Use [krew](https://sigs.k8s.io/krew) plugin manager to install
11+
12+
kubectl krew install tree
13+
kubectl tree --help
14+
15+
## Demo
16+
17+
Example (Deployment):
18+
19+
![example Kubernetes deployment object hierarchy](assets/example-1.png)
20+
21+
Example (Knative Service):
22+
23+
![example Kubernetes deployment object hierarchy](assets/example-2.png)
24+
625
## Author
726

8-
Ahmet Alp Balkan [@ahmetb](https://twitter.com/ahmetb). Inpired by
9-
@nimakaviani's knative-inspect tool.
27+
Ahmet Alp Balkan [@ahmetb](https://twitter.com/ahmetb).
28+
29+
**Special acknowledgement:** This tool is heavily inspired by @nimakaviani's
30+
[knative-inspect](https://github.com/nimakaviani/knative-inspect/) as it's a
31+
generalized version of it.
1032

1133
## License
1234

1335
Apache 2.0. See [LICENSE](./LICENSE).
1436

37+
---
38+
39+
This is not an official Google project.

assets/example-1.png

443 KB
Loading

assets/example-2.png

1.13 MB
Loading

cmd/kubectl-tree/apis.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ func contains(v []string, s string) bool {
8585
func apiNames(a metav1.APIResource, gv schema.GroupVersion) []string {
8686
var out []string
8787
singularName := a.SingularName
88+
if singularName == "" {
89+
// TODO(ahmetb): sometimes SingularName is empty (e.g. Deployment), use lowercase Kind as fallback - investigate why
90+
singularName = strings.ToLower(a.Kind)
91+
}
8892
pluralName := a.Name
8993
shortNames := a.ShortNames
9094
names := append([]string{singularName, pluralName}, shortNames...)

cmd/kubectl-tree/rootcmd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ 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",
31+
Use: "kubectl tree KIND NAME",
3232
SilenceUsage: true, // for when RunE returns an error
3333
Short: "Show sub-resources of the Kubernetes object",
3434
Example: " kubectl tree deployment my-app\n" +
@@ -66,7 +66,7 @@ func run(cmd *cobra.Command, args []string) error {
6666
for _, a := range apiRes {
6767
names = append(names, fullAPIName(a))
6868
}
69-
return fmt.Errorf("ambiguous kind %q. use one of these to disambiguate: [%s]", kind,
69+
return fmt.Errorf("ambiguous kind %q. use one of these as the KIND disambiguate: [%s]", kind,
7070
strings.Join(names, ", "))
7171
}
7272

cmd/kubectl-tree/tree.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var (
2525
// treeView prints object hierarchy to out stream.
2626
func treeView(out io.Writer, objs objectDirectory, obj unstructured.Unstructured) {
2727
tbl := uitable.New()
28+
tbl.Separator = " "
2829
tbl.AddRow("NAMESPACE", "NAME", "READY", "REASON")
2930
treeViewInner("", tbl, objs, obj)
3031
fmt.Fprintln(out, tbl)

0 commit comments

Comments
 (0)