From 7011a4c69403fcb32d0e53031bd94ab312db5c3c Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 29 Jan 2024 13:13:16 -0500 Subject: [PATCH] migrate from databaseUsername to databaseAccount --- .../glance.openstack.org_glanceapis.yaml | 10 +- api/bases/glance.openstack.org_glances.yaml | 10 +- api/v1beta1/glance_types.go | 16 +-- api/v1beta1/glanceapi_types.go | 7 +- .../glance.openstack.org_glanceapis.yaml | 10 +- .../bases/glance.openstack.org_glances.yaml | 10 +- config/samples/backends/ceph/ceph.yaml | 2 +- .../backends/multistore/multistore.yaml | 2 +- config/samples/glance_v1beta1_glance.yaml | 2 +- config/samples/glance_v1beta1_glanceapi.yaml | 2 +- config/samples/image_cache/image-cache.yaml | 2 +- .../image_conversion/image_conversion.yaml | 2 +- .../image_decompression.yaml | 2 +- .../inject_metadata/inject_metadata.yaml | 2 +- .../layout/base/glance_v1beta1_glance.yaml | 2 +- .../layout/edge/glance_v1beta1_glance.yaml | 2 +- .../multiple/glance_v1beta1_glance.yaml | 2 +- .../layout/single/glance_v1beta1_glance.yaml | 2 +- .../single_tls/glance_v1beta1_glance.yaml | 2 +- .../glance_v1beta_glance_apply_policy.yaml | 2 +- .../quotas/glance_v1beta1_glance_quota.yaml | 2 +- controllers/glance_controller.go | 68 ++++++++----- controllers/glanceapi_controller.go | 9 +- go.mod | 2 +- go.sum | 4 +- pkg/glance/const.go | 5 +- test/functional/base_test.go | 17 ++-- test/functional/glance_controller_test.go | 98 +++++++++++++++--- test/functional/glance_test_data.go | 15 ++- test/functional/glanceapi_controller_test.go | 99 ++++++++++--------- test/functional/suite_test.go | 1 + .../tests/glance_image_cache/01-assert.yaml | 2 +- .../tests/glance_image_cache/02-assert.yaml | 2 +- .../tests/glance_image_cache/03-assert.yaml | 2 +- test/kuttl/tests/glance_single/01-assert.yaml | 5 +- test/kuttl/tests/glance_split/01-assert.yaml | 8 +- 36 files changed, 263 insertions(+), 167 deletions(-) diff --git a/api/bases/glance.openstack.org_glanceapis.yaml b/api/bases/glance.openstack.org_glanceapis.yaml index 061f91d2..5ff62cc3 100644 --- a/api/bases/glance.openstack.org_glanceapis.yaml +++ b/api/bases/glance.openstack.org_glanceapis.yaml @@ -56,11 +56,11 @@ spec: items: type: string type: array - databaseHostname: - type: string - databaseUser: + databaseAccount: default: glance type: string + databaseHostname: + type: string extraMounts: items: properties: @@ -895,12 +895,8 @@ spec: type: object passwordSelectors: default: - database: GlanceDatabasePassword service: GlancePassword properties: - database: - default: GlanceDatabasePassword - type: string service: default: GlancePassword type: string diff --git a/api/bases/glance.openstack.org_glances.yaml b/api/bases/glance.openstack.org_glances.yaml index 752cb95c..1df132a9 100644 --- a/api/bases/glance.openstack.org_glances.yaml +++ b/api/bases/glance.openstack.org_glances.yaml @@ -44,11 +44,11 @@ spec: items: type: string type: array - databaseInstance: - type: string - databaseUser: + databaseAccount: default: glance type: string + databaseInstance: + type: string dbPurge: properties: age: @@ -998,12 +998,8 @@ spec: type: object passwordSelectors: default: - database: GlanceDatabasePassword service: GlancePassword properties: - database: - default: GlanceDatabasePassword - type: string service: default: GlancePassword type: string diff --git a/api/v1beta1/glance_types.go b/api/v1beta1/glance_types.go index eb8a4111..59535099 100644 --- a/api/v1beta1/glance_types.go +++ b/api/v1beta1/glance_types.go @@ -50,9 +50,8 @@ type GlanceSpecCore struct { // +kubebuilder:validation:Optional // +kubebuilder:default=glance - // DatabaseUser - optional username used for glance DB, defaults to glance - // TODO: -> implement needs work in mariadb-operator, right now only glance - DatabaseUser string `json:"databaseUser"` + // DatabaseAccount - name of MariaDBAccount which will be used to connect. + DatabaseAccount string `json:"databaseAccount"` // +kubebuilder:validation:Required // +kubebuilder:default=memcached @@ -60,11 +59,12 @@ type GlanceSpecCore struct { MemcachedInstance string `json:"memcachedInstance"` // +kubebuilder:validation:Required - // Secret containing OpenStack password information for glance GlanceDatabasePassword + // Secret containing OpenStack password information for glance's keystone + // password; no longer used for database password Secret string `json:"secret"` // +kubebuilder:validation:Optional - // +kubebuilder:default={database: GlanceDatabasePassword, service: GlancePassword} + // +kubebuilder:default={service: GlancePassword} // PasswordSelectors - Selectors to identify the DB and ServiceUser password from the Secret PasswordSelectors PasswordSelector `json:"passwordSelectors"` @@ -139,11 +139,6 @@ type GlanceSpec struct { // PasswordSelector to identify the DB and AdminUser password from the Secret type PasswordSelector struct { - // +kubebuilder:validation:Optional - // +kubebuilder:default="GlanceDatabasePassword" - // Database - Selector to get the glance database user password from the Secret - // TODO: not used, need change in mariadb-operator - Database string `json:"database"` // +kubebuilder:validation:Optional // +kubebuilder:default="GlancePassword" // Service - Selector to get the glance service password from the Secret @@ -163,7 +158,6 @@ type DBPurge struct { Schedule string `json:"schedule"` } - // GlanceStatus defines the observed state of Glance type GlanceStatus struct { // Map of hashes to track e.g. job status diff --git a/api/v1beta1/glanceapi_types.go b/api/v1beta1/glanceapi_types.go index ca352823..050afcf0 100644 --- a/api/v1beta1/glanceapi_types.go +++ b/api/v1beta1/glanceapi_types.go @@ -55,16 +55,15 @@ type GlanceAPISpec struct { // +kubebuilder:validation:Optional // +kubebuilder:default=glance - // DatabaseUser - optional username used for glance DB, defaults to glance - // TODO: -> implement needs work in mariadb-operator, right now only glance - DatabaseUser string `json:"databaseUser"` + // DatabaseAccount - name of MariaDBAccount which will be used to connect. + DatabaseAccount string `json:"databaseAccount"` // +kubebuilder:validation:Required // Secret containing OpenStack password information for glance AdminPassword Secret string `json:"secret"` // +kubebuilder:validation:Optional - // +kubebuilder:default={database: GlanceDatabasePassword, service: GlancePassword} + // +kubebuilder:default={service: GlancePassword} // PasswordSelectors - Selectors to identify the DB and ServiceUser password from the Secret PasswordSelectors PasswordSelector `json:"passwordSelectors"` diff --git a/config/crd/bases/glance.openstack.org_glanceapis.yaml b/config/crd/bases/glance.openstack.org_glanceapis.yaml index 061f91d2..5ff62cc3 100644 --- a/config/crd/bases/glance.openstack.org_glanceapis.yaml +++ b/config/crd/bases/glance.openstack.org_glanceapis.yaml @@ -56,11 +56,11 @@ spec: items: type: string type: array - databaseHostname: - type: string - databaseUser: + databaseAccount: default: glance type: string + databaseHostname: + type: string extraMounts: items: properties: @@ -895,12 +895,8 @@ spec: type: object passwordSelectors: default: - database: GlanceDatabasePassword service: GlancePassword properties: - database: - default: GlanceDatabasePassword - type: string service: default: GlancePassword type: string diff --git a/config/crd/bases/glance.openstack.org_glances.yaml b/config/crd/bases/glance.openstack.org_glances.yaml index 752cb95c..1df132a9 100644 --- a/config/crd/bases/glance.openstack.org_glances.yaml +++ b/config/crd/bases/glance.openstack.org_glances.yaml @@ -44,11 +44,11 @@ spec: items: type: string type: array - databaseInstance: - type: string - databaseUser: + databaseAccount: default: glance type: string + databaseInstance: + type: string dbPurge: properties: age: @@ -998,12 +998,8 @@ spec: type: object passwordSelectors: default: - database: GlanceDatabasePassword service: GlancePassword properties: - database: - default: GlanceDatabasePassword - type: string service: default: GlancePassword type: string diff --git a/config/samples/backends/ceph/ceph.yaml b/config/samples/backends/ceph/ceph.yaml index c48a49b4..e159b23d 100644 --- a/config/samples/backends/ceph/ceph.yaml +++ b/config/samples/backends/ceph/ceph.yaml @@ -19,7 +19,7 @@ spec: rbd_store_pool = images rbd_store_user = openstack databaseInstance: openstack - databaseUser: glance + databaseAccount: glance secret: osp-secret storageClass: "" storageRequest: 1G diff --git a/config/samples/backends/multistore/multistore.yaml b/config/samples/backends/multistore/multistore.yaml index 104aa5d9..f2b1d719 100644 --- a/config/samples/backends/multistore/multistore.yaml +++ b/config/samples/backends/multistore/multistore.yaml @@ -30,7 +30,7 @@ spec: swift_store_user = service:glance swift_store_endpoint_type = internalURL databaseInstance: openstack - databaseUser: glance + databaseAccount: glance glanceAPIs: default: preserveJobs: false diff --git a/config/samples/glance_v1beta1_glance.yaml b/config/samples/glance_v1beta1_glance.yaml index ba194636..e203abbe 100644 --- a/config/samples/glance_v1beta1_glance.yaml +++ b/config/samples/glance_v1beta1_glance.yaml @@ -9,7 +9,7 @@ spec: debug = true enabled_backends=foo:bar,foo1:bar1 databaseInstance: openstack - databaseUser: glance + databaseAccount: glance secret: osp-secret storageClass: local-storage storageRequest: 10G diff --git a/config/samples/glance_v1beta1_glanceapi.yaml b/config/samples/glance_v1beta1_glanceapi.yaml index f5214042..45ab612f 100644 --- a/config/samples/glance_v1beta1_glanceapi.yaml +++ b/config/samples/glance_v1beta1_glanceapi.yaml @@ -15,7 +15,7 @@ spec: here-foo-config [foo1] here-foo1-config - databaseUser: glance + databaseAccount: glance databaseHostname: glance preserveJobs: false replicas: 1 diff --git a/config/samples/image_cache/image-cache.yaml b/config/samples/image_cache/image-cache.yaml index 626f0624..d0471f10 100644 --- a/config/samples/image_cache/image-cache.yaml +++ b/config/samples/image_cache/image-cache.yaml @@ -21,7 +21,7 @@ spec: store_description = "RBD backend" rbd_store_pool = images rbd_store_user = openstack - databaseUser: glance + databaseAccount: glance glanceAPIs: default: preserveJobs: false diff --git a/config/samples/import_plugins/image_conversion/image_conversion.yaml b/config/samples/import_plugins/image_conversion/image_conversion.yaml index f2243947..3c2277a3 100644 --- a/config/samples/import_plugins/image_conversion/image_conversion.yaml +++ b/config/samples/import_plugins/image_conversion/image_conversion.yaml @@ -24,7 +24,7 @@ spec: [image_conversion] output_format = raw databaseInstance: openstack - databaseUser: glance + databaseAccount: glance glanceAPI: preserveJobs: false replicas: 1 diff --git a/config/samples/import_plugins/image_decompression/image_decompression.yaml b/config/samples/import_plugins/image_decompression/image_decompression.yaml index b4ce5b02..4a7ed234 100644 --- a/config/samples/import_plugins/image_decompression/image_decompression.yaml +++ b/config/samples/import_plugins/image_decompression/image_decompression.yaml @@ -21,7 +21,7 @@ spec: [image_import_opts] image_import_plugins = [image_decompression] databaseInstance: openstack - databaseUser: glance + databaseAccount: glance glanceAPI: preserveJobs: false replicas: 1 diff --git a/config/samples/import_plugins/inject_metadata/inject_metadata.yaml b/config/samples/import_plugins/inject_metadata/inject_metadata.yaml index fbd98196..52b67b9f 100644 --- a/config/samples/import_plugins/inject_metadata/inject_metadata.yaml +++ b/config/samples/import_plugins/inject_metadata/inject_metadata.yaml @@ -24,7 +24,7 @@ spec: ignore_user_roles = admin,user1 inject = "property1":"value1","property2":"value2" databaseInstance: openstack - databaseUser: glance + databaseAccount: glance glanceAPI: preserveJobs: false replicas: 1 diff --git a/config/samples/layout/base/glance_v1beta1_glance.yaml b/config/samples/layout/base/glance_v1beta1_glance.yaml index e0167f03..7291a575 100644 --- a/config/samples/layout/base/glance_v1beta1_glance.yaml +++ b/config/samples/layout/base/glance_v1beta1_glance.yaml @@ -9,7 +9,7 @@ spec: debug = true enabled_backends=foo:bar databaseInstance: openstack - databaseUser: glance + databaseAccount: glance secret: osp-secret storageClass: local-storage storageRequest: 10G diff --git a/config/samples/layout/edge/glance_v1beta1_glance.yaml b/config/samples/layout/edge/glance_v1beta1_glance.yaml index 09506257..d260acf7 100644 --- a/config/samples/layout/edge/glance_v1beta1_glance.yaml +++ b/config/samples/layout/edge/glance_v1beta1_glance.yaml @@ -8,7 +8,7 @@ spec: [DEFAULT] debug = true databaseInstance: openstack - databaseUser: glance + databaseAccount: glance keystoneEndpoint: central glanceAPIs: central: diff --git a/config/samples/layout/multiple/glance_v1beta1_glance.yaml b/config/samples/layout/multiple/glance_v1beta1_glance.yaml index f4aac6bc..3d56d97e 100644 --- a/config/samples/layout/multiple/glance_v1beta1_glance.yaml +++ b/config/samples/layout/multiple/glance_v1beta1_glance.yaml @@ -8,7 +8,7 @@ spec: [DEFAULT] debug = true databaseInstance: openstack - databaseUser: glance + databaseAccount: glance keystoneEndpoint: api1 glanceAPIs: api1: diff --git a/config/samples/layout/single/glance_v1beta1_glance.yaml b/config/samples/layout/single/glance_v1beta1_glance.yaml index b5034a56..9d4b4751 100644 --- a/config/samples/layout/single/glance_v1beta1_glance.yaml +++ b/config/samples/layout/single/glance_v1beta1_glance.yaml @@ -5,7 +5,7 @@ metadata: spec: serviceUser: glance databaseInstance: openstack - databaseUser: glance + databaseAccount: glance keystoneEndpoint: default customServiceConfig: | [DEFAULT] diff --git a/config/samples/layout/single_tls/glance_v1beta1_glance.yaml b/config/samples/layout/single_tls/glance_v1beta1_glance.yaml index 732ce4fb..31c80ad9 100644 --- a/config/samples/layout/single_tls/glance_v1beta1_glance.yaml +++ b/config/samples/layout/single_tls/glance_v1beta1_glance.yaml @@ -5,7 +5,7 @@ metadata: spec: serviceUser: glance databaseInstance: openstack - databaseUser: glance + databaseAccount: glance keystoneEndpoint: default customServiceConfig: | [DEFAULT] diff --git a/config/samples/policy/glance_v1beta_glance_apply_policy.yaml b/config/samples/policy/glance_v1beta_glance_apply_policy.yaml index 91e4d6a0..4e0e2dfc 100644 --- a/config/samples/policy/glance_v1beta_glance_apply_policy.yaml +++ b/config/samples/policy/glance_v1beta_glance_apply_policy.yaml @@ -10,7 +10,7 @@ spec: enforce_scope=true enforce_new_defaults=true databaseInstance: openstack - databaseUser: glance + databaseAccount: glance glanceAPI: preserveJobs: false replicas: 1 diff --git a/config/samples/quotas/glance_v1beta1_glance_quota.yaml b/config/samples/quotas/glance_v1beta1_glance_quota.yaml index 62d54869..d2a9754c 100644 --- a/config/samples/quotas/glance_v1beta1_glance_quota.yaml +++ b/config/samples/quotas/glance_v1beta1_glance_quota.yaml @@ -6,7 +6,7 @@ metadata: spec: serviceUser: glance databaseInstance: openstack - databaseUser: glance + databaseAccount: glance keystoneEndpoint: default glanceAPIs: default: diff --git a/controllers/glance_controller.go b/controllers/glance_controller.go index 1cbdb8f8..fd129cf4 100644 --- a/controllers/glance_controller.go +++ b/controllers/glance_controller.go @@ -21,7 +21,6 @@ import ( "fmt" "time" - "github.com/openstack-k8s-operators/lib-common/modules/common/secret" "github.com/openstack-k8s-operators/lib-common/modules/common/tls" rbacv1 "k8s.io/api/rbac/v1" k8s_errors "k8s.io/apimachinery/pkg/api/errors" @@ -300,7 +299,7 @@ func (r *GlanceReconciler) reconcileDelete(ctx context.Context, instance *glance r.Log.Info(fmt.Sprintf("Reconciling Service '%s' delete", instance.Name)) // remove db finalizer first - db, err := mariadbv1.GetDatabaseByName(ctx, helper, instance.Name) + db, err := mariadbv1.GetDatabaseByNameAndAccount(ctx, helper, glance.DatabaseName, instance.Spec.DatabaseAccount, instance.Namespace) if err != nil && !k8s_errors.IsNotFound(err) { return ctrl.Result{}, err } @@ -678,6 +677,12 @@ func (r *GlanceReconciler) reconcileNormal(ctx context.Context, instance *glance return ctrl.Result{}, err } + // remove finalizers from unused MariaDBAccount records + err = mariadbv1.DeleteUnusedMariaDBAccountFinalizers(ctx, helper, instance.Name, instance.Spec.DatabaseAccount, instance.Namespace) + if err != nil { + return ctrl.Result{}, err + } + // create DBPurge CronJob // DBPurge is not optional and always created to purge all soft deleted @@ -846,7 +851,7 @@ func (r *GlanceReconciler) apiDeploymentCreateOrUpdate( GlanceAPITemplate: apiTemplate, APIType: apiType, DatabaseHostname: instance.Status.DatabaseHostname, - DatabaseUser: instance.Spec.DatabaseUser, + DatabaseAccount: instance.Spec.DatabaseAccount, Secret: instance.Spec.Secret, ExtraMounts: instance.Spec.ExtraMounts, PasswordSelectors: instance.Spec.PasswordSelectors, @@ -933,18 +938,16 @@ func (r *GlanceReconciler) generateServiceConfig( ) error { labels := labels.GetLabels(instance, labels.GetGroupLabel(glance.ServiceName), serviceLabels) - ospSecret, _, err := secret.GetSecret(ctx, h, instance.Spec.Secret, instance.Namespace) - if err != nil { - return err - } + databaseAccount := db.GetAccount() + dbSecret := db.GetSecret() // We only need a minimal 00-config.conf that is only used by db-sync job, // hence only passing the database related parameters templateParameters := map[string]interface{}{ "MinimalConfig": true, // This tells the template to generate a minimal config "DatabaseConnection": fmt.Sprintf("mysql+pymysql://%s:%s@%s/%s?read_default_file=/etc/my.cnf", - instance.Spec.DatabaseUser, - string(ospSecret.Data[instance.Spec.PasswordSelectors.Database]), + databaseAccount.Spec.UserName, + string(dbSecret.Data[mariadbv1.DatabasePasswordSelector]), instance.Status.DatabaseHostname, glance.DatabaseName, ), @@ -1130,24 +1133,45 @@ func (r *GlanceReconciler) ensureDB( h *helper.Helper, instance *glancev1.Glance, ) (*mariadbv1.Database, ctrl.Result, error) { - // + // ensure a MariaDBAccount CR and Secret exist. + // this mariadb API function will as an interim step actually generate a + // new MariaDBAccount and Secret if one does not exist already. in a + // future release, this function may change to emit an error if the + // MariaDBAccount was not already created ahead of time (e.g. by openstack-operator + // or end-user YAML declaration) + _, _, err := mariadbv1.EnsureMariaDBAccount( + ctx, h, instance.Spec.DatabaseAccount, + instance.Namespace, false, "glance", + ) + + if err != nil { + instance.Status.Conditions.Set(condition.FalseCondition( + mariadbv1.MariaDBAccountReadyCondition, + condition.ErrorReason, + condition.SeverityWarning, + mariadbv1.MariaDBAccountNotReadyMessage, + err.Error())) + + return nil, ctrl.Result{}, err + } + instance.Status.Conditions.MarkTrue( + mariadbv1.MariaDBAccountReadyCondition, + mariadbv1.MariaDBAccountReadyMessage, + ) + // create service DB instance // - db := mariadbv1.NewDatabase( - instance.Name, - instance.Spec.DatabaseUser, - instance.Spec.Secret, - map[string]string{ - "dbName": instance.Spec.DatabaseInstance, - }, + db := mariadbv1.NewDatabaseForAccount( + instance.Spec.DatabaseInstance, // mariadb/galera service to target + glance.DatabaseName, // name used in CREATE DATABASE in mariadb + glance.DatabaseName, // CR name for MariaDBDatabase + instance.Spec.DatabaseAccount, // CR name for MariaDBAccount + instance.Namespace, // namespace ) // create or patch the DB - ctrlResult, err := db.CreateOrPatchDBByName( - ctx, - h, - instance.Spec.DatabaseInstance, - ) + ctrlResult, err := db.CreateOrPatchAll(ctx, h) + if err != nil { instance.Status.Conditions.Set(condition.FalseCondition( condition.DBReadyCondition, diff --git a/controllers/glanceapi_controller.go b/controllers/glanceapi_controller.go index a2f9d7a1..d26e8bcc 100644 --- a/controllers/glanceapi_controller.go +++ b/controllers/glanceapi_controller.go @@ -827,7 +827,7 @@ func (r *GlanceAPIReconciler) generateServiceConfig( ) error { labels := labels.GetLabels(instance, labels.GetGroupLabel(glance.ServiceName), GetServiceLabels(instance)) - db, err := mariadbv1.GetDatabaseByName(ctx, h, glance.DatabaseName) + db, err := mariadbv1.GetDatabaseByNameAndAccount(ctx, h, glance.DatabaseName, instance.Spec.DatabaseAccount, instance.Namespace) if err != nil { return err } @@ -874,6 +874,9 @@ func (r *GlanceAPIReconciler) generateServiceConfig( return err } + databaseAccount := db.GetAccount() + dbSecret := db.GetSecret() + glanceEndpoints := glanceapi.GetGlanceEndpoints(instance.Spec.APIType) httpdVhostConfig := map[string]interface{}{} for endpt := range glanceEndpoints { @@ -894,8 +897,8 @@ func (r *GlanceAPIReconciler) generateServiceConfig( "KeystoneInternalURL": keystoneInternalURL, "KeystonePublicURL": keystonePublicURL, "DatabaseConnection": fmt.Sprintf("mysql+pymysql://%s:%s@%s/%s?read_default_file=/etc/my.cnf", - instance.Spec.DatabaseUser, - string(ospSecret.Data[instance.Spec.PasswordSelectors.Database]), + databaseAccount.Spec.UserName, + string(dbSecret.Data[mariadbv1.DatabasePasswordSelector]), instance.Spec.DatabaseHostname, glance.DatabaseName, ), diff --git a/go.mod b/go.mod index 2f401c14..d2fe17c9 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/openstack-k8s-operators/lib-common/modules/openstack v0.3.1-0.20240229121803-169ced56d56e github.com/openstack-k8s-operators/lib-common/modules/storage v0.3.1-0.20240229121803-169ced56d56e github.com/openstack-k8s-operators/lib-common/modules/test v0.3.1-0.20240229121803-169ced56d56e - github.com/openstack-k8s-operators/mariadb-operator/api v0.3.1-0.20240222094307-76fef735f093 + github.com/openstack-k8s-operators/mariadb-operator/api v0.3.1-0.20240303091826-438dde8600d3 golang.org/x/exp v0.0.0-20240213143201-ec583247a57a gopkg.in/yaml.v3 v3.0.1 k8s.io/api v0.28.7 diff --git a/go.sum b/go.sum index 118de046..f64fed2d 100644 --- a/go.sum +++ b/go.sum @@ -105,8 +105,8 @@ github.com/openstack-k8s-operators/lib-common/modules/storage v0.3.1-0.202402291 github.com/openstack-k8s-operators/lib-common/modules/storage v0.3.1-0.20240229121803-169ced56d56e/go.mod h1:hKoDyLpp/Hc6fE1rYhlgXw8pYUPyRDKLgBrkAda5IPA= github.com/openstack-k8s-operators/lib-common/modules/test v0.3.1-0.20240229121803-169ced56d56e h1:rbVGqqtxuJy/RvSVERJG6ZLahbJguOZzPRUpGNT1k38= github.com/openstack-k8s-operators/lib-common/modules/test v0.3.1-0.20240229121803-169ced56d56e/go.mod h1:/ZkLOznBDxjChwIFFK3xg3EZ13WmZPP4ehu5wWy1T8E= -github.com/openstack-k8s-operators/mariadb-operator/api v0.3.1-0.20240222094307-76fef735f093 h1:gmm2o5bVYIeuAVHp7WsDIpQc8vh+/9tUUYY4Wfyus/o= -github.com/openstack-k8s-operators/mariadb-operator/api v0.3.1-0.20240222094307-76fef735f093/go.mod h1:f9IIyWeoskWoeWaDFF3qmAJ2Kqyovfi0Ar/QUfk3qag= +github.com/openstack-k8s-operators/mariadb-operator/api v0.3.1-0.20240303091826-438dde8600d3 h1:fwb+GvvnN9Mhkgg5pBksZ8W5+hLCcNOorHsUTQYA1Lg= +github.com/openstack-k8s-operators/mariadb-operator/api v0.3.1-0.20240303091826-438dde8600d3/go.mod h1:f9IIyWeoskWoeWaDFF3qmAJ2Kqyovfi0Ar/QUfk3qag= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= diff --git a/pkg/glance/const.go b/pkg/glance/const.go index 940c5074..e06c7149 100644 --- a/pkg/glance/const.go +++ b/pkg/glance/const.go @@ -30,7 +30,10 @@ const ( ServiceName = "glance" // ServiceType - ServiceType = "image" - // DatabaseName - + // DatabaseName - this is both the CR name for the MariaDBDatabase + // as well as the name used in MariaDB CREATE DATABASE statement. + // hardcoded as glanceapi_controller needs this name which originates + // from glance_controller, and is not otherwise passed between them DatabaseName = "glance" // Component - Component = "glance-api" diff --git a/test/functional/base_test.go b/test/functional/base_test.go index 61278488..54442dda 100644 --- a/test/functional/base_test.go +++ b/test/functional/base_test.go @@ -68,6 +68,7 @@ func CreateDefaultGlance(name types.NamespacedName) client.Object { "memcachedInstance": "memcached", "keystoneEndpoint": "default", "databaseInstance": "openstack", + "databaseAccount": glanceTest.GlanceDatabaseAccount.Name, "storageRequest": glanceTest.GlancePVCSize, "glanceAPIs": GetAPIList(), }, @@ -91,7 +92,7 @@ func GetGlanceDefaultSpec() map[string]interface{} { return map[string]interface{}{ "keystoneEndpoint": "default", "databaseInstance": "openstack", - "databaseUser": glanceTest.GlanceDatabaseUser, + "databaseAccount": glanceTest.GlanceDatabaseAccount.Name, "serviceUser": glanceName.Name, "secret": SecretName, "glanceAPIs": GetAPIList(), @@ -103,7 +104,7 @@ func GetGlanceDefaultSpecWithQuota() map[string]interface{} { return map[string]interface{}{ "keystoneEndpoint": "default", "databaseInstance": "openstack", - "databaseUser": glanceTest.GlanceDatabaseUser, + "databaseAccount": glanceTest.GlanceDatabaseAccount.Name, "serviceUser": glanceName.Name, "secret": SecretName, "glanceAPIs": GetAPIList(), @@ -123,8 +124,9 @@ func GetAPIList() map[string]interface{} { func GetGlanceAPIDefaultSpec(apiType APIType) map[string]interface{} { return map[string]interface{}{ - "replicas": 1, - "storageRequest": glanceTest.GlancePVCSize, + "replicas": 1, + "storageRequest": glanceTest.GlancePVCSize, + "databaseAccount": glanceTest.GlanceDatabaseAccount.Name, } } @@ -162,8 +164,7 @@ func CreateGlanceSecret(namespace string, name string) *corev1.Secret { return th.CreateSecret( types.NamespacedName{Namespace: namespace, Name: name}, map[string][]byte{ - "GlancePassword": []byte(glanceTest.GlancePassword), - "GlanceDatabasePassword": []byte(glanceTest.GlancePassword), + "GlancePassword": []byte(glanceTest.GlancePassword), }, ) } @@ -172,6 +173,7 @@ func GetDefaultGlanceSpec() map[string]interface{} { return map[string]interface{}{ "databaseInstance": "openstack", "secret": SecretName, + "databaseAccount": glanceTest.GlanceDatabaseAccount.Name, "glanceAPIs": GetAPIList(), } } @@ -186,6 +188,7 @@ func CreateGlanceAPISpec(apiType APIType) map[string]interface{} { "name": "default", "databaseHostname": "openstack", "secret": SecretName, + "databaseAccount": glanceTest.GlanceDatabaseAccount.Name, } return spec } @@ -200,6 +203,7 @@ func GetDefaultGlanceAPISpec(apiType APIType) map[string]interface{} { "name": "default", "databaseHostname": "openstack", "secret": SecretName, + "databaseAccount": glanceTest.GlanceDatabaseAccount.Name, } return spec } @@ -208,6 +212,7 @@ func GetTLSGlanceAPISpec(apiType APIType) map[string]interface{} { spec := CreateGlanceAPISpec(apiType) maps.Copy(spec, map[string]interface{}{ "databaseHostname": "openstack", + "databaseAccount": glanceTest.GlanceDatabaseAccount.Name, "secret": SecretName, "tls": map[string]interface{}{ "api": map[string]interface{}{ diff --git a/test/functional/glance_controller_test.go b/test/functional/glance_controller_test.go index bbc67f06..02a7480f 100644 --- a/test/functional/glance_controller_test.go +++ b/test/functional/glance_controller_test.go @@ -27,7 +27,9 @@ import ( memcachedv1 "github.com/openstack-k8s-operators/infra-operator/apis/memcached/v1beta1" "github.com/openstack-k8s-operators/lib-common/modules/common/condition" util "github.com/openstack-k8s-operators/lib-common/modules/common/util" + mariadb_test "github.com/openstack-k8s-operators/mariadb-operator/api/test/helpers" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/types" ptr "k8s.io/utils/ptr" ) @@ -67,7 +69,7 @@ var _ = Describe("Glance controller", func() { It("initializes Spec fields", func() { Glance := GetGlance(glanceTest.Instance) Expect(Glance.Spec.DatabaseInstance).Should(Equal("openstack")) - Expect(Glance.Spec.DatabaseUser).Should(Equal(glanceTest.GlanceDatabaseUser)) + Expect(Glance.Spec.DatabaseAccount).Should(Equal(glanceTest.GlanceDatabaseAccount.Name)) Expect(Glance.Spec.ServiceUser).Should(Equal(glanceTest.GlanceServiceUser)) Expect(Glance.Spec.MemcachedInstance).Should(Equal(glanceTest.MemcachedInstance)) // No Keystone Quota is present, check the default is 0 @@ -155,8 +157,8 @@ var _ = Describe("Glance controller", func() { ) }) It("Should set DBReady Condition and set DatabaseHostname Status when DB is Created", func() { - mariadb.SimulateMariaDBAccountCompleted(glanceTest.Instance) - mariadb.SimulateMariaDBDatabaseCompleted(glanceTest.Instance) + mariadb.SimulateMariaDBDatabaseCompleted(glanceTest.GlanceDatabaseName) + mariadb.SimulateMariaDBAccountCompleted(glanceTest.GlanceDatabaseAccount) th.SimulateJobSuccess(glanceTest.GlanceDBSync) Glance := GetGlance(glanceTest.Instance) Expect(Glance.Status.DatabaseHostname).To(Equal(fmt.Sprintf("hostname-for-openstack.%s.svc", namespace))) @@ -181,8 +183,8 @@ var _ = Describe("Glance controller", func() { ) }) It("Should fail if db-sync job fails when DB is Created", func() { - mariadb.SimulateMariaDBAccountCompleted(glanceTest.Instance) - mariadb.SimulateMariaDBDatabaseCompleted(glanceTest.Instance) + mariadb.SimulateMariaDBDatabaseCompleted(glanceTest.GlanceDatabaseName) + mariadb.SimulateMariaDBAccountCompleted(glanceTest.GlanceDatabaseAccount) th.SimulateJobFailure(glanceTest.GlanceDBSync) th.ExpectCondition( glanceTest.Instance, @@ -216,8 +218,8 @@ var _ = Describe("Glance controller", func() { }, ), ) - mariadb.SimulateMariaDBAccountCompleted(glanceTest.Instance) - mariadb.SimulateMariaDBDatabaseCompleted(glanceTest.Instance) + mariadb.SimulateMariaDBDatabaseCompleted(glanceTest.GlanceDatabaseName) + mariadb.SimulateMariaDBAccountCompleted(glanceTest.GlanceDatabaseAccount) th.SimulateJobSuccess(glanceTest.GlanceDBSync) keystoneAPI := keystone.CreateKeystoneAPI(glanceTest.Instance.Namespace) DeferCleanup(keystone.DeleteKeystoneAPI, keystoneAPI) @@ -278,8 +280,8 @@ var _ = Describe("Glance controller", func() { ), ) DeferCleanup(keystone.DeleteKeystoneAPI, keystone.CreateKeystoneAPI(glanceTest.Instance.Namespace)) - mariadb.SimulateMariaDBAccountCompleted(glanceTest.Instance) - mariadb.SimulateMariaDBDatabaseCompleted(glanceTest.Instance) + mariadb.SimulateMariaDBDatabaseCompleted(glanceTest.GlanceDatabaseName) + mariadb.SimulateMariaDBAccountCompleted(glanceTest.GlanceDatabaseAccount) th.SimulateJobSuccess(glanceTest.GlanceDBSync) keystone.SimulateKeystoneServiceReady(glanceTest.Instance) keystone.SimulateKeystoneEndpointReady(glanceTest.GlanceSingle) @@ -313,8 +315,8 @@ var _ = Describe("Glance controller", func() { ), ) DeferCleanup(keystone.DeleteKeystoneAPI, keystone.CreateKeystoneAPI(glanceTest.Instance.Namespace)) - mariadb.SimulateMariaDBAccountCompleted(glanceTest.Instance) - mariadb.SimulateMariaDBDatabaseCompleted(glanceTest.Instance) + mariadb.SimulateMariaDBDatabaseCompleted(glanceTest.GlanceDatabaseName) + mariadb.SimulateMariaDBAccountCompleted(glanceTest.GlanceDatabaseAccount) th.SimulateJobSuccess(glanceTest.GlanceDBSync) keystone.SimulateKeystoneServiceReady(glanceTest.Instance) keystone.SimulateKeystoneEndpointReady(glanceTest.GlanceSingle) @@ -353,6 +355,7 @@ var _ = Describe("Glance controller", func() { "storageRequest": glanceTest.GlancePVCSize, "secret": SecretName, "databaseInstance": "openstack", + "databaseAccount": glanceTest.GlanceDatabaseAccount.Name, "keystoneEndpoint": "default", "customServiceConfig": GlanceDummyBackend, "glanceAPIs": map[string]interface{}{ @@ -376,8 +379,8 @@ var _ = Describe("Glance controller", func() { }, ), ) - mariadb.SimulateMariaDBAccountCompleted(glanceTest.Instance) - mariadb.SimulateMariaDBDatabaseCompleted(glanceTest.Instance) + mariadb.SimulateMariaDBDatabaseCompleted(glanceTest.GlanceDatabaseName) + mariadb.SimulateMariaDBAccountCompleted(glanceTest.GlanceDatabaseAccount) th.SimulateJobSuccess(glanceTest.GlanceDBSync) keystoneAPI := keystone.CreateKeystoneAPI(glanceTest.Instance.Namespace) DeferCleanup(keystone.DeleteKeystoneAPI, keystoneAPI) @@ -411,4 +414,73 @@ var _ = Describe("Glance controller", func() { } }) }) + + // Run MariaDBAccount suite tests. these are pre-packaged ginkgo tests + // that exercise standard account create / update patterns that should be + // common to all controllers that ensure MariaDBAccount CRs. + mariadbSuite := &mariadb_test.MariaDBTestHarness{ + PopulateHarness: func(harness *mariadb_test.MariaDBTestHarness) { + harness.Setup( + "Glance", + glanceName.Namespace, + glanceTest.Instance.Name, + "Glance", + mariadb, + timeout, + interval, + ) + }, + // Generate a fully running Glance service given an accountName + // needs to make it all the way to the end where the mariadb finalizers + // are removed from unused accounts since that's part of what we are testing + SetupCR: func(accountName types.NamespacedName) { + + memcachedSpec = memcachedv1.MemcachedSpec{ + Replicas: ptr.To(int32(3)), + } + + DeferCleanup(infra.DeleteMemcached, infra.CreateMemcached(namespace, glanceTest.MemcachedInstance, memcachedSpec)) + infra.SimulateMemcachedReady(glanceTest.GlanceMemcached) + + spec := GetGlanceDefaultSpec() + spec["databaseAccount"] = accountName.Name + + DeferCleanup(th.DeleteInstance, CreateGlance(glanceTest.Instance, spec)) + DeferCleanup( + mariadb.DeleteDBService, + mariadb.CreateDBService( + glanceName.Namespace, + GetGlance(glanceTest.Instance).Spec.DatabaseInstance, + corev1.ServiceSpec{ + Ports: []corev1.ServicePort{{Port: 3306}}, + }, + ), + ) + + DeferCleanup(keystone.DeleteKeystoneAPI, keystone.CreateKeystoneAPI(glanceTest.Instance.Namespace)) + mariadb.SimulateMariaDBAccountCompleted(accountName) + mariadb.SimulateMariaDBDatabaseCompleted(glanceTest.GlanceDatabaseName) + th.SimulateJobSuccess(glanceTest.GlanceDBSync) + keystone.SimulateKeystoneServiceReady(glanceTest.Instance) + keystone.SimulateKeystoneEndpointReady(glanceTest.GlanceSingle) + GlanceAPIExists(glanceTest.GlanceSingle) + }, + // Change the account name in the service to a new name + UpdateAccount: func(newAccountName types.NamespacedName) { + + Eventually(func(g Gomega) { + glance := GetGlance(glanceTest.Instance) + glance.Spec.DatabaseAccount = newAccountName.Name + g.Expect(th.K8sClient.Update(ctx, glance)).Should(Succeed()) + }, timeout, interval).Should(Succeed()) + + }, + // delete the service, allowing finalizer removal tests + DeleteCR: func() { + th.DeleteInstance(GetGlance(glanceTest.Instance)) + }, + } + + mariadbSuite.RunBasicSuite() + }) diff --git a/test/functional/glance_test_data.go b/test/functional/glance_test_data.go index bec052fd..ed5c1144 100644 --- a/test/functional/glance_test_data.go +++ b/test/functional/glance_test_data.go @@ -17,6 +17,7 @@ package functional import ( "fmt" + "github.com/openstack-k8s-operators/glance-operator/pkg/glance" "k8s.io/apimachinery/pkg/types" ) @@ -42,12 +43,15 @@ const ( GlanceDummyBackend = "enabled_backends=backend1:type1 # CHANGE_ME" // MemcachedInstance - name of the memcached instance MemcachedInstance = "memcached" + // AccountName - name of the MariaDBAccount CR + AccountName = glance.DatabaseName ) // GlanceTestData is the data structure used to provide input data to envTest type GlanceTestData struct { ContainerImage string - GlanceDatabaseUser string + GlanceDatabaseName types.NamespacedName + GlanceDatabaseAccount types.NamespacedName GlancePassword string GlanceServiceUser string GlancePVCSize string @@ -177,7 +181,14 @@ func GetGlanceTestData(glanceName types.NamespacedName) GlanceTestData { Namespace: glanceName.Namespace, Name: "internalapi", }, - GlanceDatabaseUser: "glance", + GlanceDatabaseName: types.NamespacedName{ + Namespace: glanceName.Namespace, + Name: glance.DatabaseName, + }, + GlanceDatabaseAccount: types.NamespacedName{ + Namespace: glanceName.Namespace, + Name: AccountName, + }, // Password used for both db and service GlancePassword: "12345678", GlanceServiceUser: "glance", diff --git a/test/functional/glanceapi_controller_test.go b/test/functional/glanceapi_controller_test.go index bdbf4d10..4ef6e393 100644 --- a/test/functional/glanceapi_controller_test.go +++ b/test/functional/glanceapi_controller_test.go @@ -37,6 +37,9 @@ var _ = Describe("Glanceapi controller", func() { memcachedSpec = memcachedv1.MemcachedSpec{ Replicas: ptr.To(int32(3)), } + acc, accSecret := mariadb.CreateMariaDBAccountAndSecret(glanceTest.GlanceDatabaseAccount, mariadbv1.MariaDBAccountSpec{}) + DeferCleanup(k8sClient.Delete, ctx, accSecret) + DeferCleanup(k8sClient.Delete, ctx, acc) }) When("GlanceAPI CR is created", func() { @@ -97,10 +100,9 @@ var _ = Describe("Glanceapi controller", func() { }, ), ) - mariadb.CreateMariaDBAccount(glanceTest.Instance.Namespace, glanceTest.Instance.Name, mariadbv1.MariaDBAccountSpec{}) - mariadb.CreateMariaDBDatabase(glanceTest.Instance.Namespace, glanceTest.Instance.Name, mariadbv1.MariaDBDatabaseSpec{}) - mariadb.SimulateMariaDBAccountCompleted(glanceTest.Instance) - mariadb.SimulateMariaDBDatabaseCompleted(glanceTest.Instance) + mariadb.CreateMariaDBDatabase(glanceTest.GlanceDatabaseName.Namespace, glanceTest.GlanceDatabaseName.Name, mariadbv1.MariaDBDatabaseSpec{}) + DeferCleanup(k8sClient.Delete, ctx, mariadb.GetMariaDBDatabase(glanceTest.GlanceDatabaseName)) + spec := GetDefaultGlanceAPISpec(GlanceAPITypeSingle) spec["customServiceConfig"] = "foo=bar" DeferCleanup(th.DeleteInstance, CreateGlanceAPI(glanceTest.GlanceSingle, spec)) @@ -156,10 +158,10 @@ var _ = Describe("Glanceapi controller", func() { }, ), ) - mariadb.CreateMariaDBAccount(glanceTest.Instance.Namespace, glanceTest.Instance.Name, mariadbv1.MariaDBAccountSpec{}) - mariadb.CreateMariaDBDatabase(glanceTest.Instance.Namespace, glanceTest.Instance.Name, mariadbv1.MariaDBDatabaseSpec{}) - mariadb.SimulateMariaDBAccountCompleted(glanceTest.Instance) - mariadb.SimulateMariaDBDatabaseCompleted(glanceTest.Instance) + + mariadb.CreateMariaDBDatabase(glanceTest.GlanceDatabaseName.Namespace, glanceTest.GlanceDatabaseName.Name, mariadbv1.MariaDBDatabaseSpec{}) + DeferCleanup(k8sClient.Delete, ctx, mariadb.GetMariaDBDatabase(glanceTest.GlanceDatabaseName)) + DeferCleanup(th.DeleteInstance, CreateGlanceAPI(glanceTest.GlanceInternal, CreateGlanceAPISpec(GlanceAPITypeInternal))) DeferCleanup(th.DeleteInstance, CreateGlanceAPI(glanceTest.GlanceExternal, CreateGlanceAPISpec(GlanceAPITypeExternal))) DeferCleanup(keystone.DeleteKeystoneAPI, keystone.CreateKeystoneAPI(glanceTest.Instance.Namespace)) @@ -239,10 +241,10 @@ var _ = Describe("Glanceapi controller", func() { }, ), ) - mariadb.CreateMariaDBAccount(glanceTest.Instance.Namespace, glanceTest.Instance.Name, mariadbv1.MariaDBAccountSpec{}) - mariadb.CreateMariaDBDatabase(glanceTest.Instance.Namespace, glanceTest.Instance.Name, mariadbv1.MariaDBDatabaseSpec{}) - mariadb.SimulateMariaDBAccountCompleted(glanceTest.Instance) - mariadb.SimulateMariaDBDatabaseCompleted(glanceTest.Instance) + + mariadb.CreateMariaDBDatabase(glanceTest.GlanceDatabaseName.Namespace, glanceTest.GlanceDatabaseName.Name, mariadbv1.MariaDBDatabaseSpec{}) + DeferCleanup(k8sClient.Delete, ctx, mariadb.GetMariaDBDatabase(glanceTest.GlanceDatabaseName)) + DeferCleanup(th.DeleteInstance, CreateGlanceAPI(glanceTest.GlanceEdge, CreateGlanceAPISpec(GlanceAPITypeEdge))) DeferCleanup(keystone.DeleteKeystoneAPI, keystone.CreateKeystoneAPI(glanceTest.Instance.Namespace)) th.ExpectCondition( @@ -293,10 +295,10 @@ var _ = Describe("Glanceapi controller", func() { }, ), ) - mariadb.CreateMariaDBAccount(glanceTest.Instance.Namespace, glanceTest.Instance.Name, mariadbv1.MariaDBAccountSpec{}) - mariadb.CreateMariaDBDatabase(glanceTest.Instance.Namespace, glanceTest.Instance.Name, mariadbv1.MariaDBDatabaseSpec{}) - mariadb.SimulateMariaDBAccountCompleted(glanceTest.Instance) - mariadb.SimulateMariaDBDatabaseCompleted(glanceTest.Instance) + + mariadb.CreateMariaDBDatabase(glanceTest.GlanceDatabaseName.Namespace, glanceTest.GlanceDatabaseName.Name, mariadbv1.MariaDBDatabaseSpec{}) + DeferCleanup(k8sClient.Delete, ctx, mariadb.GetMariaDBDatabase(glanceTest.GlanceDatabaseName)) + DeferCleanup(th.DeleteInstance, CreateGlanceAPI(glanceTest.GlanceSingle, CreateGlanceAPISpec(GlanceAPITypeSingle))) DeferCleanup(keystone.DeleteKeystoneAPI, keystone.CreateKeystoneAPI(glanceTest.Instance.Namespace)) th.ExpectCondition( @@ -340,10 +342,9 @@ var _ = Describe("Glanceapi controller", func() { }, ), ) - mariadb.CreateMariaDBAccount(glanceTest.Instance.Namespace, glanceTest.Instance.Name, mariadbv1.MariaDBAccountSpec{}) - mariadb.CreateMariaDBDatabase(glanceTest.Instance.Namespace, glanceTest.Instance.Name, mariadbv1.MariaDBDatabaseSpec{}) - mariadb.SimulateMariaDBAccountCompleted(glanceTest.Instance) - mariadb.SimulateMariaDBDatabaseCompleted(glanceTest.Instance) + mariadb.CreateMariaDBDatabase(glanceTest.GlanceDatabaseName.Namespace, glanceTest.GlanceDatabaseName.Name, mariadbv1.MariaDBDatabaseSpec{}) + DeferCleanup(k8sClient.Delete, ctx, mariadb.GetMariaDBDatabase(glanceTest.GlanceDatabaseName)) + DeferCleanup(th.DeleteInstance, CreateGlanceAPI(glanceTest.GlanceExternal, CreateGlanceAPISpec(GlanceAPITypeExternal))) DeferCleanup(keystone.DeleteKeystoneAPI, keystone.CreateKeystoneAPI(glanceTest.GlanceExternal.Namespace)) th.SimulateStatefulSetReplicaReady(glanceTest.GlanceExternalStatefulSet) @@ -391,10 +392,10 @@ var _ = Describe("Glanceapi controller", func() { }, ), ) - mariadb.CreateMariaDBAccount(glanceTest.Instance.Namespace, glanceTest.Instance.Name, mariadbv1.MariaDBAccountSpec{}) - mariadb.CreateMariaDBDatabase(glanceTest.Instance.Namespace, glanceTest.Instance.Name, mariadbv1.MariaDBDatabaseSpec{}) - mariadb.SimulateMariaDBAccountCompleted(glanceTest.Instance) - mariadb.SimulateMariaDBDatabaseCompleted(glanceTest.Instance) + + mariadb.CreateMariaDBDatabase(glanceTest.GlanceDatabaseName.Namespace, glanceTest.GlanceDatabaseName.Name, mariadbv1.MariaDBDatabaseSpec{}) + DeferCleanup(k8sClient.Delete, ctx, mariadb.GetMariaDBDatabase(glanceTest.GlanceDatabaseName)) + DeferCleanup(th.DeleteInstance, CreateGlanceAPI(glanceTest.GlanceInternal, CreateGlanceAPISpec(GlanceAPITypeInternal))) DeferCleanup(keystone.DeleteKeystoneAPI, keystone.CreateKeystoneAPI(glanceTest.GlanceInternal.Namespace)) th.SimulateStatefulSetReplicaReady(glanceTest.GlanceInternalStatefulSet) @@ -442,10 +443,10 @@ var _ = Describe("Glanceapi controller", func() { }, ), ) - mariadb.CreateMariaDBAccount(glanceTest.Instance.Namespace, glanceTest.Instance.Name, mariadbv1.MariaDBAccountSpec{}) - mariadb.CreateMariaDBDatabase(glanceTest.Instance.Namespace, glanceTest.Instance.Name, mariadbv1.MariaDBDatabaseSpec{}) - mariadb.SimulateMariaDBAccountCompleted(glanceTest.Instance) - mariadb.SimulateMariaDBDatabaseCompleted(glanceTest.Instance) + + mariadb.CreateMariaDBDatabase(glanceTest.GlanceDatabaseName.Namespace, glanceTest.GlanceDatabaseName.Name, mariadbv1.MariaDBDatabaseSpec{}) + DeferCleanup(k8sClient.Delete, ctx, mariadb.GetMariaDBDatabase(glanceTest.GlanceDatabaseName)) + DeferCleanup(th.DeleteInstance, CreateGlanceAPI(glanceTest.GlanceSingle, CreateGlanceAPISpec(GlanceAPITypeSingle))) DeferCleanup(keystone.DeleteKeystoneAPI, keystone.CreateKeystoneAPI(glanceTest.GlanceSingle.Namespace)) th.SimulateStatefulSetReplicaReady(glanceTest.GlanceSingle) @@ -494,10 +495,10 @@ var _ = Describe("Glanceapi controller", func() { }, ), ) - mariadb.CreateMariaDBAccount(glanceTest.Instance.Namespace, glanceTest.Instance.Name, mariadbv1.MariaDBAccountSpec{}) - mariadb.CreateMariaDBDatabase(glanceTest.Instance.Namespace, glanceTest.Instance.Name, mariadbv1.MariaDBDatabaseSpec{}) - mariadb.SimulateMariaDBAccountCompleted(glanceTest.Instance) - mariadb.SimulateMariaDBDatabaseCompleted(glanceTest.Instance) + + mariadb.CreateMariaDBDatabase(glanceTest.GlanceDatabaseName.Namespace, glanceTest.GlanceDatabaseName.Name, mariadbv1.MariaDBDatabaseSpec{}) + DeferCleanup(k8sClient.Delete, ctx, mariadb.GetMariaDBDatabase(glanceTest.GlanceDatabaseName)) + spec := CreateGlanceAPISpec(GlanceAPITypeInternal) serviceOverride := map[string]interface{}{} serviceOverride["internal"] = map[string]interface{}{ @@ -575,10 +576,10 @@ var _ = Describe("Glanceapi controller", func() { }, ), ) - mariadb.CreateMariaDBAccount(glanceTest.Instance.Namespace, glanceTest.Instance.Name, mariadbv1.MariaDBAccountSpec{}) - mariadb.CreateMariaDBDatabase(glanceTest.Instance.Namespace, glanceTest.Instance.Name, mariadbv1.MariaDBDatabaseSpec{}) - mariadb.SimulateMariaDBAccountCompleted(glanceTest.Instance) - mariadb.SimulateMariaDBDatabaseCompleted(glanceTest.Instance) + + mariadb.CreateMariaDBDatabase(glanceTest.GlanceDatabaseName.Namespace, glanceTest.GlanceDatabaseName.Name, mariadbv1.MariaDBDatabaseSpec{}) + DeferCleanup(k8sClient.Delete, ctx, mariadb.GetMariaDBDatabase(glanceTest.GlanceDatabaseName)) + spec := CreateGlanceAPISpec(GlanceAPITypeExternal) serviceOverride := map[string]interface{}{} serviceOverride["public"] = map[string]interface{}{ @@ -623,10 +624,11 @@ var _ = Describe("Glanceapi controller", func() { }, ), ) - mariadb.CreateMariaDBAccount(glanceTest.Instance.Namespace, glanceTest.Instance.Name, mariadbv1.MariaDBAccountSpec{}) - mariadb.CreateMariaDBDatabase(glanceTest.Instance.Namespace, glanceTest.Instance.Name, mariadbv1.MariaDBDatabaseSpec{}) - mariadb.SimulateMariaDBAccountCompleted(glanceTest.Instance) - mariadb.SimulateMariaDBTLSDatabaseCompleted(glanceTest.Instance) + + mariadb.CreateMariaDBDatabase(glanceTest.GlanceDatabaseName.Namespace, glanceTest.GlanceDatabaseName.Name, mariadbv1.MariaDBDatabaseSpec{}) + DeferCleanup(k8sClient.Delete, ctx, mariadb.GetMariaDBDatabase(glanceTest.GlanceDatabaseName)) + mariadb.SimulateMariaDBTLSDatabaseCompleted(glanceTest.GlanceDatabaseName) + DeferCleanup(k8sClient.Delete, ctx, th.CreateCABundleSecret(glanceTest.CABundleSecret)) DeferCleanup(k8sClient.Delete, ctx, th.CreateCertSecret(glanceTest.InternalCertSecret)) DeferCleanup(k8sClient.Delete, ctx, th.CreateCertSecret(glanceTest.PublicCertSecret)) @@ -742,10 +744,11 @@ var _ = Describe("Glanceapi controller", func() { }, ), ) - mariadb.CreateMariaDBAccount(glanceTest.Instance.Namespace, glanceTest.Instance.Name, mariadbv1.MariaDBAccountSpec{}) - mariadb.CreateMariaDBDatabase(glanceTest.Instance.Namespace, glanceTest.Instance.Name, mariadbv1.MariaDBDatabaseSpec{}) - mariadb.SimulateMariaDBAccountCompleted(glanceTest.Instance) - mariadb.SimulateMariaDBTLSDatabaseCompleted(glanceTest.Instance) + + mariadb.CreateMariaDBDatabase(glanceTest.GlanceDatabaseName.Namespace, glanceTest.GlanceDatabaseName.Name, mariadbv1.MariaDBDatabaseSpec{}) + DeferCleanup(k8sClient.Delete, ctx, mariadb.GetMariaDBDatabase(glanceTest.GlanceDatabaseName)) + mariadb.SimulateMariaDBTLSDatabaseCompleted(glanceTest.GlanceDatabaseName) + DeferCleanup(th.DeleteInstance, CreateDefaultGlance(glanceTest.Instance)) DeferCleanup(th.DeleteInstance, CreateGlanceAPI(glanceTest.GlanceSingle, GetTLSGlanceAPISpec(GlanceAPITypeSingle))) DeferCleanup(keystone.DeleteKeystoneAPI, keystone.CreateKeystoneAPI(glanceTest.Instance.Namespace)) @@ -917,10 +920,10 @@ var _ = Describe("Glanceapi controller", func() { }, ), ) - mariadb.CreateMariaDBAccount(glanceTest.Instance.Namespace, glanceTest.Instance.Name, mariadbv1.MariaDBAccountSpec{}) - mariadb.CreateMariaDBDatabase(glanceTest.Instance.Namespace, glanceTest.Instance.Name, mariadbv1.MariaDBDatabaseSpec{}) - mariadb.SimulateMariaDBAccountCompleted(glanceTest.Instance) - mariadb.SimulateMariaDBTLSDatabaseCompleted(glanceTest.Instance) + + mariadb.CreateMariaDBDatabase(glanceTest.GlanceDatabaseName.Namespace, glanceTest.GlanceDatabaseName.Name, mariadbv1.MariaDBDatabaseSpec{}) + DeferCleanup(k8sClient.Delete, ctx, mariadb.GetMariaDBDatabase(glanceTest.GlanceDatabaseName)) + DeferCleanup(k8sClient.Delete, ctx, th.CreateCABundleSecret(glanceTest.CABundleSecret)) DeferCleanup(k8sClient.Delete, ctx, th.CreateCertSecret(glanceTest.InternalCertSecret)) DeferCleanup(k8sClient.Delete, ctx, th.CreateCertSecret(glanceTest.PublicCertSecret)) diff --git a/test/functional/suite_test.go b/test/functional/suite_test.go index dea90d2b..16792eb6 100644 --- a/test/functional/suite_test.go +++ b/test/functional/suite_test.go @@ -258,4 +258,5 @@ var _ = BeforeEach(func() { DeferCleanup(th.DeleteNamespace, namespace) // Let's create the osp-secret in advance (in common to all the test cases) DeferCleanup(k8sClient.Delete, ctx, CreateGlanceSecret(glanceName.Namespace, SecretName)) + }) diff --git a/test/kuttl/tests/glance_image_cache/01-assert.yaml b/test/kuttl/tests/glance_image_cache/01-assert.yaml index 058b909d..bdf916f9 100644 --- a/test/kuttl/tests/glance_image_cache/01-assert.yaml +++ b/test/kuttl/tests/glance_image_cache/01-assert.yaml @@ -15,7 +15,7 @@ metadata: spec: serviceUser: glance databaseInstance: openstack - databaseUser: glance + databaseAccount: glance glanceAPIs: default: replicas: 1 diff --git a/test/kuttl/tests/glance_image_cache/02-assert.yaml b/test/kuttl/tests/glance_image_cache/02-assert.yaml index e3088d33..7c5e8032 100644 --- a/test/kuttl/tests/glance_image_cache/02-assert.yaml +++ b/test/kuttl/tests/glance_image_cache/02-assert.yaml @@ -15,7 +15,7 @@ metadata: spec: serviceUser: glance databaseInstance: openstack - databaseUser: glance + databaseAccount: glance glanceAPIs: default: replicas: 2 diff --git a/test/kuttl/tests/glance_image_cache/03-assert.yaml b/test/kuttl/tests/glance_image_cache/03-assert.yaml index 01d4a40f..a47d7e0d 100644 --- a/test/kuttl/tests/glance_image_cache/03-assert.yaml +++ b/test/kuttl/tests/glance_image_cache/03-assert.yaml @@ -16,7 +16,7 @@ metadata: spec: serviceUser: glance databaseInstance: openstack - databaseUser: glance + databaseAccount: glance glanceAPIs: default: replicas: 1 diff --git a/test/kuttl/tests/glance_single/01-assert.yaml b/test/kuttl/tests/glance_single/01-assert.yaml index 3afecb9a..621e840f 100644 --- a/test/kuttl/tests/glance_single/01-assert.yaml +++ b/test/kuttl/tests/glance_single/01-assert.yaml @@ -15,7 +15,7 @@ metadata: spec: serviceUser: glance databaseInstance: openstack - databaseUser: glance + databaseAccount: glance glanceAPIs: default: replicas: 1 @@ -31,10 +31,9 @@ metadata: name: glance-default-single spec: apiType: single - databaseUser: glance + databaseAccount: glance databaseHostname: openstack.glance-kuttl-tests.svc passwordSelectors: - database: GlanceDatabasePassword service: GlancePassword replicas: 1 --- diff --git a/test/kuttl/tests/glance_split/01-assert.yaml b/test/kuttl/tests/glance_split/01-assert.yaml index 406fb4ea..dc301aa4 100644 --- a/test/kuttl/tests/glance_split/01-assert.yaml +++ b/test/kuttl/tests/glance_split/01-assert.yaml @@ -18,7 +18,7 @@ metadata: spec: serviceUser: glance databaseInstance: openstack - databaseUser: glance + databaseAccount: glance glanceAPIs: default: replicas: 1 @@ -33,10 +33,9 @@ metadata: name: glance-default-external spec: apiType: external - databaseUser: glance + databaseAccount: glance databaseHostname: openstack.glance-kuttl-tests.svc passwordSelectors: - database: GlanceDatabasePassword service: GlancePassword replicas: 1 --- @@ -46,10 +45,9 @@ metadata: name: glance-default-internal spec: apiType: internal - databaseUser: glance + databaseAccount: glance databaseHostname: openstack.glance-kuttl-tests.svc passwordSelectors: - database: GlanceDatabasePassword service: GlancePassword replicas: 1 ---