fix disable addon check several bugs (#3488)

Signed-off-by: 楚岳 <wangyike.wyk@alibaba-inc.com>
This commit is contained in:
wyike
2022-03-22 10:06:16 +08:00
committed by GitHub
parent 9a8ec5d797
commit 345e4c8144
3 changed files with 5 additions and 4 deletions
+3 -3
View File
@@ -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
}
+1 -1
View File
@@ -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 (
+1
View File
@@ -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