diff --git a/.gitignore b/.gitignore index 955f948..21e180c 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,4 @@ CI_TOOLS_REPO # CI generated files ci/olm.yaml +tests/kuttl/test-suites/default/output/* diff --git a/Makefile b/Makefile index 8754679..a63e46b 100644 --- a/Makefile +++ b/Makefile @@ -396,3 +396,35 @@ watcher_cleanup: export CATALOG_IMG=${CATALOG_IMAGE} watcher_cleanup: ## Cleaning watcher operator via olm bash ci/olm.sh oc delete -f ci/olm.yaml + +KUTTL_SUITE ?= default +KUTTL_NAMESPACE ?= watcher-kuttl-$(KUTTL_SUITE) +KUTTL_SUITE_DIR ?= tests/kuttl/test-suites/$(KUTTL_SUITE) + +.PHONY: kuttl-test-prep +kuttl-test-prep: + oc apply -k $(KUTTL_SUITE_DIR)/deps/ --timeout=120s + oc wait -n $(KUTTL_NAMESPACE) openstackcontrolplane openstack --for condition=Ready --timeout=300s + +.PHONY: kuttl-test-run +kuttl-test-run: + oc kuttl test --v 1 --start-kind=false --config $(KUTTL_SUITE_DIR)/config.yaml + +.PHONY: kuttl-test +kuttl-test: kuttl-test-prep kuttl-test-run + +.PHONY: kuttl-test-cleanup +kuttl-test-cleanup: + # only cleanup if the $(KUTTL_NAMESPACE) exists + $(eval namespace_exists=$(shell oc get namespace $(KUTTL_NAMESPACE) --ignore-not-found -o name)) + # We need to order the deletion. Simply deleting the namespace will + # result in errors in mariadb- and keystone-operator and then + # finalizer removal get stuck blocking the namespace deletion. + if [ "${namespace_exists}" != "" ]; then \ + oc delete --wait=true --all=true -n $(KUTTL_NAMESPACE) --timeout=120s Watcher; \ + oc delete --wait=true --all=true -n $(KUTTL_NAMESPACE) --timeout=120s OpenStackControlPlane; \ + oc delete --wait=true namespace $(KUTTL_NAMESPACE); \ + oc get pv |grep "Released.*crc-csi-hostpath-provisioner"|awk '{print $$1}'|xargs -I {} oc delete pv {} ;\ + else \ + echo "Namespce already cleaned up. Nothing to do"; \ + fi diff --git a/api/bases/watcher.openstack.org_watchers.yaml b/api/bases/watcher.openstack.org_watchers.yaml index 7652d0b..03af3c3 100644 --- a/api/bases/watcher.openstack.org_watchers.yaml +++ b/api/bases/watcher.openstack.org_watchers.yaml @@ -41,7 +41,7 @@ spec: DB, defaults to watcher type: string databaseInstance: - description: MariaDB instance name Required to use the maridb-operator + description: MariaDB instance name Required to use the mariadb-operator instance to create the DB and user type: string passwordSelectors: diff --git a/api/v1beta1/common_types.go b/api/v1beta1/common_types.go index bbde476..b1d422e 100644 --- a/api/v1beta1/common_types.go +++ b/api/v1beta1/common_types.go @@ -33,7 +33,7 @@ type WatcherTemplate struct { // +kubebuilder:validation:Required // MariaDB instance name - // Required to use the maridb-operator instance to create the DB and user + // Required to use the mariadb-operator instance to create the DB and user DatabaseInstance string `json:"databaseInstance"` // +kubebuilder:validation:Optional diff --git a/config/crd/bases/watcher.openstack.org_watchers.yaml b/config/crd/bases/watcher.openstack.org_watchers.yaml index 7652d0b..03af3c3 100644 --- a/config/crd/bases/watcher.openstack.org_watchers.yaml +++ b/config/crd/bases/watcher.openstack.org_watchers.yaml @@ -41,7 +41,7 @@ spec: DB, defaults to watcher type: string databaseInstance: - description: MariaDB instance name Required to use the maridb-operator + description: MariaDB instance name Required to use the mariadb-operator instance to create the DB and user type: string passwordSelectors: diff --git a/controllers/watcher_controller.go b/controllers/watcher_controller.go index 0bfb9ac..7f33bb5 100644 --- a/controllers/watcher_controller.go +++ b/controllers/watcher_controller.go @@ -107,7 +107,7 @@ func (r *WatcherReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re _ = serviceLabels - // Save a copy of the condtions so that we can restore the LastTransitionTime + // Save a copy of the conditions so that we can restore the LastTransitionTime // when a condition's state doesn't change. isNewInstance := instance.Status.Conditions == nil savedConditions := instance.Status.Conditions.DeepCopy() @@ -219,7 +219,7 @@ func (r *WatcherReconciler) ensureDB( Log := r.GetLogger(ctx) Log.Info(fmt.Sprintf("Reconciling the DB instance for '%s'", instance.Name)) - // ensure MariaDBAccount existswithout being yet associated with any database. + // ensure MariaDBAccount exists without being yet associated with any database. // This account record may be created by the openstack-operator up front. _, _, err := mariadbv1.EnsureMariaDBAccount( ctx, h, instance.Spec.DatabaseAccount, diff --git a/tests/functional/watcher_test_data.go b/tests/functional/watcher_test_data.go index 2ec9330..875d0c2 100644 --- a/tests/functional/watcher_test_data.go +++ b/tests/functional/watcher_test_data.go @@ -1,5 +1,5 @@ /* -Copyright 2023. +Copyright 2024. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Package functional implements the envTest coverage for barbican-operator +// Package functional implements the envTest coverage for watcher-operator package functional import ( @@ -27,7 +27,7 @@ import ( type APIType string -// BarbicanTestData is the data structure used to provide input data to envTest +// WatcherTestData is the data structure used to provide input data to envTest type WatcherTestData struct { //DatabaseHostname string DatabaseInstance string @@ -38,7 +38,7 @@ type WatcherTestData struct { WatcherDatabaseAccountSecret types.NamespacedName } -// GetBarbicanTestData is a function that initialize the BarbicanTestData +// GetWatcherTestData is a function that initialize the WatcherTestData // used in the test func GetWatcherTestData(watcherName types.NamespacedName) WatcherTestData { m := watcherName diff --git a/tests/kuttl/test-suites/default/03-assert.yaml b/tests/kuttl/test-suites/default/03-assert.yaml new file mode 100644 index 0000000..fbd3c04 --- /dev/null +++ b/tests/kuttl/test-suites/default/03-assert.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Secret +metadata: + name: watcher-db-secret + namespace: watcher-kuttl-default +--- +apiVersion: mariadb.openstack.org/v1beta1 +kind: MariaDBAccount +metadata: + name: watcher-precreated + namespace: watcher-kuttl-default diff --git a/tests/kuttl/test-suites/default/common/cleanup-watcher.yaml b/tests/kuttl/test-suites/default/common/cleanup-watcher.yaml new file mode 100644 index 0000000..31bb5ab --- /dev/null +++ b/tests/kuttl/test-suites/default/common/cleanup-watcher.yaml @@ -0,0 +1,7 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestStep +delete: +- apiVersion: watcher.openstack.org/v1beta1 + kind: Watcher + name: watcher-kuttl + namespace: watcher-kuttl-default diff --git a/tests/kuttl/test-suites/default/config.yaml b/tests/kuttl/test-suites/default/config.yaml new file mode 100644 index 0000000..65e3755 --- /dev/null +++ b/tests/kuttl/test-suites/default/config.yaml @@ -0,0 +1,14 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestSuite +reportFormat: JSON +reportName: kuttl-default-results +namespace: watcher-kuttl-default +# we could set this lower, but the initial image pull can take a while +timeout: 300 +parallel: 1 +skipDelete: true +testDirs: + - tests/kuttl/test-suites/default/ +suppress: + - events +artifactsDir: tests/kuttl/test-suites/default/output diff --git a/tests/kuttl/test-suites/default/deps/infra.yaml b/tests/kuttl/test-suites/default/deps/infra.yaml new file mode 100644 index 0000000..31b56f9 --- /dev/null +++ b/tests/kuttl/test-suites/default/deps/infra.yaml @@ -0,0 +1,34 @@ +apiVersion: core.openstack.org/v1beta1 +kind: OpenStackControlPlane +metadata: + name: openstack +spec: + storageClass: crc-csi-hostpath-provisioner + mariadb: + enabled: false + galera: + enabled: true + templates: + openstack: + storageRequest: 500M + storageClass: crc-csi-hostpath-provisioner + rabbitmq: + templates: + rabbitmq: + replicas: 1 + memcached: + templates: + memcached: + replicas: 1 + nova: + enabled: false + placement: + enabled: false + neutron: + enabled: false + keystone: + enabled: true + cinder: + enabled: false + telemetry: + enabled: false diff --git a/tests/kuttl/test-suites/default/deps/keystone.yaml b/tests/kuttl/test-suites/default/deps/keystone.yaml new file mode 100644 index 0000000..97f568e --- /dev/null +++ b/tests/kuttl/test-suites/default/deps/keystone.yaml @@ -0,0 +1,9 @@ +apiVersion: core.openstack.org/v1beta1 +kind: OpenStackControlPlane +metadata: + name: openstack +spec: + keystone: + template: + databaseInstance: openstack + secret: osp-secret diff --git a/tests/kuttl/test-suites/default/deps/kustomization.yaml b/tests/kuttl/test-suites/default/deps/kustomization.yaml new file mode 100644 index 0000000..30d1d12 --- /dev/null +++ b/tests/kuttl/test-suites/default/deps/kustomization.yaml @@ -0,0 +1,42 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +namespace: watcher-kuttl-default + +secretGenerator: +- literals: + - AdminPassword=password + - DbRootPassword=password + - DatabasePassword=password + - WatcherPassword=password + - KeystoneDatabasePassword=password + - PlacementPassword=password + - PlacementDatabasePassword=password + - GlancePassword=password + - GlanceDatabasePassword=password + - NeutronPassword=password + - NeutronDatabasePassword=password + - NovaPassword=password + - NovaAPIDatabasePassword=password + - NovaCell0DatabasePassword=password + - NovaCell1DatabasePassword=password + - MetadataSecret=42 + name: osp-secret +generatorOptions: + disableNameSuffixHash: true + labels: + type: osp-secret + +resources: +- namespace.yaml +- infra.yaml + +patches: +- patch: |- + apiVersion: core.openstack.org/v1beta1 + kind: OpenStackControlPlane + metadata: + name: openstack + spec: + secret: osp-secret +- path: infra.yaml +- path: keystone.yaml diff --git a/tests/kuttl/test-suites/default/deps/namespace.yaml b/tests/kuttl/test-suites/default/deps/namespace.yaml new file mode 100644 index 0000000..3be094c --- /dev/null +++ b/tests/kuttl/test-suites/default/deps/namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: watcher-kuttl-default diff --git a/tests/kuttl/test-suites/default/test/00-cleanup-watcher.yaml b/tests/kuttl/test-suites/default/test/00-cleanup-watcher.yaml new file mode 120000 index 0000000..92ed6e0 --- /dev/null +++ b/tests/kuttl/test-suites/default/test/00-cleanup-watcher.yaml @@ -0,0 +1 @@ +../common/cleanup-watcher.yaml \ No newline at end of file diff --git a/tests/kuttl/test-suites/default/test/01-assert.yaml b/tests/kuttl/test-suites/default/test/01-assert.yaml new file mode 100644 index 0000000..9426536 --- /dev/null +++ b/tests/kuttl/test-suites/default/test/01-assert.yaml @@ -0,0 +1,50 @@ +apiVersion: watcher.openstack.org/v1beta1 +kind: Watcher +metadata: + finalizers: + - openstack.org/watcher + name: watcher-kuttl + namespace: watcher-kuttl-default +status: + conditions: + - message: Setup complete + reason: Ready + status: "True" + type: Ready + - message: DB create completed + reason: Ready + status: "True" + type: DBReady + - message: MariaDBAccount creation complete + reason: Ready + status: "True" + type: MariaDBAccountReady +--- +apiVersion: v1 +kind: Secret +metadata: + name: watcher-db-secret + namespace: watcher-kuttl-default + finalizers: + - openstack.org/watcher +--- +apiVersion: mariadb.openstack.org/v1beta1 +kind: MariaDBAccount +metadata: + name: watcher + namespace: watcher-kuttl-default + finalizers: + - openstack.org/watcher + - openstack.org/mariadbaccount + labels: + mariaDBDatabaseName: watcher +--- +apiVersion: mariadb.openstack.org/v1beta1 +kind: MariaDBDatabase +metadata: + name: watcher + namespace: watcher-kuttl-default + finalizers: + - openstack.org/watcher + - openstack.org/mariadbdatabase + - openstack.org/mariadbaccount-watcher diff --git a/tests/kuttl/test-suites/default/test/01-deploy-with-defaults.yaml b/tests/kuttl/test-suites/default/test/01-deploy-with-defaults.yaml new file mode 100644 index 0000000..3b969ba --- /dev/null +++ b/tests/kuttl/test-suites/default/test/01-deploy-with-defaults.yaml @@ -0,0 +1,7 @@ +apiVersion: watcher.openstack.org/v1beta1 +kind: Watcher +metadata: + name: watcher-kuttl + namespace: watcher-kuttl-default +spec: + databaseInstance: "openstack" diff --git a/tests/kuttl/test-suites/default/test/02-cleanup-watcher.yaml b/tests/kuttl/test-suites/default/test/02-cleanup-watcher.yaml new file mode 120000 index 0000000..92ed6e0 --- /dev/null +++ b/tests/kuttl/test-suites/default/test/02-cleanup-watcher.yaml @@ -0,0 +1 @@ +../common/cleanup-watcher.yaml \ No newline at end of file diff --git a/tests/kuttl/test-suites/default/test/03-precreate-mariadbaccount.yaml b/tests/kuttl/test-suites/default/test/03-precreate-mariadbaccount.yaml new file mode 100644 index 0000000..cb94f3b --- /dev/null +++ b/tests/kuttl/test-suites/default/test/03-precreate-mariadbaccount.yaml @@ -0,0 +1,9 @@ +apiVersion: mariadb.openstack.org/v1beta1 +kind: MariaDBAccount +metadata: + name: watcher-precreated + namespace: watcher-kuttl-default +spec: + requireTLS: false + secret: watcher-db-secret + userName: watcher_test diff --git a/tests/kuttl/test-suites/default/test/04-assert.yaml b/tests/kuttl/test-suites/default/test/04-assert.yaml new file mode 100644 index 0000000..3a4c03a --- /dev/null +++ b/tests/kuttl/test-suites/default/test/04-assert.yaml @@ -0,0 +1,56 @@ +apiVersion: watcher.openstack.org/v1beta1 +kind: Watcher +metadata: + finalizers: + - openstack.org/watcher + name: watcher-kuttl + namespace: watcher-kuttl-default +spec: + databaseAccount: watcher-precreated + databaseInstance: openstack + passwordSelectors: + service: WatcherPassword + secret: osp-secret +status: + conditions: + - message: Setup complete + reason: Ready + status: "True" + type: Ready + - message: DB create completed + reason: Ready + status: "True" + type: DBReady + - message: MariaDBAccount creation complete + reason: Ready + status: "True" + type: MariaDBAccountReady +--- +apiVersion: v1 +kind: Secret +metadata: + name: watcher-db-secret + namespace: watcher-kuttl-default + finalizers: + - openstack.org/watcher +--- +apiVersion: mariadb.openstack.org/v1beta1 +kind: MariaDBAccount +metadata: + name: watcher-precreated + namespace: watcher-kuttl-default + finalizers: + - openstack.org/watcher + - openstack.org/mariadbaccount + labels: + mariaDBDatabaseName: watcher +--- +apiVersion: mariadb.openstack.org/v1beta1 +kind: MariaDBDatabase +metadata: + name: watcher + namespace: watcher-kuttl-default + finalizers: + - openstack.org/watcher + - openstack.org/mariadbdatabase + - openstack.org/mariadbaccount-watcher-precreated diff --git a/tests/kuttl/test-suites/default/test/04-deploy-with-precreated-account.yaml b/tests/kuttl/test-suites/default/test/04-deploy-with-precreated-account.yaml new file mode 100644 index 0000000..6cda9cf --- /dev/null +++ b/tests/kuttl/test-suites/default/test/04-deploy-with-precreated-account.yaml @@ -0,0 +1,8 @@ +apiVersion: watcher.openstack.org/v1beta1 +kind: Watcher +metadata: + name: watcher-kuttl + namespace: watcher-kuttl-default +spec: + databaseInstance: "openstack" + databaseAccount: watcher-precreated diff --git a/tests/kuttl/test-suites/default/test/05-assert.yaml b/tests/kuttl/test-suites/default/test/05-assert.yaml new file mode 100644 index 0000000..59bb51e --- /dev/null +++ b/tests/kuttl/test-suites/default/test/05-assert.yaml @@ -0,0 +1,9 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestAssert +namespaced: true +commands: + - script: | + set -ex + oc get mariadbaccount -n watcher-kuttl-default --no-headers=true | [ $(grep -c ^watcher) == 0 ] + oc get mariadbdatabase -n watcher-kuttl-default --no-headers=true | [ $(grep -c ^watcher) == 0 ] + oc get secret -n watcher-kuttl-default --no-headers=true | [ $(grep -c ^watcher) == 0 ] diff --git a/tests/kuttl/test-suites/default/test/05-cleanup-watcher.yaml b/tests/kuttl/test-suites/default/test/05-cleanup-watcher.yaml new file mode 120000 index 0000000..92ed6e0 --- /dev/null +++ b/tests/kuttl/test-suites/default/test/05-cleanup-watcher.yaml @@ -0,0 +1 @@ +../common/cleanup-watcher.yaml \ No newline at end of file