Skip to content

Commit

Permalink
feat: Display namespace column only if objects are in different names…
Browse files Browse the repository at this point in the history
…paces

Signed-off-by: Justin Toh <[email protected]>
  • Loading branch information
tohjustin committed Sep 11, 2021
1 parent deb73bd commit 5e49663
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
27 changes: 20 additions & 7 deletions pkg/cmd/lineage/lineage.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,30 +321,43 @@ func (o *CmdOptions) getObjectsByResource(api Resource) ([]unstructuredv1.Unstru
return result, nil
}

func (o *CmdOptions) print(nodeMap NodeMap, uid types.UID) error {
func (o *CmdOptions) print(nodeMap NodeMap, rootUID types.UID) error {
// TODO: Auto-show group if all objects contains different resources with the same kind
// Setup Table Printer
withGroup := false
if o.PrintFlags.HumanReadableFlags.ShowGroup != nil {
withGroup = *o.PrintFlags.HumanReadableFlags.ShowGroup
}
// TODO: Auto-hide namespace column if all objects are in the same namespace
withNamespace := true
// Display namespace column only if objects are in different namespaces
withNamespace := false
if o.ResourceScope != meta.RESTScopeNameNamespace {
rootNs := nodeMap[rootUID].GetNamespace()
for _, node := range nodeMap {
if rootNs != node.GetNamespace() {
withNamespace = true
break
}
}
}
printer, err := o.ToPrinter(withGroup, withNamespace)
if err != nil {
return err
}

// TODO: Sort dependents before printing
rows, err := printNodeMap(nodeMap, uid, "", withGroup)
// Generate Table Rows for printing
rows, err := printNodeMap(nodeMap, rootUID, "", withGroup)
if err != nil {
return err
}

table := &metav1.Table{
ColumnDefinitions: objectColumnDefinitions,
Rows: rows,
}
return printer.PrintObj(table, o.Out)
if err = printer.PrintObj(table, o.Out); err != nil {
return err
}

return nil
}

func resourceFor(mapper meta.RESTMapper, resourceArg string) (schema.GroupVersionResource, error) {
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/lineage/table_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type objectColumns struct {
Age string
}

// TODO: Sort dependents before printing
// TODO: Refactor this to remove duplication
func printNodeMap(nodeMap NodeMap, uid types.UID, prefix string, showGroup bool) ([]metav1.TableRow, error) {
var rows []metav1.TableRow
Expand Down

0 comments on commit 5e49663

Please sign in to comment.