Skip to content

Commit

Permalink
Add an e2e test case
Browse files Browse the repository at this point in the history
Signed-off-by: Jian Qiu <jqiu@redhat.com>
  • Loading branch information
qiujian16 committed Apr 18, 2024
1 parent 9c987a0 commit 0fab09f
Showing 1 changed file with 78 additions and 10 deletions.
88 changes: 78 additions & 10 deletions test/e2e/addonmanagement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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: imageOverrideDeploymentConfigName,
},
},
}
_, 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{
Expand Down Expand Up @@ -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{})
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 0fab09f

Please sign in to comment.