From 81c3333b688935f99184182d883cd7d16721a06e Mon Sep 17 00:00:00 2001 From: Balazs Gibizer Date: Thu, 28 Sep 2023 11:04:55 +0200 Subject: [PATCH] Delete database test helpers This is necessary to remove a dependency cycle. The helpers are moved to mariadb-operator/api module. --- modules/certmanager/go.mod | 1 - modules/certmanager/go.sum | 2 - modules/test/go.mod | 1 - modules/test/go.sum | 2 - modules/test/helpers/database.go | 118 ------------------------------- 5 files changed, 124 deletions(-) delete mode 100644 modules/test/helpers/database.go diff --git a/modules/certmanager/go.mod b/modules/certmanager/go.mod index 4799e383..cd71385f 100644 --- a/modules/certmanager/go.mod +++ b/modules/certmanager/go.mod @@ -42,7 +42,6 @@ require ( github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/openshift/api v3.9.0+incompatible // indirect github.com/openstack-k8s-operators/infra-operator/apis v0.1.1-0.20230920125017-2c76cd203b44 // indirect - github.com/openstack-k8s-operators/mariadb-operator/api v0.1.1-0.20230918111825-8999b3b2dc3c // indirect github.com/pkg/errors v0.9.1 // indirect github.com/prometheus/client_golang v1.14.0 // indirect github.com/prometheus/client_model v0.3.0 // indirect diff --git a/modules/certmanager/go.sum b/modules/certmanager/go.sum index f90b5b6c..73732646 100644 --- a/modules/certmanager/go.sum +++ b/modules/certmanager/go.sum @@ -236,8 +236,6 @@ github.com/openshift/api v0.0.0-20230414143018-3367bc7e6ac7 h1:rncLxJBpFGqBztyxC github.com/openshift/api v0.0.0-20230414143018-3367bc7e6ac7/go.mod h1:ctXNyWanKEjGj8sss1KjjHQ3ENKFm33FFnS5BKaIPh4= github.com/openstack-k8s-operators/infra-operator/apis v0.1.1-0.20230920125017-2c76cd203b44 h1:W2HZy+uk5fnVwvw3+/Jd/k7sNiVXCOd8SiV0dMvmjys= github.com/openstack-k8s-operators/infra-operator/apis v0.1.1-0.20230920125017-2c76cd203b44/go.mod h1:fOJ95wMSymtfoellY/TFKcrzW6bu/nTCTzEnFEgCGCc= -github.com/openstack-k8s-operators/mariadb-operator/api v0.1.1-0.20230918111825-8999b3b2dc3c h1:9R8T1WRwuPS5KMfsQWxAMSGPuJrGMJ7bODKK9dirhHA= -github.com/openstack-k8s-operators/mariadb-operator/api v0.1.1-0.20230918111825-8999b3b2dc3c/go.mod h1:xXHF/R/L0XamRHR/UkzlgzSTocBQ6GSQ2U16Q9Mf/bA= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= diff --git a/modules/test/go.mod b/modules/test/go.mod index 083c966e..2b66e97a 100644 --- a/modules/test/go.mod +++ b/modules/test/go.mod @@ -8,7 +8,6 @@ require ( github.com/onsi/gomega v1.27.10 github.com/openstack-k8s-operators/infra-operator/apis v0.1.1-0.20230920125017-2c76cd203b44 github.com/openstack-k8s-operators/lib-common/modules/common v0.1.1-0.20230919113507-d74c2f31d216 - github.com/openstack-k8s-operators/mariadb-operator/api v0.1.1-0.20230918111825-8999b3b2dc3c golang.org/x/mod v0.12.0 k8s.io/api v0.26.9 k8s.io/apimachinery v0.26.9 diff --git a/modules/test/go.sum b/modules/test/go.sum index 6848494d..05d2c04e 100644 --- a/modules/test/go.sum +++ b/modules/test/go.sum @@ -230,8 +230,6 @@ github.com/openshift/api v0.0.0-20230414143018-3367bc7e6ac7 h1:rncLxJBpFGqBztyxC github.com/openshift/api v0.0.0-20230414143018-3367bc7e6ac7/go.mod h1:ctXNyWanKEjGj8sss1KjjHQ3ENKFm33FFnS5BKaIPh4= github.com/openstack-k8s-operators/infra-operator/apis v0.1.1-0.20230920125017-2c76cd203b44 h1:W2HZy+uk5fnVwvw3+/Jd/k7sNiVXCOd8SiV0dMvmjys= github.com/openstack-k8s-operators/infra-operator/apis v0.1.1-0.20230920125017-2c76cd203b44/go.mod h1:fOJ95wMSymtfoellY/TFKcrzW6bu/nTCTzEnFEgCGCc= -github.com/openstack-k8s-operators/mariadb-operator/api v0.1.1-0.20230918111825-8999b3b2dc3c h1:9R8T1WRwuPS5KMfsQWxAMSGPuJrGMJ7bODKK9dirhHA= -github.com/openstack-k8s-operators/mariadb-operator/api v0.1.1-0.20230918111825-8999b3b2dc3c/go.mod h1:xXHF/R/L0XamRHR/UkzlgzSTocBQ6GSQ2U16Q9Mf/bA= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= diff --git a/modules/test/helpers/database.go b/modules/test/helpers/database.go deleted file mode 100644 index 4b33054c..00000000 --- a/modules/test/helpers/database.go +++ /dev/null @@ -1,118 +0,0 @@ -/* -Copyright 2023 Red Hat -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package helpers - -import ( - "github.com/onsi/gomega" - mariadbv1 "github.com/openstack-k8s-operators/mariadb-operator/api/v1beta1" - k8s_errors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" - - corev1 "k8s.io/api/core/v1" -) - -// CreateDBService creates a k8s Service object that matches with the -// Expectations of lib-common database module as a Service for the MariaDB -func (tc *TestHelper) CreateDBService(namespace string, mariadbCRName string, spec corev1.ServiceSpec) types.NamespacedName { - // The Name is used as the hostname to access the service. So - // we generate something unique for the MariaDB CR it represents - // so we can assert that the correct Service is selected. - serviceName := "hostname-for-" + mariadbCRName - service := &corev1.Service{ - ObjectMeta: metav1.ObjectMeta{ - Name: serviceName, - Namespace: namespace, - // NOTE(gibi): The lib-common databvase module looks up the - // Service exposed by MariaDB via these labels. - Labels: map[string]string{ - "app": "mariadb", - "cr": "mariadb-" + mariadbCRName, - }, - }, - Spec: spec, - } - gomega.Expect(tc.K8sClient.Create(tc.Ctx, service)).Should(gomega.Succeed()) - - return types.NamespacedName{Name: serviceName, Namespace: namespace} -} - -// DeleteDBService The function deletes the Service if exists and wait for it to disappear from the API. -// If the Service does not exists then it is assumed to be successfully deleted. -// Example: -// -// th.DeleteDBService(types.NamespacedName{Name: "my-service", Namespace: "my-namespace"}) -// -// or: -// -// DeferCleanup(th.DeleteDBService, th.CreateDBService(cell0.MariaDBDatabaseName.Namespace, cell0.MariaDBDatabaseName.Name, serviceSpec)) -func (tc *TestHelper) DeleteDBService(name types.NamespacedName) { - gomega.Eventually(func(g gomega.Gomega) { - service := &corev1.Service{} - err := tc.K8sClient.Get(tc.Ctx, name, service) - // if it is already gone that is OK - if k8s_errors.IsNotFound(err) { - return - } - g.Expect(err).NotTo(gomega.HaveOccurred()) - - g.Expect(tc.K8sClient.Delete(tc.Ctx, service)).Should(gomega.Succeed()) - - err = tc.K8sClient.Get(tc.Ctx, name, service) - g.Expect(k8s_errors.IsNotFound(err)).To(gomega.BeTrue()) - }, tc.Timeout, tc.Interval).Should(gomega.Succeed()) -} - -// GetMariaDBDatabase waits for and retrieves a MariaDBDatabase resource from the Kubernetes cluster -// -// Example: -// -// mariadbDatabase := th.GetMariaDBDatabase(types.NamespacedName{Name: "my-mariadb-database", Namespace: "my-namespace"}) -func (tc *TestHelper) GetMariaDBDatabase(name types.NamespacedName) *mariadbv1.MariaDBDatabase { - instance := &mariadbv1.MariaDBDatabase{} - gomega.Eventually(func(g gomega.Gomega) { - g.Expect(tc.K8sClient.Get(tc.Ctx, name, instance)).Should(gomega.Succeed()) - }, tc.Timeout, tc.Interval).Should(gomega.Succeed()) - return instance -} - -// SimulateMariaDBDatabaseCompleted simulates a completed state for a MariaDBDatabase resource in a Kubernetes cluster. -// -// Example: -// -// th.SimulateMariaDBDatabaseCompleted(types.NamespacedName{Name: "my-mariadb-database", Namespace: "my-namespace"}) -// -// or -// -// DeferCleanup(th.SimulateMariaDBDatabaseCompleted, types.NamespacedName{Name: "my-mariadb-database", Namespace: "my-namespace"}) -func (tc *TestHelper) SimulateMariaDBDatabaseCompleted(name types.NamespacedName) { - gomega.Eventually(func(g gomega.Gomega) { - db := tc.GetMariaDBDatabase(name) - db.Status.Completed = true - // This can return conflict so we have the gomega.Eventually block to retry - g.Expect(tc.K8sClient.Status().Update(tc.Ctx, db)).To(gomega.Succeed()) - - }, tc.Timeout, tc.Interval).Should(gomega.Succeed()) - - tc.Logger.Info("Simulated DB completed", "on", name) -} - -// AssertMariaDBDatabaseDoesNotExist ensures the MariaDBDatabase resource does not exist in a k8s cluster. -func (tc *TestHelper) AssertMariaDBDatabaseDoesNotExist(name types.NamespacedName) { - instance := &mariadbv1.MariaDBDatabase{} - gomega.Eventually(func(g gomega.Gomega) { - err := tc.K8sClient.Get(tc.Ctx, name, instance) - g.Expect(k8s_errors.IsNotFound(err)).To(gomega.BeTrue()) - }, tc.Timeout, tc.Interval).Should(gomega.Succeed()) -}