From 345e4c8144642128a4874d4ee2ac4563a9d3fd33 Mon Sep 17 00:00:00 2001 From: wyike Date: Tue, 22 Mar 2022 10:06:16 +0800 Subject: [PATCH] fix disable addon check several bugs (#3488) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 楚岳 --- pkg/addon/utils.go | 6 +++--- pkg/addon/utils_test.go | 2 +- pkg/apiserver/rest/webservice/addon.go | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/addon/utils.go b/pkg/addon/utils.go index 04c42fadb..9e0dafdd1 100644 --- a/pkg/addon/utils.go +++ b/pkg/addon/utils.go @@ -197,15 +197,15 @@ func findLegacyAddonDefs(ctx context.Context, k8sClient client.Client, addonName } func usingAppsInfo(apps []v1beta1.Application) string { - res := "application: " + res := "addon is being used :" appsNamespaceNameList := map[string][]string{} for _, app := range apps { appsNamespaceNameList[app.GetNamespace()] = append(appsNamespaceNameList[app.GetNamespace()], app.GetName()) } for namespace, appNames := range appsNamespaceNameList { nameStr := strings.Join(appNames, ",") - res += fmt.Sprintf("(%s) in namespace:%s,", nameStr, namespace) + res += fmt.Sprintf("{%s} in namespace:%s,", nameStr, namespace) } - res = strings.TrimSuffix(res, ",") + " are still using this addon" + res = strings.TrimSuffix(res, ",") + ".Please delete them before disabling the addon." return res } diff --git a/pkg/addon/utils_test.go b/pkg/addon/utils_test.go index 17f85a89d..d591e17ea 100644 --- a/pkg/addon/utils_test.go +++ b/pkg/addon/utils_test.go @@ -144,7 +144,7 @@ func TestUsingAddonInfo(t *testing.T) { v1beta1.Application{ObjectMeta: metav1.ObjectMeta{Namespace: "namespace-1", Name: "app-3"}}, } res := usingAppsInfo(apps) - assert.Equal(t, true, strings.Contains(res, "still using this addon")) + assert.Equal(t, true, strings.Contains(res, "Please delete them before disabling the addon")) } const ( diff --git a/pkg/apiserver/rest/webservice/addon.go b/pkg/apiserver/rest/webservice/addon.go index 0a05c1e74..c4e5115cf 100644 --- a/pkg/apiserver/rest/webservice/addon.go +++ b/pkg/apiserver/rest/webservice/addon.go @@ -101,6 +101,7 @@ func (s *addonWebService) GetWebService() *restful.WebService { Returns(200, "OK", apis.AddonStatusResponse{}). Returns(400, "Bad Request", bcode.Bcode{}). Param(ws.PathParameter("name", "addon name to enable").DataType("string").Required(true)). + Param(ws.QueryParameter("force", "force disable an anddon").DataType("bool").Required(false)). Writes(apis.AddonStatusResponse{})) // update addon