Skip to content

Commit

Permalink
DBAAS-1193: uninstall rds-dbaas-operator when launching dbaas-operato…
Browse files Browse the repository at this point in the history
…r to trigger ack-rds-operator re-installation
  • Loading branch information
xieshenzh committed Feb 15, 2023
1 parent 97e2b76 commit 974d84f
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 4 deletions.
26 changes: 26 additions & 0 deletions controllers/dbaasplatform_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
122 changes: 118 additions & 4 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"testing"
"time"

"github.com/RHEcosystemAppEng/dbaas-operator/controllers/reconcilers"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

Expand Down Expand Up @@ -193,7 +195,8 @@ var _ = BeforeSuite(func() {
}).SetupWithManager(k8sManager)
Expect(err).ToNot(HaveOccurred())

mockRDSController(k8sManager)
mockACKRDSController(k8sManager)
mockRDSOperator(k8sManager)

createCSV(k8sManager)
err = (&DBaaSPlatformReconciler{
Expand All @@ -202,7 +205,8 @@ var _ = BeforeSuite(func() {
}).SetupWithManager(k8sManager)
Expect(err).ToNot(HaveOccurred())

checkRDSController(k8sManager)
checkACKRDSController(k8sManager)
checkRDSOperator(k8sManager)

go func() {
defer GinkgoRecover()
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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())
}

0 comments on commit 974d84f

Please sign in to comment.