From bcf9fa361b12899652028cec63931fb0484caf53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charles-Edouard=20Br=C3=A9t=C3=A9ch=C3=A9?= Date: Thu, 14 Sep 2023 23:02:44 +0200 Subject: [PATCH] fix: names not formatted correctly in cli output (#8411) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Charles-Edouard Brétéché --- cmd/cli/kubectl-kyverno/output/color/color.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cmd/cli/kubectl-kyverno/output/color/color.go b/cmd/cli/kubectl-kyverno/output/color/color.go index e3e4f756c0..437419726a 100644 --- a/cmd/cli/kubectl-kyverno/output/color/color.go +++ b/cmd/cli/kubectl-kyverno/output/color/color.go @@ -1,6 +1,8 @@ package color import ( + "strings" + "github.com/fatih/color" "github.com/kataras/tablewriter" ) @@ -32,6 +34,13 @@ func InitColors(noColor bool) { } func Policy(namespace, name string) string { + if strings.Contains(name, "/") { + parts := strings.Split(name, "/") + if len(parts) >= 2 { + namespace = parts[0] + name = parts[1] + } + } if namespace == "" { return BoldFgCyan.Sprint(name) } @@ -43,6 +52,13 @@ func Rule(name string) string { } func Resource(kind, namespace, name string) string { + if strings.Contains(name, "/") { + parts := strings.Split(name, "/") + if len(parts) >= 2 { + namespace = parts[0] + name = parts[1] + } + } if namespace == "" { return BoldFgCyan.Sprint(kind) + "/" + BoldFgCyan.Sprint(name) }