mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Merge pull request #75483 from gsadhani/describe-output-fix
Skip smart label in kubectl describe if field has special chars
This commit is contained in:
commit
483cd0db09
@ -29,6 +29,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
"time"
|
"time"
|
||||||
|
"unicode"
|
||||||
|
|
||||||
"github.com/fatih/camelcase"
|
"github.com/fatih/camelcase"
|
||||||
|
|
||||||
@ -303,8 +304,15 @@ func printUnstructuredContent(w PrefixWriter, level int, content map[string]inte
|
|||||||
}
|
}
|
||||||
|
|
||||||
func smartLabelFor(field string) string {
|
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)
|
parts := camelcase.Split(field)
|
||||||
result := make([]string, 0, len(parts))
|
result := make([]string, 0, len(parts))
|
||||||
for _, part := range parts {
|
for _, part := range parts {
|
||||||
|
@ -2595,7 +2595,11 @@ func TestDescribeUnstructuredContent(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
expected: `API Version: v1
|
expected: `API Version: v1
|
||||||
Dummy 2: present
|
Dummy - Dummy: present
|
||||||
|
dummy-dummy@dummy: present
|
||||||
|
dummy/dummy: present
|
||||||
|
dummy2: present
|
||||||
|
Dummy Dummy: present
|
||||||
Items:
|
Items:
|
||||||
Item Bool: true
|
Item Bool: true
|
||||||
Item Int: 42
|
Item Int: 42
|
||||||
@ -2633,10 +2637,14 @@ URL: http://localhost
|
|||||||
w := NewPrefixWriter(out)
|
w := NewPrefixWriter(out)
|
||||||
obj := &unstructured.Unstructured{
|
obj := &unstructured.Unstructured{
|
||||||
Object: map[string]interface{}{
|
Object: map[string]interface{}{
|
||||||
"apiVersion": "v1",
|
"apiVersion": "v1",
|
||||||
"kind": "Test",
|
"kind": "Test",
|
||||||
"dummy1": "present",
|
"dummyDummy": "present",
|
||||||
"dummy2": "present",
|
"dummy/dummy": "present",
|
||||||
|
"dummy-dummy@dummy": "present",
|
||||||
|
"dummy-dummy": "present",
|
||||||
|
"dummy1": "present",
|
||||||
|
"dummy2": "present",
|
||||||
"metadata": map[string]interface{}{
|
"metadata": map[string]interface{}{
|
||||||
"name": "MyName",
|
"name": "MyName",
|
||||||
"namespace": "MyNamespace",
|
"namespace": "MyNamespace",
|
||||||
|
Loading…
Reference in New Issue
Block a user