diff --git a/test/e2e/addonmanagement_test.go b/test/e2e/addonmanagement_test.go index f5ddf958d..702d69e1a 100644 --- a/test/e2e/addonmanagement_test.go +++ b/test/e2e/addonmanagement_test.go @@ -28,6 +28,7 @@ import ( const ( nodePlacementDeploymentConfigName = "node-placement-deploy-config" imageOverrideDeploymentConfigName = "image-override-deploy-config" + namespaceOverrideConfigName = "namespace-override-config" originalImageValue = "quay.io/open-cluster-management/addon-examples:latest" overrideImageValue = "quay.io/ocm/addon-examples:latest" customSignerName = "example.com/signer-name" @@ -476,6 +477,55 @@ var _ = ginkgo.Describe("Enable addon management feature gate", ginkgo.Ordered, }) + ginkgo.It("Template type addon should be configured by addon deployment config for namespace", func() { + ginkgo.By("Prepare a AddOnDeploymentConfig for namespace config") + overrideNamespace := &corev1.Namespace{ + ObjectMeta: metav1.ObjectMeta{ + Name: "another-addon-namespace", + }, + } + _, err := t.SpokeKubeClient.CoreV1().Namespaces().Create(context.TODO(), overrideNamespace, metav1.CreateOptions{}) + gomega.Expect(err).ToNot(gomega.HaveOccurred()) + gomega.Eventually(func() error { + return prepareInstallNamespace(clusterName, overrideNamespace.Name) + }, eventuallyTimeout, eventuallyInterval).ShouldNot(gomega.HaveOccurred()) + + ginkgo.By("Add the configs to ManagedClusterAddOn") + gomega.Eventually(func() error { + addon, err := t.AddOnClinet.AddonV1alpha1().ManagedClusterAddOns(clusterName).Get( + context.Background(), addOnName, metav1.GetOptions{}) + if err != nil { + return err + } + newAddon := addon.DeepCopy() + newAddon.Spec.Configs = []addonapiv1alpha1.AddOnConfig{ + { + ConfigGroupResource: addonapiv1alpha1.ConfigGroupResource{ + Group: "addon.open-cluster-management.io", + Resource: "addondeploymentconfigs", + }, + ConfigReferent: addonapiv1alpha1.ConfigReferent{ + Namespace: clusterName, + Name: namespaceOverrideConfigName, + }, + }, + } + _, err = t.AddOnClinet.AddonV1alpha1().ManagedClusterAddOns(clusterName).Update( + context.Background(), newAddon, metav1.UpdateOptions{}) + if err != nil { + return err + } + return nil + }, eventuallyTimeout, eventuallyInterval).ShouldNot(gomega.HaveOccurred()) + + ginkgo.By("Make sure addon is configured") + gomega.Eventually(func() error { + _, err := t.SpokeKubeClient.AppsV1().Deployments(overrideNamespace.Name).Get( + context.Background(), "hello-template-agent", metav1.GetOptions{}) + return err + }, eventuallyTimeout, eventuallyInterval).ShouldNot(gomega.HaveOccurred()) + }) + ginkgo.It("Template type addon's image should be overrode by cluster annotation", func() { ginkgo.By("Prepare cluster annotation for addon image override config") overrideRegistries := addonapiv1alpha1.AddOnDeploymentConfigSpec{ @@ -564,6 +614,32 @@ var _ = ginkgo.Describe("Enable addon management feature gate", ginkgo.Ordered, }) +func prepareInstallNamespace(namespace, installNamespace string) error { + _, err := t.AddOnClinet.AddonV1alpha1().AddOnDeploymentConfigs(namespace).Get( + context.Background(), namespaceOverrideConfigName, metav1.GetOptions{}) + if errors.IsNotFound(err) { + if _, err := t.AddOnClinet.AddonV1alpha1().AddOnDeploymentConfigs(namespace).Create( + context.Background(), + &addonapiv1alpha1.AddOnDeploymentConfig{ + ObjectMeta: metav1.ObjectMeta{ + Name: namespaceOverrideConfigName, + Namespace: namespace, + }, + Spec: addonapiv1alpha1.AddOnDeploymentConfigSpec{ + AgentInstallNamespace: installNamespace, + }, + }, + metav1.CreateOptions{}, + ); err != nil { + return err + } + + return nil + } + + return err +} + func prepareImageOverrideAddOnDeploymentConfig(namespace, installNamespace string) error { _, err := t.AddOnClinet.AddonV1alpha1().AddOnDeploymentConfigs(namespace).Get( context.Background(), imageOverrideDeploymentConfigName, metav1.GetOptions{}) @@ -588,11 +664,7 @@ func prepareImageOverrideAddOnDeploymentConfig(namespace, installNamespace strin return nil } - if err != nil { - return err - } - - return nil + return err } func prepareNodePlacementAddOnDeploymentConfig(namespace, installNamespace string) error { @@ -622,11 +694,7 @@ func prepareNodePlacementAddOnDeploymentConfig(namespace, installNamespace strin return nil } - if err != nil { - return err - } - - return nil + return err } func copySignerSecret(ctx context.Context, kubeClient kubernetes.Interface, srcNs, srcName, dstNs, dstName string) error {