github.com/oam-dev/kubevela@v1.9.11/e2e/addon/addon_test.go (about) 1 /* 2 Copyright 2021 The KubeVela Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package e2e 18 19 import ( 20 "context" 21 "encoding/json" 22 "fmt" 23 "strings" 24 "time" 25 26 "github.com/Netflix/go-expect" 27 . "github.com/onsi/ginkgo/v2" 28 . "github.com/onsi/gomega" 29 v1 "k8s.io/api/core/v1" 30 apierrors "k8s.io/apimachinery/pkg/api/errors" 31 "k8s.io/apimachinery/pkg/types" 32 33 "github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1" 34 "github.com/oam-dev/kubevela/e2e" 35 "github.com/oam-dev/kubevela/pkg/addon" 36 addonutil "github.com/oam-dev/kubevela/pkg/utils/addon" 37 "github.com/oam-dev/kubevela/pkg/utils/common" 38 ) 39 40 var _ = Describe("Addon Test", func() { 41 args := common.Args{Schema: common.Scheme} 42 k8sClient, err := args.GetClient() 43 Expect(err).Should(BeNil()) 44 45 Context("List addons", func() { 46 It("List all addon", func() { 47 output, err := e2e.Exec("vela addon list") 48 Expect(err).NotTo(HaveOccurred()) 49 Expect(output).To(ContainSubstring("test-addon")) 50 }) 51 52 It("Enable addon test-addon", func() { 53 output, err := e2e.Exec("vela addon enable test-addon") 54 Expect(err).NotTo(HaveOccurred()) 55 Expect(output).To(ContainSubstring("enabled successfully.")) 56 }) 57 58 It("Upgrade addon test-addon", func() { 59 output, err := e2e.Exec("vela addon upgrade test-addon") 60 Expect(err).NotTo(HaveOccurred()) 61 Expect(output).To(ContainSubstring("enabled successfully.")) 62 }) 63 64 It("Disable addon test-addon", func() { 65 output, err := e2e.LongTimeExec("vela addon disable test-addon", 600*time.Second) 66 Expect(err).NotTo(HaveOccurred()) 67 Expect(output).To(ContainSubstring("Successfully disable addon")) 68 Eventually(func(g Gomega) { 69 g.Expect(apierrors.IsNotFound(k8sClient.Get(context.Background(), types.NamespacedName{Name: "addon-test-addon", Namespace: "vela-system"}, &v1beta1.Application{}))).Should(BeTrue()) 70 g.Expect(apierrors.IsNotFound(k8sClient.Get(context.Background(), types.NamespacedName{Name: "addon-secret-test-addon", Namespace: "vela-system"}, &v1.Secret{}))).Should(BeTrue()) 71 }, 60*time.Second).Should(Succeed()) 72 }) 73 74 It("Enable addon with input", func() { 75 output, err := e2e.LongTimeExec("vela addon enable test-addon example=redis", 300*time.Second) 76 Expect(err).NotTo(HaveOccurred()) 77 Expect(output).To(ContainSubstring("enabled successfully.")) 78 }) 79 80 It("Enable addon with specified registry ", func() { 81 output, err := e2e.LongTimeExec("vela addon enable KubeVela/test-addon", 300*time.Second) 82 Expect(err).NotTo(HaveOccurred()) 83 Expect(output).To(ContainSubstring("enabled successfully.")) 84 }) 85 86 It("Disable addon test-addon", func() { 87 output, err := e2e.LongTimeExec("vela addon disable test-addon", 600*time.Second) 88 Expect(err).NotTo(HaveOccurred()) 89 Expect(output).To(ContainSubstring("Successfully disable addon")) 90 Eventually(func(g Gomega) { 91 g.Expect(apierrors.IsNotFound(k8sClient.Get(context.Background(), types.NamespacedName{Name: "addon-test-addon", Namespace: "vela-system"}, &v1beta1.Application{}))).Should(BeTrue()) 92 }, 60*time.Second).Should(Succeed()) 93 }) 94 95 It("Enable local addon with . as path", func() { 96 output, err := e2e.LongTimeExec("vela addon enable ../../e2e/addon/mock/testdata/sample/.", 600*time.Second) 97 Expect(err).NotTo(HaveOccurred()) 98 Expect(output).To(ContainSubstring("sample enabled successfully.")) 99 }) 100 101 It("Test Change default namespace can work", func() { 102 output, err := e2e.LongTimeExecWithEnv("vela addon list", 600*time.Second, []string{"DEFAULT_VELA_NS=test-vela"}) 103 Expect(err).NotTo(HaveOccurred()) 104 Expect(output).To(ContainSubstring("test-addon")) 105 Expect(output).To(ContainSubstring("-")) 106 107 output, err = e2e.LongTimeExecWithEnv("vela addon enable test-addon", 600*time.Second, []string{"DEFAULT_VELA_NS=test-vela"}) 108 Expect(err).NotTo(HaveOccurred()) 109 Expect(output).To(ContainSubstring("enabled successfully.")) 110 111 Eventually(func(g Gomega) { 112 g.Expect(k8sClient.Get(context.Background(), types.NamespacedName{Name: "addon-test-addon", Namespace: "test-vela"}, &v1beta1.Application{})).Should(BeNil()) 113 }, 60*time.Second).Should(Succeed()) 114 115 output, err = e2e.LongTimeExecWithEnv("vela addon disable test-addon", 600*time.Second, []string{"DEFAULT_VELA_NS=test-vela"}) 116 Expect(err).NotTo(HaveOccurred()) 117 Expect(output).To(ContainSubstring("Successfully disable addon")) 118 Eventually(func(g Gomega) { 119 g.Expect(apierrors.IsNotFound(k8sClient.Get(context.Background(), types.NamespacedName{Name: "addon-test-addon", Namespace: "test-vela"}, &v1beta1.Application{}))).Should(BeTrue()) 120 }, 60*time.Second).Should(Succeed()) 121 }) 122 123 It("Enable fluxcd-test-version whose version can't suit system requirements", func() { 124 output, err := e2e.InteractiveExec("vela addon enable fluxcd-test-version", func(c *expect.Console) { 125 _, err = c.SendLine("y") 126 Expect(err).NotTo(HaveOccurred()) 127 }) 128 Expect(output).To(ContainSubstring("enabled successfully")) 129 Expect(err).NotTo(HaveOccurred()) 130 }) 131 132 It("Disable addon fluxcd-test-version", func() { 133 output, err := e2e.LongTimeExec("vela addon disable fluxcd-test-version", 600*time.Second) 134 Expect(err).NotTo(HaveOccurred()) 135 Expect(output).To(ContainSubstring("Successfully disable addon")) 136 }) 137 138 It("Enable fluxcd-test-version whose version can't suit system requirements with 'n' input", func() { 139 output, err := e2e.InteractiveExec("vela addon enable fluxcd-test-version", func(c *expect.Console) { 140 _, err = c.SendLine("n") 141 Expect(err).NotTo(HaveOccurred()) 142 }) 143 Expect(output).To(ContainSubstring("you can try another version by command")) 144 Expect(err).NotTo(HaveOccurred()) 145 }) 146 }) 147 148 Context("Addon registry test", func() { 149 It("List all addon registry", func() { 150 output, err := e2e.Exec("vela addon registry list") 151 Expect(err).NotTo(HaveOccurred()) 152 Expect(output).To(ContainSubstring("KubeVela")) 153 }) 154 155 It("Get addon registry", func() { 156 output, err := e2e.Exec("vela addon registry get KubeVela") 157 Expect(err).NotTo(HaveOccurred()) 158 Expect(output).To(ContainSubstring("KubeVela")) 159 }) 160 161 It("Add test addon registry", func() { 162 output, err := e2e.LongTimeExec("vela addon registry add my-repo --type=git --endpoint=https://github.com/oam-dev/catalog --path=/experimental/addons", 600*time.Second) 163 Expect(err).NotTo(HaveOccurred()) 164 Expect(output).To(ContainSubstring("Successfully add an addon registry my-repo")) 165 166 Eventually(func() error { 167 output, err := e2e.LongTimeExec("vela addon registry update my-repo --type=git --endpoint=https://github.com/oam-dev/catalog --path=/addons", 300*time.Second) 168 if err != nil { 169 return err 170 } 171 if !strings.Contains(output, "Successfully update an addon registry my-repo") { 172 return fmt.Errorf("cannot update addon registry") 173 } 174 return nil 175 }, 30*time.Second, 300*time.Millisecond).Should(BeNil()) 176 177 output, err = e2e.LongTimeExec("vela addon registry delete my-repo", 600*time.Second) 178 Expect(err).NotTo(HaveOccurred()) 179 Expect(output).To(ContainSubstring("Successfully delete an addon registry my-repo")) 180 }) 181 }) 182 183 Context("Enable dependency addon test", func() { 184 It("enable upstream addon without specified clusters when dependence addon is not enabled", func() { 185 output, err := e2e.Exec("vela addon enable mock-dependence-rely") 186 Expect(err).NotTo(HaveOccurred()) 187 Expect(output).To(ContainSubstring("enabled successfully.")) 188 Eventually(func(g Gomega) { 189 app := &v1beta1.Application{} 190 Expect(k8sClient.Get(context.Background(), types.NamespacedName{Name: "addon-mock-dependence", Namespace: "vela-system"}, app)).Should(Succeed()) 191 topologyPolicyValue := map[string]interface{}{} 192 for _, policy := range app.Spec.Policies { 193 if policy.Type == "topology" { 194 Expect(json.Unmarshal(policy.Properties.Raw, &topologyPolicyValue)).Should(Succeed()) 195 break 196 } 197 } 198 Expect(topologyPolicyValue["clusterLabelSelector"]).Should(Equal(map[string]interface{}{})) 199 }, 30*time.Second).Should(Succeed()) 200 }) 201 202 It("enable upstream addon with specified clusters when dependence addon is not enabled ", func() { 203 output, err := e2e.Exec("vela addon enable mock-dependence-rely2 --clusters local") 204 Expect(err).NotTo(HaveOccurred()) 205 Expect(output).To(ContainSubstring("enabled successfully.")) 206 Eventually(func(g Gomega) { 207 app := &v1beta1.Application{} 208 Expect(k8sClient.Get(context.Background(), types.NamespacedName{Name: "addon-mock-dependence2", Namespace: "vela-system"}, app)).Should(Succeed()) 209 topologyPolicyValue := map[string]interface{}{} 210 for _, policy := range app.Spec.Policies { 211 if policy.Type == "topology" { 212 Expect(json.Unmarshal(policy.Properties.Raw, &topologyPolicyValue)).Should(Succeed()) 213 break 214 } 215 } 216 Expect(topologyPolicyValue["clusters"]).Should(Equal([]interface{}{"local"})) 217 }, 30*time.Second).Should(Succeed()) 218 }) 219 220 It("enable upstream addon without specified clusters when dependence addon is enabled with specified clusters", func() { 221 // 1. enable mock-dependence addon with local clusters 222 dependentName := "mock-dependence3" 223 addonName := "mock-dependence-rely3" 224 output, err := e2e.Exec("vela addon enable " + dependentName + " --clusters local myparam=test") 225 Expect(err).NotTo(HaveOccurred()) 226 Expect(output).To(ContainSubstring("enabled successfully.")) 227 Eventually(func(g Gomega) { 228 // check parameter 229 sec := &v1.Secret{} 230 g.Expect(k8sClient.Get(context.Background(), types.NamespacedName{Name: addonutil.Addon2SecName(dependentName), Namespace: "vela-system"}, sec)).Should(Succeed()) 231 parameters := map[string]interface{}{} 232 json.Unmarshal(sec.Data[addon.AddonParameterDataKey], ¶meters) 233 g.Expect(parameters).Should(BeEquivalentTo(map[string]interface{}{ 234 "clusters": []interface{}{"local"}, 235 "myparam": "test", 236 })) 237 // check application render cluster 238 app := &v1beta1.Application{} 239 Expect(k8sClient.Get(context.Background(), types.NamespacedName{Name: addonutil.Addon2AppName(dependentName), Namespace: "vela-system"}, app)).Should(Succeed()) 240 topologyPolicyValue := map[string]interface{}{} 241 for _, policy := range app.Spec.Policies { 242 if policy.Type == "topology" { 243 Expect(json.Unmarshal(policy.Properties.Raw, &topologyPolicyValue)).Should(Succeed()) 244 break 245 } 246 } 247 Expect(topologyPolicyValue["clusters"]).Should(Equal([]interface{}{"local"})) 248 Expect(topologyPolicyValue["clusterLabelSelector"]).Should(BeNil()) 249 }, 600*time.Second).Should(Succeed()) 250 // 2. enable mock-dependence-rely addon without clusters 251 output1, err1 := e2e.Exec("vela addon enable " + addonName) 252 Expect(err1).NotTo(HaveOccurred()) 253 Expect(output1).To(ContainSubstring("enabled successfully.")) 254 // 3. enable mock-dependence-rely addon changes the mock-dependence topology policy 255 Eventually(func(g Gomega) { 256 // check parameter 257 sec := &v1.Secret{} 258 g.Expect(k8sClient.Get(context.Background(), types.NamespacedName{Name: addonutil.Addon2SecName(dependentName), Namespace: "vela-system"}, sec)).Should(Succeed()) 259 parameters := map[string]interface{}{} 260 json.Unmarshal(sec.Data[addon.AddonParameterDataKey], ¶meters) 261 g.Expect(parameters).Should(BeEquivalentTo(map[string]interface{}{ 262 "myparam": "test", 263 })) 264 app := &v1beta1.Application{} 265 Expect(k8sClient.Get(context.Background(), types.NamespacedName{Name: addonutil.Addon2AppName(dependentName), Namespace: "vela-system"}, app)).Should(Succeed()) 266 topologyPolicyValue := map[string]interface{}{} 267 for _, policy := range app.Spec.Policies { 268 if policy.Type == "topology" { 269 Expect(json.Unmarshal(policy.Properties.Raw, &topologyPolicyValue)).Should(Succeed()) 270 break 271 } 272 } 273 Expect(topologyPolicyValue["clusters"]).Should(BeNil()) 274 Expect(topologyPolicyValue["clusterLabelSelector"]).Should(Equal(map[string]interface{}{})) 275 }, 30*time.Second).Should(Succeed()) 276 }) 277 278 It("enable upstream addon with specified clusters when dependence addon is enabled with clusters value is nil", func() { 279 // enable fluxcd 280 // enable rollout --clusters={local} 281 // 1. enable mock-dependence addon with nil clusters parameter 282 output, err := e2e.InteractiveExec("vela addon enable mock-dependence myparam=test", func(c *expect.Console) { 283 _, err = c.SendLine("y") 284 Expect(err).NotTo(HaveOccurred()) 285 }) 286 Expect(err).NotTo(HaveOccurred()) 287 Expect(output).To(ContainSubstring("enabled successfully.")) 288 Eventually(func(g Gomega) { 289 // check parameter 290 sec := &v1.Secret{} 291 g.Expect(k8sClient.Get(context.Background(), types.NamespacedName{Name: "addon-secret-mock-dependence", Namespace: "vela-system"}, sec)).Should(Succeed()) 292 parameters := map[string]interface{}{} 293 json.Unmarshal(sec.Data[addon.AddonParameterDataKey], ¶meters) 294 g.Expect(parameters).Should(BeEquivalentTo(map[string]interface{}{ 295 "myparam": "test", 296 })) 297 // check application render cluster 298 app := &v1beta1.Application{} 299 Expect(k8sClient.Get(context.Background(), types.NamespacedName{Name: "addon-mock-dependence", Namespace: "vela-system"}, app)).Should(Succeed()) 300 topologyPolicyValue := map[string]interface{}{} 301 for _, policy := range app.Spec.Policies { 302 if policy.Type == "topology" { 303 Expect(json.Unmarshal(policy.Properties.Raw, &topologyPolicyValue)).Should(Succeed()) 304 break 305 } 306 } 307 Expect(topologyPolicyValue["clusters"]).Should(BeNil()) 308 Expect(topologyPolicyValue["clusterLabelSelector"]).Should(Equal(map[string]interface{}{})) 309 }, 600*time.Second).Should(Succeed()) 310 311 // 2. enable mock-dependence-rely addon with local clusters 312 output1, err := e2e.InteractiveExec("vela addon enable mock-dependence-rely --clusters local", func(c *expect.Console) { 313 _, err = c.SendLine("y") 314 Expect(err).NotTo(HaveOccurred()) 315 }) 316 Expect(err).NotTo(HaveOccurred()) 317 Expect(output1).To(ContainSubstring("enabled successfully.")) 318 // 3. enable mock-dependence-rely addon changes the mock-dependence topology policy 319 Eventually(func(g Gomega) { 320 // check parameter 321 sec := &v1.Secret{} 322 g.Expect(k8sClient.Get(context.Background(), types.NamespacedName{Name: "addon-secret-mock-dependence", Namespace: "vela-system"}, sec)).Should(Succeed()) 323 parameters := map[string]interface{}{} 324 json.Unmarshal(sec.Data[addon.AddonParameterDataKey], ¶meters) 325 g.Expect(parameters).Should(BeEquivalentTo(map[string]interface{}{ 326 "myparam": "test", 327 })) 328 // check application render cluster 329 app := &v1beta1.Application{} 330 Expect(k8sClient.Get(context.Background(), types.NamespacedName{Name: "addon-mock-dependence", Namespace: "vela-system"}, app)).Should(Succeed()) 331 topologyPolicyValue := map[string]interface{}{} 332 for _, policy := range app.Spec.Policies { 333 if policy.Type == "topology" { 334 Expect(json.Unmarshal(policy.Properties.Raw, &topologyPolicyValue)).Should(Succeed()) 335 break 336 } 337 } 338 Expect(topologyPolicyValue["clusters"]).Should(BeNil()) 339 Expect(topologyPolicyValue["clusterLabelSelector"]).Should(Equal(map[string]interface{}{})) 340 }, 30*time.Second).Should(Succeed()) 341 }) 342 343 It("enable upstream addon without clusters when dependence addon is enabled with clusters value is not nil", func() { 344 // enable fluxcd --clusters={local} 345 // enable rollout 346 // 1. enable mock-dependence addon with local clusters and myparam parameter 347 output, err := e2e.InteractiveExec("vela addon enable mock-dependence --clusters local myparam=test", func(c *expect.Console) { 348 _, err = c.SendLine("y") 349 Expect(err).NotTo(HaveOccurred()) 350 }) 351 Expect(err).NotTo(HaveOccurred()) 352 Expect(output).To(ContainSubstring("enabled successfully.")) 353 Eventually(func(g Gomega) { 354 // check parameter 355 sec := &v1.Secret{} 356 g.Expect(k8sClient.Get(context.Background(), types.NamespacedName{Name: "addon-secret-mock-dependence", Namespace: "vela-system"}, sec)).Should(Succeed()) 357 parameters := map[string]interface{}{} 358 json.Unmarshal(sec.Data[addon.AddonParameterDataKey], ¶meters) 359 g.Expect(parameters).Should(BeEquivalentTo(map[string]interface{}{ 360 "clusters": []interface{}{"local"}, 361 "myparam": "test", 362 })) 363 // check application render cluster 364 app := &v1beta1.Application{} 365 Expect(k8sClient.Get(context.Background(), types.NamespacedName{Name: "addon-mock-dependence", Namespace: "vela-system"}, app)).Should(Succeed()) 366 topologyPolicyValue := map[string]interface{}{} 367 for _, policy := range app.Spec.Policies { 368 if policy.Type == "topology" { 369 Expect(json.Unmarshal(policy.Properties.Raw, &topologyPolicyValue)).Should(Succeed()) 370 break 371 } 372 } 373 Expect(topologyPolicyValue["clusters"]).Should(Equal([]interface{}{"local"})) 374 Expect(topologyPolicyValue["clusterLabelSelector"]).Should(BeNil()) 375 }, 600*time.Second).Should(Succeed()) 376 377 // 2. enable mock-dependence-rely addon without clusters 378 output1, err := e2e.InteractiveExec("vela addon enable mock-dependence-rely", func(c *expect.Console) { 379 _, err = c.SendLine("y") 380 Expect(err).NotTo(HaveOccurred()) 381 }) 382 Expect(err).NotTo(HaveOccurred()) 383 Expect(output1).To(ContainSubstring("enabled successfully.")) 384 // 3. enable mock-dependence-rely addon changes the mock-dependence topology policy 385 Eventually(func(g Gomega) { 386 // check parameter 387 sec := &v1.Secret{} 388 g.Expect(k8sClient.Get(context.Background(), types.NamespacedName{Name: "addon-secret-mock-dependence", Namespace: "vela-system"}, sec)).Should(Succeed()) 389 parameters := map[string]interface{}{} 390 json.Unmarshal(sec.Data[addon.AddonParameterDataKey], ¶meters) 391 g.Expect(parameters).Should(BeEquivalentTo(map[string]interface{}{ 392 "myparam": "test", 393 })) 394 // check application render cluster 395 app := &v1beta1.Application{} 396 Expect(k8sClient.Get(context.Background(), types.NamespacedName{Name: "addon-mock-dependence", Namespace: "vela-system"}, app)).Should(Succeed()) 397 topologyPolicyValue := map[string]interface{}{} 398 for _, policy := range app.Spec.Policies { 399 if policy.Type == "topology" { 400 Expect(json.Unmarshal(policy.Properties.Raw, &topologyPolicyValue)).Should(Succeed()) 401 break 402 } 403 } 404 Expect(topologyPolicyValue["clusters"]).Should(BeNil()) 405 Expect(topologyPolicyValue["clusterLabelSelector"]).Should(Equal(map[string]interface{}{})) 406 }, 60*time.Second).Should(Succeed()) 407 }) 408 409 It("enable upstream addon with two clusters when dependence addon is enabled with one cluster", func() { 410 const clusterName = "k3s-default" 411 // enable addon 412 output, err := e2e.InteractiveExec("vela addon enable mock-dependence --clusters local myparam=test", func(c *expect.Console) { 413 _, err = c.SendLine("y") 414 Expect(err).NotTo(HaveOccurred()) 415 }) 416 Expect(err).NotTo(HaveOccurred()) 417 Expect(output).To(ContainSubstring("enabled successfully.")) 418 output1, err := e2e.Exec("vela ls -A") 419 Expect(err).NotTo(HaveOccurred()) 420 Expect(output1).To(ContainSubstring("mock-dependence")) 421 output2, err := e2e.Exec("vela addon list") 422 Expect(err).NotTo(HaveOccurred()) 423 Expect(output2).To(ContainSubstring("mock-dependence")) 424 // check dependence application parameter 425 Eventually(func(g Gomega) { 426 // check parameter 427 sec := &v1.Secret{} 428 g.Expect(k8sClient.Get(context.Background(), types.NamespacedName{Name: "addon-secret-mock-dependence", Namespace: "vela-system"}, sec)).Should(Succeed()) 429 parameters := map[string]interface{}{} 430 json.Unmarshal(sec.Data[addon.AddonParameterDataKey], ¶meters) 431 g.Expect(parameters).Should(BeEquivalentTo(map[string]interface{}{ 432 "clusters": []interface{}{"local"}, 433 "myparam": "test", 434 })) 435 // check application render cluster 436 app := &v1beta1.Application{} 437 Expect(k8sClient.Get(context.Background(), types.NamespacedName{Name: "addon-mock-dependence", Namespace: "vela-system"}, app)).Should(Succeed()) 438 topologyPolicyValue := map[string]interface{}{} 439 for _, policy := range app.Spec.Policies { 440 if policy.Type == "topology" { 441 Expect(json.Unmarshal(policy.Properties.Raw, &topologyPolicyValue)).Should(Succeed()) 442 break 443 } 444 } 445 fluxcdYaml, err1 := e2e.Exec("vela status addon-mock-dependence -n vela-system -oyaml") 446 Expect(err1).NotTo(HaveOccurred()) 447 Expect(fluxcdYaml).To(ContainSubstring("mock-dependence")) 448 fluxcdStatus, err2 := e2e.Exec("vela addon status mock-dependence -v") 449 Expect(err2).NotTo(HaveOccurred()) 450 Expect(fluxcdStatus).To(ContainSubstring("mock-dependence")) 451 Expect(topologyPolicyValue["clusters"]).Should(Equal([]interface{}{"local"})) 452 }, 600*time.Second).Should(Succeed()) 453 // enable addon which rely on mock-dependence addon 454 e2e.InteractiveExec("vela addon enable mock-dependence-rely --clusters local,"+clusterName, func(c *expect.Console) { 455 _, err = c.SendLine("y") 456 Expect(err).NotTo(HaveOccurred()) 457 }) 458 // check mock-dependence application parameter 459 Eventually(func(g Gomega) { 460 sec := &v1.Secret{} 461 g.Expect(k8sClient.Get(context.Background(), types.NamespacedName{Name: "addon-secret-mock-dependence", Namespace: "vela-system"}, sec)).Should(Succeed()) 462 parameters := map[string]interface{}{} 463 json.Unmarshal(sec.Data[addon.AddonParameterDataKey], ¶meters) 464 g.Expect(parameters).Should(BeEquivalentTo(map[string]interface{}{ 465 "clusters": []interface{}{"local", clusterName}, 466 "myparam": "test", 467 })) 468 app := &v1beta1.Application{} 469 Expect(k8sClient.Get(context.Background(), types.NamespacedName{Name: "addon-mock-dependence", Namespace: "vela-system"}, app)).Should(Succeed()) 470 topologyPolicyValue := map[string]interface{}{} 471 for _, policy := range app.Spec.Policies { 472 if policy.Type == "topology" { 473 Expect(json.Unmarshal(policy.Properties.Raw, &topologyPolicyValue)).Should(Succeed()) 474 break 475 } 476 } 477 Expect(topologyPolicyValue["clusters"]).Should(Equal([]interface{}{"local", clusterName})) 478 }, 60*time.Second).Should(Succeed()) 479 }) 480 481 It("enable upstream addon without clusters when dependence addon which is enabled locally", func() { 482 // enable ./fluxcd 483 // enable rollout 484 // enable addon locally 485 output, err := e2e.LongTimeExec("vela addon enable ../../e2e/addon/mock/testdata/mock-dependence-locally --clusters local myparam=test", 600*time.Second) 486 Expect(err).NotTo(HaveOccurred()) 487 Expect(output).To(ContainSubstring("enabled successfully.")) 488 // check dependence application parameter 489 Eventually(func(g Gomega) { 490 // check parameter 491 sec := &v1.Secret{} 492 g.Expect(k8sClient.Get(context.Background(), types.NamespacedName{Name: "addon-secret-mock-dependence-locally", Namespace: "vela-system"}, sec)).Should(Succeed()) 493 parameters := map[string]interface{}{} 494 json.Unmarshal(sec.Data[addon.AddonParameterDataKey], ¶meters) 495 g.Expect(parameters).Should(BeEquivalentTo(map[string]interface{}{ 496 "clusters": []interface{}{"local"}, 497 "myparam": "test", 498 })) 499 // check application render cluster 500 app := &v1beta1.Application{} 501 Expect(k8sClient.Get(context.Background(), types.NamespacedName{Name: "addon-mock-dependence-locally", Namespace: "vela-system"}, app)).Should(Succeed()) 502 topologyPolicyValue := map[string]interface{}{} 503 for _, policy := range app.Spec.Policies { 504 if policy.Type == "topology" { 505 Expect(json.Unmarshal(policy.Properties.Raw, &topologyPolicyValue)).Should(Succeed()) 506 break 507 } 508 } 509 Expect(topologyPolicyValue["clusters"]).Should(Equal([]interface{}{"local"})) 510 Expect(topologyPolicyValue["clusterLabelSelector"]).Should(BeNil()) 511 }, 600*time.Second).Should(Succeed()) 512 // enable addon which rely on mock-dependence-locally 513 output1, err1 := e2e.Exec("vela addon enable mock-dependence-upstream-locally") 514 Expect(err1).NotTo(HaveOccurred()) 515 Expect(output1).To(ContainSubstring("enabled successfully.")) 516 // check mock-dependence-locally application parameter 517 Eventually(func(g Gomega) { 518 // check parameter 519 sec := &v1.Secret{} 520 g.Expect(k8sClient.Get(context.Background(), types.NamespacedName{Name: "addon-secret-mock-dependence-locally", Namespace: "vela-system"}, sec)).Should(Succeed()) 521 parameters := map[string]interface{}{} 522 json.Unmarshal(sec.Data[addon.AddonParameterDataKey], ¶meters) 523 g.Expect(parameters).Should(BeEquivalentTo(map[string]interface{}{ 524 "clusters": []interface{}{"local"}, 525 "myparam": "test", 526 })) 527 // check application render cluster 528 app := &v1beta1.Application{} 529 Expect(k8sClient.Get(context.Background(), types.NamespacedName{Name: "addon-mock-dependence-locally", Namespace: "vela-system"}, app)).Should(Succeed()) 530 topologyPolicyValue := map[string]interface{}{} 531 for _, policy := range app.Spec.Policies { 532 if policy.Type == "topology" { 533 Expect(json.Unmarshal(policy.Properties.Raw, &topologyPolicyValue)).Should(Succeed()) 534 break 535 } 536 } 537 Expect(topologyPolicyValue["clusters"]).Should(Equal([]interface{}{"local"})) 538 Expect(topologyPolicyValue["clusterLabelSelector"]).Should(BeNil()) 539 }, 30*time.Second).Should(Succeed()) 540 }) 541 542 It("enable upstream addon with specified clusters when dependence addon which without clusters arg is enabled", func() { 543 // enable vela-prism 544 // enable o11 545 output, err := e2e.LongTimeExec("vela addon enable mock-dependence-no-clusters-arg myparam=test", 600*time.Second) 546 Expect(err).NotTo(HaveOccurred()) 547 Expect(output).To(ContainSubstring("enabled successfully.")) 548 // check dependence application parameter 549 Eventually(func(g Gomega) { 550 // check parameter 551 sec := &v1.Secret{} 552 g.Expect(k8sClient.Get(context.Background(), types.NamespacedName{Name: "addon-secret-mock-dependence-no-clusters-arg", Namespace: "vela-system"}, sec)).Should(Succeed()) 553 parameters := map[string]interface{}{} 554 json.Unmarshal(sec.Data[addon.AddonParameterDataKey], ¶meters) 555 g.Expect(parameters).Should(BeEquivalentTo(map[string]interface{}{ 556 "myparam": "test", 557 })) 558 }, 600*time.Second).Should(Succeed()) 559 // enable addon which rely on mock-dependence-no-clusters-arg 560 output1, err1 := e2e.Exec("vela addon enable mock-dependence-upstream-no-clusters-arg --clusters local") 561 Expect(err1).NotTo(HaveOccurred()) 562 Expect(output1).To(ContainSubstring("enabled successfully.")) 563 // check mock-dependence-locally application parameter 564 Eventually(func(g Gomega) { 565 // check parameter 566 sec := &v1.Secret{} 567 g.Expect(k8sClient.Get(context.Background(), types.NamespacedName{Name: "addon-secret-mock-dependence-no-clusters-arg", Namespace: "vela-system"}, sec)).Should(Succeed()) 568 parameters := map[string]interface{}{} 569 json.Unmarshal(sec.Data[addon.AddonParameterDataKey], ¶meters) 570 g.Expect(parameters).Should(BeEquivalentTo(map[string]interface{}{ 571 "myparam": "test", 572 })) 573 }, 30*time.Second).Should(Succeed()) 574 }) 575 }) 576 577 })