From 14770dff0d628cc94b323874ed643366af7ea48f Mon Sep 17 00:00:00 2001 From: Zheng Xi Zhou Date: Wed, 24 Nov 2021 19:52:59 +0800 Subject: [PATCH] Fix: arguments map[string]string doesn't support observability's args (#2790) * Fix: arguments map[string]string doesn't support observability's args As there are bool typed arguments, the current arguments type doesn't support. --- pkg/addon/addon.go | 21 ++++++++++++++------- pkg/apiserver/rest/apis/v1/types.go | 2 +- test/e2e-apiserver-test/addon_test.go | 2 +- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/pkg/addon/addon.go b/pkg/addon/addon.go index 0157cba8d..b436b63a7 100644 --- a/pkg/addon/addon.go +++ b/pkg/addon/addon.go @@ -23,6 +23,7 @@ import ( "net/url" "path" "path/filepath" + "strconv" "strings" "sync" "time" @@ -457,10 +458,7 @@ func cutPathUntil(path []string, end string) ([]string, error) { } // RenderApplication render a K8s application -func RenderApplication(addon *types.Addon, args map[string]string) (*v1beta1.Application, []*unstructured.Unstructured, error) { - if args == nil { - args = map[string]string{} - } +func RenderApplication(addon *types.Addon, args map[string]interface{}) (*v1beta1.Application, []*unstructured.Unstructured, error) { app := addon.AppTemplate if app == nil { app = &v1beta1.Application{ @@ -582,7 +580,7 @@ func renderRawComponent(elem types.AddonElementFile) (*common2.ApplicationCompon } // renderCUETemplate will return a component from cue template -func renderCUETemplate(elem types.AddonElementFile, parameters string, args map[string]string) (*common2.ApplicationComponent, error) { +func renderCUETemplate(elem types.AddonElementFile, parameters string, args map[string]interface{}) (*common2.ApplicationComponent, error) { bt, err := json.Marshal(args) if err != nil { return nil, err @@ -633,14 +631,23 @@ func Convert2AddonName(name string) string { } // RenderArgsSecret TODO add desc -func RenderArgsSecret(addon *types.Addon, args map[string]string) *v1.Secret { +func RenderArgsSecret(addon *types.Addon, args map[string]interface{}) *v1.Secret { + data := make(map[string]string) + for k, v := range args { + switch v := v.(type) { + case bool: + data[k] = strconv.FormatBool(v) + default: + data[k] = fmt.Sprintf("%v", v) + } + } sec := v1.Secret{ TypeMeta: metav1.TypeMeta{APIVersion: "v1", Kind: "Secret"}, ObjectMeta: metav1.ObjectMeta{ Name: Convert2SecName(addon.Name), Namespace: types.DefaultKubeVelaNS, }, - StringData: args, + StringData: data, Type: v1.SecretTypeOpaque, } return &sec diff --git a/pkg/apiserver/rest/apis/v1/types.go b/pkg/apiserver/rest/apis/v1/types.go index 1d2ce9418..e18fde1de 100644 --- a/pkg/apiserver/rest/apis/v1/types.go +++ b/pkg/apiserver/rest/apis/v1/types.go @@ -83,7 +83,7 @@ type ListAddonRegistryResponse struct { // EnableAddonRequest defines the format for enable addon request type EnableAddonRequest struct { // Args is the key-value environment variables, e.g. AK/SK credentials. - Args map[string]string `json:"args,omitempty"` + Args map[string]interface{} `json:"args,omitempty"` } // ListAddonResponse defines the format for addon list response diff --git a/test/e2e-apiserver-test/addon_test.go b/test/e2e-apiserver-test/addon_test.go index eb0134183..612347ae5 100644 --- a/test/e2e-apiserver-test/addon_test.go +++ b/test/e2e-apiserver-test/addon_test.go @@ -91,7 +91,7 @@ var _ = Describe("Test addon rest api", func() { PIt("should enable and disable an addon", func() { defer GinkgoRecover() req := apis.EnableAddonRequest{ - Args: map[string]string{ + Args: map[string]interface{}{ "example": "test-args", }, }