Skip to content

Commit

Permalink
Add kuttl tests for the database creation
Browse files Browse the repository at this point in the history
This patch is:

- Adding the base kuttl tests structure
- Adding some make targets to run and cleanup kuttl tests
- Creating kuttl tests for the database creation including with and
  without precreating a MariaDBAccount.

This will be used for a kuttl job that will be added later.
  • Loading branch information
amoralej authored and openshift-merge-bot[bot] committed Nov 22, 2024
1 parent dce7e52 commit d9ad573
Show file tree
Hide file tree
Showing 23 changed files with 305 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ CI_TOOLS_REPO

# CI generated files
ci/olm.yaml
tests/kuttl/test-suites/default/output/*
32 changes: 32 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion api/bases/watcher.openstack.org_watchers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion api/v1beta1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion config/crd/bases/watcher.openstack.org_watchers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions controllers/watcher_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions tests/functional/watcher_test_data.go
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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 (
Expand All @@ -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
Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions tests/kuttl/test-suites/default/03-assert.yaml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions tests/kuttl/test-suites/default/common/cleanup-watcher.yaml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions tests/kuttl/test-suites/default/config.yaml
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions tests/kuttl/test-suites/default/deps/infra.yaml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions tests/kuttl/test-suites/default/deps/keystone.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: core.openstack.org/v1beta1
kind: OpenStackControlPlane
metadata:
name: openstack
spec:
keystone:
template:
databaseInstance: openstack
secret: osp-secret
42 changes: 42 additions & 0 deletions tests/kuttl/test-suites/default/deps/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions tests/kuttl/test-suites/default/deps/namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: watcher-kuttl-default
50 changes: 50 additions & 0 deletions tests/kuttl/test-suites/default/test/01-assert.yaml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: watcher.openstack.org/v1beta1
kind: Watcher
metadata:
name: watcher-kuttl
namespace: watcher-kuttl-default
spec:
databaseInstance: "openstack"
Original file line number Diff line number Diff line change
@@ -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
56 changes: 56 additions & 0 deletions tests/kuttl/test-suites/default/test/04-assert.yaml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions tests/kuttl/test-suites/default/test/05-assert.yaml
Original file line number Diff line number Diff line change
@@ -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 ]
Loading

0 comments on commit d9ad573

Please sign in to comment.