From 974d84fa5ea294c3f5c5895c729809abb9a5e978 Mon Sep 17 00:00:00 2001 From: xiezhang Date: Wed, 15 Feb 2023 15:04:51 -0500 Subject: [PATCH] DBAAS-1193: uninstall rds-dbaas-operator when launching dbaas-operator to trigger ack-rds-operator re-installation --- controllers/dbaasplatform_controller.go | 26 +++++ controllers/suite_test.go | 122 +++++++++++++++++++++++- 2 files changed, 144 insertions(+), 4 deletions(-) diff --git a/controllers/dbaasplatform_controller.go b/controllers/dbaasplatform_controller.go index ba49fc61..4c3b680b 100644 --- a/controllers/dbaasplatform_controller.go +++ b/controllers/dbaasplatform_controller.go @@ -471,5 +471,31 @@ func (r *DBaaSPlatformReconciler) prepareRDSController(ctx context.Context, cli } } + rds := reconcilers.InstallationPlatforms[v1beta1.RDSProviderInstallation] + + subscription := &v1alpha1.Subscription{ + ObjectMeta: metav1.ObjectMeta{ + Name: rds.Name + "-subscription", + Namespace: r.InstallNamespace, + }, + } + if err := cli.Delete(ctx, subscription); err != nil { + if !apierrors.IsNotFound(err) { + return err + } + } + + csv := &v1alpha1.ClusterServiceVersion{ + ObjectMeta: metav1.ObjectMeta{ + Name: rds.CSV, + Namespace: r.InstallNamespace, + }, + } + if err := cli.Delete(ctx, csv); err != nil { + if !apierrors.IsNotFound(err) { + return err + } + } + return nil } diff --git a/controllers/suite_test.go b/controllers/suite_test.go index 98b6e7bb..ceed7384 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -25,6 +25,8 @@ import ( "testing" "time" + "github.com/RHEcosystemAppEng/dbaas-operator/controllers/reconcilers" + . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -193,7 +195,8 @@ var _ = BeforeSuite(func() { }).SetupWithManager(k8sManager) Expect(err).ToNot(HaveOccurred()) - mockRDSController(k8sManager) + mockACKRDSController(k8sManager) + mockRDSOperator(k8sManager) createCSV(k8sManager) err = (&DBaaSPlatformReconciler{ @@ -202,7 +205,8 @@ var _ = BeforeSuite(func() { }).SetupWithManager(k8sManager) Expect(err).ToNot(HaveOccurred()) - checkRDSController(k8sManager) + checkACKRDSController(k8sManager) + checkRDSOperator(k8sManager) go func() { defer GinkgoRecover() @@ -251,7 +255,7 @@ func createCSV(k8sManager manager.Manager) { Expect(err).ToNot(HaveOccurred()) } -func mockRDSController(k8sManager manager.Manager) { +func mockACKRDSController(k8sManager manager.Manager) { serverClient, err := client.New( k8sManager.GetConfig(), client.Options{ @@ -339,7 +343,85 @@ func mockRDSController(k8sManager manager.Manager) { Expect(err).ToNot(HaveOccurred()) } -func checkRDSController(k8sManager manager.Manager) { +func mockRDSOperator(k8sManager manager.Manager) { + serverClient, err := client.New( + k8sManager.GetConfig(), + client.Options{ + Scheme: k8sManager.GetScheme(), + }, + ) + Expect(err).ToNot(HaveOccurred()) + + rds := reconcilers.InstallationPlatforms[v1beta1.RDSProviderInstallation] + + csv := &operatorframework.ClusterServiceVersion{ + ObjectMeta: metav1.ObjectMeta{ + Name: rds.CSV, + Namespace: testNamespace, + }, + Spec: operatorframework.ClusterServiceVersionSpec{ + DisplayName: "RHODA Provider Operator for Amazon RDS", + InstallStrategy: operatorframework.NamedInstallStrategy{ + StrategyName: "deployment", + StrategySpec: operatorframework.StrategyDetailsDeployment{ + DeploymentSpecs: []operatorframework.StrategyDeploymentSpec{ + { + Name: "rds-dbaas-operator-controller-manager", + Spec: appsv1.DeploymentSpec{ + Replicas: pointer.Int32(1), + Selector: &metav1.LabelSelector{ + MatchLabels: map[string]string{ + "control-plane": "controller-manager", + "type": "rds-dbaas-operator", + }, + }, + Template: corev1.PodTemplateSpec{ + ObjectMeta: metav1.ObjectMeta{ + Labels: map[string]string{ + "control-plane": "controller-manager", + "type": "rds-dbaas-operator", + }, + }, + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + Name: "controller", + Image: "quay.io/ecosystem-appeng/busybox", + ImagePullPolicy: corev1.PullIfNotPresent, + Command: []string{"sh", "-c", "echo The app is running! && sleep 3600"}, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + } + err = serverClient.Create(ctx, csv) + Expect(err).ToNot(HaveOccurred()) + + subscription := &operatorframework.Subscription{ + ObjectMeta: metav1.ObjectMeta{ + Name: rds.Name + "-subscription", + Namespace: testNamespace, + }, + Spec: &operatorframework.SubscriptionSpec{ + CatalogSource: "rds-provider-catalogsource", + CatalogSourceNamespace: "openshift-marketplace", + Package: "rds-dbaas-operator", + Channel: "alpha", + InstallPlanApproval: "Automatic", + StartingCSV: "rds-dbaas-operator.v0.3.0", + }, + } + err = serverClient.Create(ctx, subscription) + Expect(err).ToNot(HaveOccurred()) +} + +func checkACKRDSController(k8sManager manager.Manager) { serverClient, err := client.New( k8sManager.GetConfig(), client.Options{ @@ -368,3 +450,35 @@ func checkRDSController(k8sManager manager.Manager) { Expect(err).To(HaveOccurred()) Expect(errors.IsNotFound(err)).Should(BeTrue()) } + +func checkRDSOperator(k8sManager manager.Manager) { + serverClient, err := client.New( + k8sManager.GetConfig(), + client.Options{ + Scheme: k8sManager.GetScheme(), + }, + ) + Expect(err).ToNot(HaveOccurred()) + + rds := reconcilers.InstallationPlatforms[v1beta1.RDSProviderInstallation] + + csv := &operatorframework.ClusterServiceVersion{ + ObjectMeta: metav1.ObjectMeta{ + Name: rds.CSV, + Namespace: testNamespace, + }, + } + err = serverClient.Get(ctx, client.ObjectKeyFromObject(csv), csv) + Expect(err).To(HaveOccurred()) + Expect(errors.IsNotFound(err)).Should(BeTrue()) + + subscription := &operatorframework.Subscription{ + ObjectMeta: metav1.ObjectMeta{ + Name: rds.Name + "-subscription", + Namespace: testNamespace, + }, + } + err = serverClient.Get(ctx, client.ObjectKeyFromObject(subscription), subscription) + Expect(err).To(HaveOccurred()) + Expect(errors.IsNotFound(err)).Should(BeTrue()) +}