diff --git a/api/bases/glance.openstack.org_glanceapis.yaml b/api/bases/glance.openstack.org_glanceapis.yaml index d1c42fa4..13385fd0 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: @@ -881,12 +881,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 c95b9a5c..25c7c289 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: @@ -980,12 +980,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 c9ac7236..da6dff11 100644 --- a/api/v1beta1/glance_types.go +++ b/api/v1beta1/glance_types.go @@ -54,16 +54,20 @@ type GlanceSpec 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. + // As an interim solution, glance-controller will + // generate the MariaDBAccount object of the given name if it's not + // present in the cluster. Later, openstack-operator will perform this + // generation and also populate this field for the Glance objects it creates + DatabaseAccount string `json:"databaseAccount"` // +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"` @@ -134,11 +138,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 diff --git a/api/v1beta1/glanceapi_types.go b/api/v1beta1/glanceapi_types.go index 7e2057e9..d4cef992 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 d1c42fa4..13385fd0 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: @@ -881,12 +881,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 c95b9a5c..25c7c289 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: @@ -980,12 +980,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/manifests/bases/glance-operator.clusterserviceversion.yaml b/config/manifests/bases/glance-operator.clusterserviceversion.yaml index 05237105..76dbed7a 100644 --- a/config/manifests/bases/glance-operator.clusterserviceversion.yaml +++ b/config/manifests/bases/glance-operator.clusterserviceversion.yaml @@ -18,11 +18,19 @@ spec: displayName: Glance API kind: GlanceAPI name: glanceapis.glance.openstack.org + specDescriptors: + - description: TLS - Parameters related to the TLS + displayName: TLS + path: tls version: v1beta1 - description: Glance is the Schema for the glances API displayName: Glance kind: Glance name: glances.glance.openstack.org + specDescriptors: + - description: TLS - Parameters related to the TLS + displayName: TLS + path: glanceAPIs.tls version: v1beta1 description: Glance Operator displayName: Glance Operator 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 26228cc8..ca21b79d 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 5ebf4e88..09f42227 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" @@ -266,7 +265,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 } @@ -532,6 +531,32 @@ func (r *GlanceReconciler) reconcileNormal(ctx context.Context, instance *glance instance.Status.Conditions.MarkTrue(condition.InputReadyCondition, condition.InputReadyMessage) // run check OpenStack secret - end + // 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, helper, 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 ctrl.Result{}, err + } + instance.Status.Conditions.MarkTrue( + mariadbv1.MariaDBAccountReadyCondition, + mariadbv1.MariaDBAccountReadyMessage, + ) + db, ctrlResult, err := r.ensureDB(ctx, helper, instance) if err != nil { return ctrl.Result{}, err @@ -607,6 +632,13 @@ func (r *GlanceReconciler) reconcileNormal(ctx context.Context, instance *glance if err != nil { 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 CronJobs: DBPurge (always), CacheCleaner and CachePruner if image-cache // is enabled ctrlResult, err = r.ensureCronJobs(ctx, helper, instance, serviceLabels, serviceAnnotations) @@ -767,7 +799,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, @@ -852,18 +884,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, ), @@ -1053,24 +1083,19 @@ func (r *GlanceReconciler) ensureDB( h *helper.Helper, instance *glancev1.Glance, ) (*mariadbv1.Database, ctrl.Result, error) { - // // 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 7b742863..2d461805 100644 --- a/controllers/glanceapi_controller.go +++ b/controllers/glanceapi_controller.go @@ -792,7 +792,7 @@ func (r *GlanceAPIReconciler) generateServiceConfig( ) error { labels := labels.GetLabels(instance, labels.GetGroupLabel(glance.ServiceName), serviceLabels) - 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 } @@ -839,6 +839,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 { @@ -859,8 +862,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 7184a815..3abf05e1 100644 --- a/go.mod +++ b/go.mod @@ -93,3 +93,5 @@ replace github.com/openstack-k8s-operators/glance-operator/api => ./api // mschuppert: map to latest commit from release-4.13 tag // must consistent within modules and service operators replace github.com/openshift/api => github.com/openshift/api v0.0.0-20230414143018-3367bc7e6ac7 //allow-merging + +replace github.com/openstack-k8s-operators/mariadb-operator/api => github.com/zzzeek/mariadb-operator/api v0.3.1-0.20240223174203-130ff24a0c90 //allow-merging diff --git a/go.sum b/go.sum index af0ca975..d650f727 100644 --- a/go.sum +++ b/go.sum @@ -93,8 +93,6 @@ github.com/openstack-k8s-operators/lib-common/modules/storage v0.3.1-0.202402241 github.com/openstack-k8s-operators/lib-common/modules/storage v0.3.1-0.20240224182407-3b6c02b195f6/go.mod h1:Qg6DbOUHCzMCGhRikhN0XTWSOBOX9uB9z74jTbjyOUk= github.com/openstack-k8s-operators/lib-common/modules/test v0.3.1-0.20240224182407-3b6c02b195f6 h1:8SbXBGb7qgvYTXF9WiaNg1esn2J7mVXkqcAC0pIZJe4= github.com/openstack-k8s-operators/lib-common/modules/test v0.3.1-0.20240224182407-3b6c02b195f6/go.mod h1:82nzS+DbBe1tzaMvNHH8FctmZzQ14ZAJysFGsMJiivo= -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/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -117,6 +115,8 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +github.com/zzzeek/mariadb-operator/api v0.3.1-0.20240223174203-130ff24a0c90 h1:oFD6wDyzRjeh069l8JrqzZOpq9qFbM4ZMqs7hjwOXa0= +github.com/zzzeek/mariadb-operator/api v0.3.1-0.20240223174203-130ff24a0c90/go.mod h1:f9IIyWeoskWoeWaDFF3qmAJ2Kqyovfi0Ar/QUfk3qag= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= diff --git a/pkg/glance/const.go b/pkg/glance/const.go index 1ba3b6cc..61fb21b8 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 9c807a51..a08c9ff4 100644 --- a/test/functional/base_test.go +++ b/test/functional/base_test.go @@ -67,6 +67,7 @@ func CreateDefaultGlance(name types.NamespacedName) client.Object { "spec": map[string]interface{}{ "keystoneEndpoint": "default", "databaseInstance": "openstack", + "databaseAccount": glanceTest.GlanceDatabaseAccount.Name, "storageRequest": glanceTest.GlancePVCSize, "glanceAPIs": GetAPIList(), }, @@ -90,7 +91,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(), @@ -102,7 +103,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(), @@ -121,8 +122,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, } } @@ -160,8 +162,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), }, ) } @@ -170,6 +171,7 @@ func GetDefaultGlanceSpec() map[string]interface{} { return map[string]interface{}{ "databaseInstance": "openstack", "secret": SecretName, + "databaseAccount": glanceTest.GlanceDatabaseAccount.Name, "glanceAPIs": GetAPIList(), } } @@ -184,6 +186,7 @@ func CreateGlanceAPISpec(apiType APIType) map[string]interface{} { "name": "default", "databaseHostname": "openstack", "secret": SecretName, + "databaseAccount": glanceTest.GlanceDatabaseAccount.Name, } return spec } @@ -198,6 +201,7 @@ func GetDefaultGlanceAPISpec(apiType APIType) map[string]interface{} { "name": "default", "databaseHostname": "openstack", "secret": SecretName, + "databaseAccount": glanceTest.GlanceDatabaseAccount.Name, } return spec } @@ -206,6 +210,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 3f801678..f34da80d 100644 --- a/test/functional/glance_controller_test.go +++ b/test/functional/glance_controller_test.go @@ -24,13 +24,16 @@ import ( . "github.com/openstack-k8s-operators/lib-common/modules/common/test/helpers" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/types" glancev1 "github.com/openstack-k8s-operators/glance-operator/api/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" ) var _ = Describe("Glance controller", func() { + When("Glance is created", func() { BeforeEach(func() { DeferCleanup(th.DeleteInstance, CreateDefaultGlance(glanceName)) @@ -56,7 +59,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)) // No Keystone Quota is present, check the default is 0 Expect(Glance.Spec.Quotas.ImageCountUpload).To(Equal(int(0))) @@ -141,8 +144,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))) @@ -167,8 +170,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, @@ -200,8 +203,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) @@ -258,8 +261,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) @@ -291,8 +294,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) @@ -329,6 +332,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{}{ @@ -352,8 +356,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) @@ -387,4 +391,65 @@ 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. + mariadb_test.MariaDBAccountSuiteTests( + "Glance", + // Populate test variables which will run inside of BeforeEach + func(harness *mariadb_test.MariaDBTestHarness) { + harness.PopulateHarness( + 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 + func(accountName types.NamespacedName) { + + 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 + 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 + func() { + th.DeleteInstance(GetGlance(glanceTest.Instance)) + }, + ) + }) diff --git a/test/functional/glance_test_data.go b/test/functional/glance_test_data.go index 01a49b91..5b9ae176 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" ) @@ -40,12 +41,15 @@ const ( CABundleSecretName = "combined-ca-bundle" //GlanceDummyBackend - GlanceDummyBackend = "enabled_backends=backend1:type1 # CHANGE_ME" + + AccountName = "test-glance-account" ) // 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 @@ -173,7 +177,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 6f8d3c2b..3f41b093 100644 --- a/test/functional/glanceapi_controller_test.go +++ b/test/functional/glanceapi_controller_test.go @@ -29,6 +29,13 @@ import ( ) var _ = Describe("Glanceapi controller", func() { + + BeforeEach(func() { + acc, accSecret := mariadb.CreateMariaDBAccountAndSecret(glanceTest.GlanceDatabaseAccount, mariadbv1.MariaDBAccountSpec{}) + DeferCleanup(k8sClient.Delete, ctx, accSecret) + DeferCleanup(k8sClient.Delete, ctx, acc) + }) + When("GlanceAPI CR is created", func() { BeforeEach(func() { DeferCleanup(th.DeleteInstance, CreateGlanceAPI(glanceTest.GlanceSingle, GetDefaultGlanceAPISpec(GlanceAPITypeSingle))) @@ -81,10 +88,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)) @@ -138,10 +144,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)) @@ -219,10 +225,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( @@ -271,10 +277,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( @@ -316,10 +322,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) @@ -365,10 +370,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) @@ -414,10 +419,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) @@ -464,10 +469,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{}{ @@ -543,10 +548,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{}{ @@ -589,10 +594,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)) @@ -706,10 +712,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)) @@ -879,10 +886,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 69b7f2f7..aca48676 100644 --- a/test/functional/suite_test.go +++ b/test/functional/suite_test.go @@ -247,4 +247,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_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 ---