From 148968a559ef3e64eddb3645b0f79f9946f3719a Mon Sep 17 00:00:00 2001 From: ashish Date: Mon, 20 Jun 2022 14:17:13 +0530 Subject: [PATCH 1/2] change catalogsource object and subscription object names Signed-off-by: ashish --- internal/controllers/addon/phase_ensure_catalogsource.go | 2 +- internal/controllers/addon/phase_ensure_subscription.go | 2 +- internal/controllers/addon/utils.go | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/controllers/addon/phase_ensure_catalogsource.go b/internal/controllers/addon/phase_ensure_catalogsource.go index c2b62ed1f..ecf0551c7 100644 --- a/internal/controllers/addon/phase_ensure_catalogsource.go +++ b/internal/controllers/addon/phase_ensure_catalogsource.go @@ -33,7 +33,7 @@ func (r *olmReconciler) ensureCatalogSource( catalogSource := &operatorsv1alpha1.CatalogSource{ ObjectMeta: metav1.ObjectMeta{ - Name: addon.Name, + Name: CatalogSourceName(addon), Namespace: commonConfig.Namespace, }, Spec: operatorsv1alpha1.CatalogSourceSpec{ diff --git a/internal/controllers/addon/phase_ensure_subscription.go b/internal/controllers/addon/phase_ensure_subscription.go index 7c1ee76a3..e72f55f00 100644 --- a/internal/controllers/addon/phase_ensure_subscription.go +++ b/internal/controllers/addon/phase_ensure_subscription.go @@ -41,7 +41,7 @@ func (r *olmReconciler) ensureSubscription( subscriptionConfigObject := createSubscriptionConfigObject(commonInstallOptions) desiredSubscription := &operatorsv1alpha1.Subscription{ ObjectMeta: metav1.ObjectMeta{ - Name: addon.Name, + Name: SubscriptionName(addon), Namespace: commonInstallOptions.Namespace, }, Spec: &operatorsv1alpha1.SubscriptionSpec{ diff --git a/internal/controllers/addon/utils.go b/internal/controllers/addon/utils.go index 8cc9f6569..554f3d788 100644 --- a/internal/controllers/addon/utils.go +++ b/internal/controllers/addon/utils.go @@ -342,5 +342,13 @@ func getCatalogSourceNetworkPolicyName(addon *addonsv1alpha1.Addon) string { return fmt.Sprintf("addon-%s-catalogs", addon.Name) } +func CatalogSourceName(addon *addonsv1alpha1.Addon) string { + return fmt.Sprintf("addon-%s-catalog", addon.Name) +} + +func SubscriptionName(addon *addonsv1alpha1.Addon) string { + return fmt.Sprintf("addon-%s", addon.Name) +} + func corev1ProtocolPtr(proto corev1.Protocol) *corev1.Protocol { return &proto } func intOrStringPtr(iors intstr.IntOrString) *intstr.IntOrString { return &iors } From 0ae3965ea3da97df6e8fa413de0d9ee5d070fe10 Mon Sep 17 00:00:00 2001 From: ashish Date: Mon, 20 Jun 2022 15:31:56 +0530 Subject: [PATCH 2/2] update integration tests Signed-off-by: ashish --- integration/addon_test.go | 15 ++++++++------- integration/broken_subscription_test.go | 5 +++-- integration/fixtures_test.go | 4 ++-- integration/resource_adoption_test.go | 5 +++-- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/integration/addon_test.go b/integration/addon_test.go index 9a54f342d..79e38e690 100644 --- a/integration/addon_test.go +++ b/integration/addon_test.go @@ -14,6 +14,7 @@ import ( addonsv1alpha1 "github.com/openshift/addon-operator/apis/addons/v1alpha1" "github.com/openshift/addon-operator/integration" + addonUtil "github.com/openshift/addon-operator/internal/controllers/addon" ) func (s *integrationTestSuite) TestAddon() { @@ -119,7 +120,7 @@ func (s *integrationTestSuite) TestAddon() { s.Run("catalogsource exists", func() { currentCatalogSource := &operatorsv1alpha1.CatalogSource{} err := integration.Client.Get(ctx, client.ObjectKey{ - Name: addon.Name, + Name: addonUtil.CatalogSourceName(addon), Namespace: addon.Spec.Install.OLMOwnNamespace.Namespace, }, currentCatalogSource) s.Assert().NoError(err, "could not get CatalogSource %s", addon.Name) @@ -133,7 +134,7 @@ func (s *integrationTestSuite) TestAddon() { { err := integration.Client.Get(ctx, client.ObjectKey{ Namespace: addon.Spec.Install.OLMOwnNamespace.Namespace, - Name: addon.Name, + Name: addonUtil.SubscriptionName(addon), }, subscription) s.Require().NoError(err) @@ -164,7 +165,7 @@ func (s *integrationTestSuite) TestAddon() { err := integration.Client.Get(ctx, client.ObjectKey{ Namespace: addon.Spec.Install.OLMOwnNamespace.Namespace, - Name: addon.Name, + Name: addonUtil.SubscriptionName(addon), }, subscription) s.Require().NoError(err) envObjectsPresent := subscription.Spec.Config.Env @@ -187,7 +188,7 @@ func (s *integrationTestSuite) TestAddon() { // assert that CatalogSource is gone currentCatalogSource := &operatorsv1alpha1.CatalogSource{} err = integration.Client.Get(ctx, client.ObjectKey{ - Name: addon.Name, + Name: addonUtil.CatalogSourceName(addon), Namespace: addon.Spec.Install.OLMOwnNamespace.Namespace, }, currentCatalogSource) s.Assert().True(k8sApiErrors.IsNotFound(err), "CatalogSource not deleted: %s", currentCatalogSource.Name) @@ -232,9 +233,9 @@ func (s *integrationTestSuite) TestAddonWithAdditionalCatalogSrc() { s.Assert().NoError(err, "could not get CatalogSource %s", addon.Name) s.Assert().Equal(3, len(catalogSourceList.Items)) expectedImages := map[string]string{ - "test-1": referenceAddonCatalogSourceImageWorking, - "test-2": referenceAddonCatalogSourceImageWorking, - addon.Name: referenceAddonCatalogSourceImageWorking, + "test-1": referenceAddonCatalogSourceImageWorking, + "test-2": referenceAddonCatalogSourceImageWorking, + addonUtil.CatalogSourceName(addon): referenceAddonCatalogSourceImageWorking, } for _, ctlgSrc := range catalogSourceList.Items { s.Assert().Equal(expectedImages[ctlgSrc.Name], ctlgSrc.Spec.Image) diff --git a/integration/broken_subscription_test.go b/integration/broken_subscription_test.go index a3114fd1e..6d1b2e3fc 100644 --- a/integration/broken_subscription_test.go +++ b/integration/broken_subscription_test.go @@ -13,6 +13,7 @@ import ( addonsv1alpha1 "github.com/openshift/addon-operator/apis/addons/v1alpha1" "github.com/openshift/addon-operator/integration" + addonUtil "github.com/openshift/addon-operator/internal/controllers/addon" ) // This test deploys a version of our addon where InstallPlan and @@ -55,7 +56,7 @@ func (s *integrationTestSuite) TestAddon_BrokenSubscription() { subscription := &operatorsv1alpha1.Subscription{} err := integration.Client.Get(ctx, client.ObjectKey{ Namespace: addon.Spec.Install.OLMOwnNamespace.Namespace, - Name: addon.Name, + Name: addonUtil.SubscriptionName(addon), }, subscription) s.Require().NoError(err) @@ -73,7 +74,7 @@ func (s *integrationTestSuite) TestAddon_BrokenSubscription() { // assert that CatalogSource is gone currentCatalogSource := &operatorsv1alpha1.CatalogSource{} err = integration.Client.Get(ctx, types.NamespacedName{ - Name: addon.Name, + Name: addonUtil.CatalogSourceName(addon), Namespace: addon.Spec.Install.OLMOwnNamespace.Namespace, }, currentCatalogSource) s.Assert().True(k8sApiErrors.IsNotFound(err), "CatalogSource not deleted: %s", currentCatalogSource.Name) diff --git a/integration/fixtures_test.go b/integration/fixtures_test.go index 89b3b9473..d9aa6cde1 100644 --- a/integration/fixtures_test.go +++ b/integration/fixtures_test.go @@ -220,7 +220,7 @@ func namespace_TestResourceAdoption() *corev1.Namespace { func catalogsource_TestResourceAdoption() *operatorsv1alpha1.CatalogSource { return &operatorsv1alpha1.CatalogSource{ ObjectMeta: metav1.ObjectMeta{ - Name: referenceAddonName, + Name: fmt.Sprintf("addon-%s-catalog", referenceAddonName), Namespace: referenceAddonNamespace, }, Spec: operatorsv1alpha1.CatalogSourceSpec{ @@ -247,7 +247,7 @@ func operatorgroup_TestResourceAdoption() *operatorsv1.OperatorGroup { func subscription_TestResourceAdoption() *operatorsv1alpha1.Subscription { return &operatorsv1alpha1.Subscription{ ObjectMeta: metav1.ObjectMeta{ - Name: referenceAddonName, + Name: fmt.Sprintf("addon-%s", referenceAddonName), Namespace: referenceAddonNamespace}, Spec: &operatorsv1alpha1.SubscriptionSpec{ CatalogSource: referenceAddonName, diff --git a/integration/resource_adoption_test.go b/integration/resource_adoption_test.go index 01a932567..435bdc7ff 100644 --- a/integration/resource_adoption_test.go +++ b/integration/resource_adoption_test.go @@ -16,6 +16,7 @@ import ( addonsv1alpha1 "github.com/openshift/addon-operator/apis/addons/v1alpha1" "github.com/openshift/addon-operator/integration" "github.com/openshift/addon-operator/internal/controllers" + addonUtil "github.com/openshift/addon-operator/internal/controllers/addon" ) func (s *integrationTestSuite) TestResourceAdoption() { @@ -107,7 +108,7 @@ func (s *integrationTestSuite) TestResourceAdoption() { { observedSubscription := &operatorsv1alpha1.Subscription{ ObjectMeta: metav1.ObjectMeta{ - Name: referenceAddonName, + Name: addonUtil.SubscriptionName(addon), Namespace: referenceAddonNamespace, }, } @@ -142,7 +143,7 @@ func (s *integrationTestSuite) TestResourceAdoption() { { observedCS := &operatorsv1alpha1.CatalogSource{ ObjectMeta: metav1.ObjectMeta{ - Name: referenceAddonName, + Name: addonUtil.CatalogSourceName(addon), Namespace: referenceAddonNamespace, }, }