Commit b040513a authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #43067 from xilabao/dedup-in-printer

Automatic merge from submit-queue De-duplication in printer
parents 35837d80 697efd1b
...@@ -300,7 +300,7 @@ func printUnstructured(unstructured runtime.Unstructured, w io.Writer, additiona ...@@ -300,7 +300,7 @@ func printUnstructured(unstructured runtime.Unstructured, w io.Writer, additiona
} }
} }
name := formatResourceName(options.Kind, metadata.GetName(), options.WithKind) name := FormatResourceName(options.Kind, metadata.GetName(), options.WithKind)
if _, err := fmt.Fprintf(w, "%s\t%s", name, kind); err != nil { if _, err := fmt.Fprintf(w, "%s\t%s", name, kind); err != nil {
return err return err
...@@ -319,10 +319,10 @@ func printUnstructured(unstructured runtime.Unstructured, w io.Writer, additiona ...@@ -319,10 +319,10 @@ func printUnstructured(unstructured runtime.Unstructured, w io.Writer, additiona
} }
} }
} }
if _, err := fmt.Fprint(w, appendLabels(metadata.GetLabels(), options.ColumnLabels)); err != nil { if _, err := fmt.Fprint(w, AppendLabels(metadata.GetLabels(), options.ColumnLabels)); err != nil {
return err return err
} }
if _, err := fmt.Fprint(w, appendAllLabels(options.ShowLabels, metadata.GetLabels())); err != nil { if _, err := fmt.Fprint(w, AppendAllLabels(options.ShowLabels, metadata.GetLabels())); err != nil {
return err return err
} }
...@@ -349,10 +349,9 @@ func formatShowLabelsHeader(showLabels bool, t reflect.Type) []string { ...@@ -349,10 +349,9 @@ func formatShowLabelsHeader(showLabels bool, t reflect.Type) []string {
return nil return nil
} }
// formatResourceName receives a resource kind, name, and boolean specifying // FormatResourceName receives a resource kind, name, and boolean specifying
// whether or not to update the current name to "kind/name" // whether or not to update the current name to "kind/name"
// TODO: dedup this with printers/internalversions func FormatResourceName(kind, name string, withKind bool) string {
func formatResourceName(kind, name string, withKind bool) string {
if !withKind || kind == "" { if !withKind || kind == "" {
return name return name
} }
...@@ -360,8 +359,7 @@ func formatResourceName(kind, name string, withKind bool) string { ...@@ -360,8 +359,7 @@ func formatResourceName(kind, name string, withKind bool) string {
return kind + "/" + name return kind + "/" + name
} }
// TODO: dedup this with printers/internalversions func AppendLabels(itemLabels map[string]string, columnLabels []string) string {
func appendLabels(itemLabels map[string]string, columnLabels []string) string {
var buffer bytes.Buffer var buffer bytes.Buffer
for _, cl := range columnLabels { for _, cl := range columnLabels {
...@@ -378,8 +376,7 @@ func appendLabels(itemLabels map[string]string, columnLabels []string) string { ...@@ -378,8 +376,7 @@ func appendLabels(itemLabels map[string]string, columnLabels []string) string {
// Append all labels to a single column. We need this even when show-labels flag* is // Append all labels to a single column. We need this even when show-labels flag* is
// false, since this adds newline delimiter to the end of each row. // false, since this adds newline delimiter to the end of each row.
// TODO: dedup this with printers/internalversions func AppendAllLabels(showLabels bool, itemLabels map[string]string) string {
func appendAllLabels(showLabels bool, itemLabels map[string]string) string {
var buffer bytes.Buffer var buffer bytes.Buffer
if showLabels { if showLabels {
......
...@@ -236,7 +236,7 @@ func TestFormatResourceName(t *testing.T) { ...@@ -236,7 +236,7 @@ func TestFormatResourceName(t *testing.T) {
{"kind", "name", "kind/name"}, {"kind", "name", "kind/name"},
} }
for _, tt := range tests { for _, tt := range tests {
if got := formatResourceName(tt.kind, tt.name, true); got != tt.want { if got := printers.FormatResourceName(tt.kind, tt.name, true); got != tt.want {
t.Errorf("formatResourceName(%q, %q) = %q, want %q", tt.kind, tt.name, got, tt.want) t.Errorf("formatResourceName(%q, %q) = %q, want %q", tt.kind, tt.name, got, tt.want)
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment