mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 12:15:52 +00:00
Skip smart label in kubectl describe if field has special chars
Attempts to create smart label for fields containing special chanracter ends up looking very odd. This change skips creating smart labels for fields containing special characters other than '-'.
This commit is contained in:
parent
1d441c1f93
commit
029582d339
@ -29,6 +29,7 @@ import (
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
"time"
|
||||
"unicode"
|
||||
|
||||
"github.com/fatih/camelcase"
|
||||
|
||||
@ -302,8 +303,15 @@ func printUnstructuredContent(w PrefixWriter, level int, content map[string]inte
|
||||
}
|
||||
|
||||
func smartLabelFor(field string) string {
|
||||
commonAcronyms := []string{"API", "URL", "UID", "OSB", "GUID"}
|
||||
// skip creating smart label if field name contains
|
||||
// special characters other than '-'
|
||||
if strings.IndexFunc(field, func(r rune) bool {
|
||||
return !unicode.IsLetter(r) && r != '-'
|
||||
}) != -1 {
|
||||
return field
|
||||
}
|
||||
|
||||
commonAcronyms := []string{"API", "URL", "UID", "OSB", "GUID"}
|
||||
parts := camelcase.Split(field)
|
||||
result := make([]string, 0, len(parts))
|
||||
for _, part := range parts {
|
||||
|
@ -2499,7 +2499,11 @@ func TestDescribeUnstructuredContent(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
expected: `API Version: v1
|
||||
Dummy 2: present
|
||||
Dummy - Dummy: present
|
||||
dummy-dummy@dummy: present
|
||||
dummy/dummy: present
|
||||
dummy2: present
|
||||
Dummy Dummy: present
|
||||
Items:
|
||||
Item Bool: true
|
||||
Item Int: 42
|
||||
@ -2537,10 +2541,14 @@ URL: http://localhost
|
||||
w := NewPrefixWriter(out)
|
||||
obj := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"apiVersion": "v1",
|
||||
"kind": "Test",
|
||||
"dummy1": "present",
|
||||
"dummy2": "present",
|
||||
"apiVersion": "v1",
|
||||
"kind": "Test",
|
||||
"dummyDummy": "present",
|
||||
"dummy/dummy": "present",
|
||||
"dummy-dummy@dummy": "present",
|
||||
"dummy-dummy": "present",
|
||||
"dummy1": "present",
|
||||
"dummy2": "present",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "MyName",
|
||||
"namespace": "MyNamespace",
|
||||
|
Loading…
Reference in New Issue
Block a user