From fb23e0ebd28a3f40ff1a1a9beab9d15242d160be Mon Sep 17 00:00:00 2001 From: wangyuan249 <35907099+wangyuan249@users.noreply.github.com> Date: Wed, 2 Jun 2021 17:27:28 +0800 Subject: [PATCH] fix show annotations (#1711) * fix show annotations * only fix map value --- e2e/plugin/plugin_test.go | 6 ++++++ references/plugins/references.go | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/e2e/plugin/plugin_test.go b/e2e/plugin/plugin_test.go index 5a3e5d5c0..1c9892bee 100644 --- a/e2e/plugin/plugin_test.go +++ b/e2e/plugin/plugin_test.go @@ -140,6 +140,12 @@ var _ = Describe("Test Kubectl Plugin", func() { Expect(output).Should(ContainSubstring("targetPort")) Expect(output).Should(ContainSubstring("target port num for service provider.")) }) + It("Test show traitDefinition def with cue single map parameter", func() { + tdName := "annotations" + output, err := e2e.Exec(fmt.Sprintf("kubectl-vela show %s", tdName)) + Expect(err).NotTo(HaveOccurred()) + Expect(output).Should(ContainSubstring("map[string]string")) + }) }) Context("Test kubectl vela comp discover", func() { diff --git a/references/plugins/references.go b/references/plugins/references.go index 163b36aa0..b452d8b75 100644 --- a/references/plugins/references.go +++ b/references/plugins/references.go @@ -536,6 +536,17 @@ func (ref *ParseReference) parseParameters(paraValue cue.Value, paramKey string, if err != nil { return fmt.Errorf("arguments not defined as struct %w", err) } + if arguments.Len() == 0 { + var param ReferenceParameter + param.Name = "undefined" + param.Required = true + tl := paraValue.Template() + if tl != nil { // is map type + param.PrintableType = fmt.Sprintf("map[string]%s", tl("").IncompleteKind().String()) + } + params = append(params, param) + } + for i := 0; i < arguments.Len(); i++ { var param ReferenceParameter fi := arguments.Field(i)