From e5ec07cd9373f2a009582a59bbaf4183f1008d3c Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Wed, 7 Jan 2026 09:08:45 +1100 Subject: [PATCH] refactor: rename scope to selector --- README.md | 10 +++---- api/v1alpha1/databaserequest_types.go | 4 +-- api/v1alpha1/mongodbprovider_types.go | 4 +-- .../relationaldatabaseprovider_types.go | 4 +-- .../bases/crd.lagoon.sh_databaserequests.yaml | 11 +++---- .../bases/crd.lagoon.sh_mongodbproviders.yaml | 9 +++--- ...lagoon.sh_relationaldatabaseproviders.yaml | 9 +++--- ..._v1alpha1_databaserequest_mysql-scope.yaml | 2 +- .../crd_v1alpha1_databaserequest_mysql.yaml | 2 +- ...crd_v1alpha1_databaserequest_postgres.yaml | 2 +- .../crd_v1alpha1_databaserequest_seed.yaml | 2 +- .../samples/crd_v1alpha1_mongodbprovider.yaml | 2 +- ...elationaldatabaseprovider_mysql-scope.yaml | 2 +- ...pha1_relationaldatabaseprovider_mysql.yaml | 2 +- ...1_relationaldatabaseprovider_postgres.yaml | 2 +- .../controller/databaserequest_controller.go | 24 +++++++-------- .../databaserequest_controller_test.go | 6 ++-- .../controller/mongodbprovider_controller.go | 28 ++++++++--------- .../mongodbprovider_controller_test.go | 2 +- .../relationaldatabaseprovider_controller.go | 30 +++++++++---------- ...ationaldatabaseprovider_controller_test.go | 4 +-- ...redential_broken_seed_databaserequest.yaml | 2 +- ...xisting_database_seed_databaserequest.yaml | 2 +- 23 files changed, 84 insertions(+), 81 deletions(-) diff --git a/README.md b/README.md index 1a86111..093097b 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ Use the status connectionStatus field to check the status of the MySQL connectio ### RelationalDatabaseProvider Spec Fields - kind (required): The type of database provider, which can be either mysql or postgresql. -- scope (required): Defines the scope of the database request, which influences the environment setup. Valid values are production, development, and custom. Defaults to development if not specified. +- selector (required): Defines the selector of the database request, which influences the environment setup. Valid values are production, development, and custom. Defaults to development if not specified. - connections (required): A list of `connection` objects that detail the connection parameters to MySQL or PostgreSQL databases. At least one connection must be defined. - connection Fields @@ -116,7 +116,7 @@ metadata: name: example-mysql-provider spec: kind: mysql - scope: development + selector: development mysqlConnections: - name: primary-db hostname: primary-db.example.com @@ -130,12 +130,12 @@ spec: ## DatabaseRequest CRD Documentation -The `DatabaseRequest` Custom Resource Definition (CRD) provides a mechanism for requesting database instances within a Kubernetes cluster. This resource allows lagoon to specify their requirements for a database, including the type, scope, and optional parameters such as seeding data, additional users, and database connection references. This documentation outlines the structure and functionality of the `DatabaseRequest` resource to facilitate its usage. +The `DatabaseRequest` Custom Resource Definition (CRD) provides a mechanism for requesting database instances within a Kubernetes cluster. This resource allows lagoon to specify their requirements for a database, including the type, selector, and optional parameters such as seeding data, additional users, and database connection references. This documentation outlines the structure and functionality of the `DatabaseRequest` resource to facilitate its usage. ### DatabaseRequest Spec Fields - name (required): Defines the intended service name for the database. This field is required and must be unique within the namespace. -- scope (required): Defines the intended use of the requested database. It helps in configuring the database appropriately for its intended environment. Valid options are production, development, and custom. The default value is development. +- selector (required): Defines the intended use of the requested database. It helps in configuring the database appropriately for its intended environment. Valid options are production, development, and custom. The default value is development. - type (required): Specifies the type of database requested. Supported types are mysql, mariadb, postgres, and mongodb. - seed (optional): A reference to a local Kubernetes secret within the same namespace that contains data used for seeding the database. This field is optional and intended for initial database setup. - additionalUsers (optional): Specifies the creation of additional database users. @@ -162,7 +162,7 @@ kind: DatabaseRequest metadata: name: example-database-request spec: - scope: development + selector: development type: mysql additionalUsers: type: read-write diff --git a/api/v1alpha1/databaserequest_types.go b/api/v1alpha1/databaserequest_types.go index 11f4189..9130de3 100644 --- a/api/v1alpha1/databaserequest_types.go +++ b/api/v1alpha1/databaserequest_types.go @@ -60,8 +60,8 @@ type DatabaseRequestSpec struct { //+kubebuilder:required //+kubebuilder:validation:Required - // Scope is the scope of the database request, this is used to select a provider from a pool of scopes - Scope string `json:"scope"` + // Selector is the name of the database request, this is used to select a provider from a pool of providers with the same selector + Selector string `json:"selector"` //+kubebuilder:required //+kubebuilder:validation:Required diff --git a/api/v1alpha1/mongodbprovider_types.go b/api/v1alpha1/mongodbprovider_types.go index b07805f..e1c2696 100644 --- a/api/v1alpha1/mongodbprovider_types.go +++ b/api/v1alpha1/mongodbprovider_types.go @@ -89,8 +89,8 @@ type MongoDBConnection struct { type MongoDBProviderSpec struct { //+kubebuilder:required //+kubebuilder:validation:Required - // Scope is the scope of the database request, this is used to select a provider from a pool of scopes - Scope string `json:"scope"` + // Selector is the name of the database request, this is used to select a provider from a pool of providers with the same selector + Selector string `json:"selector"` //+kubebuilder:validation:MinItems=1 // Connections defines the connection to a relational database diff --git a/api/v1alpha1/relationaldatabaseprovider_types.go b/api/v1alpha1/relationaldatabaseprovider_types.go index d856578..5bcafb7 100644 --- a/api/v1alpha1/relationaldatabaseprovider_types.go +++ b/api/v1alpha1/relationaldatabaseprovider_types.go @@ -71,8 +71,8 @@ type RelationalDatabaseProviderSpec struct { //+kubebuilder:required //+kubebuilder:validation:Required - // Scope is the scope of the database request, this is used to select a provider from a pool of scopes - Scope string `json:"scope"` + // Selector is the name of the database request, this is used to select a provider from a pool of providers with the same selector + Selector string `json:"selector"` //+kubebuilder:validation:MinItems=1 // Connections defines the connection to a relational database diff --git a/config/crd/bases/crd.lagoon.sh_databaserequests.yaml b/config/crd/bases/crd.lagoon.sh_databaserequests.yaml index 69da86b..963e7ae 100644 --- a/config/crd/bases/crd.lagoon.sh_databaserequests.yaml +++ b/config/crd/bases/crd.lagoon.sh_databaserequests.yaml @@ -137,10 +137,6 @@ spec: Name is used for the service name and the prefix in the secret data for example mariadb-0 type: string - scope: - description: Scope is the scope of the database request, this is used - to select a provider from a pool of scopes - type: string seed: description: |- Seed is the seed for the database request @@ -156,6 +152,11 @@ spec: type: string type: object x-kubernetes-map-type: atomic + selector: + description: Selector is the name of the database request, this is + used to select a provider from a pool of providers with the same + selector + type: string type: description: |- Type is the type of the database request @@ -168,7 +169,7 @@ spec: type: string required: - name - - scope + - selector - type type: object status: diff --git a/config/crd/bases/crd.lagoon.sh_mongodbproviders.yaml b/config/crd/bases/crd.lagoon.sh_mongodbproviders.yaml index 698fd57..890b25a 100644 --- a/config/crd/bases/crd.lagoon.sh_mongodbproviders.yaml +++ b/config/crd/bases/crd.lagoon.sh_mongodbproviders.yaml @@ -124,13 +124,14 @@ spec: type: object minItems: 1 type: array - scope: - description: Scope is the scope of the database request, this is used - to select a provider from a pool of scopes + selector: + description: Selector is the name of the database request, this is + used to select a provider from a pool of providers with the same + selector type: string required: - connections - - scope + - selector type: object status: description: MongoDBProviderStatus defines the observed state of MongoDBProvider diff --git a/config/crd/bases/crd.lagoon.sh_relationaldatabaseproviders.yaml b/config/crd/bases/crd.lagoon.sh_relationaldatabaseproviders.yaml index df8370d..490b350 100644 --- a/config/crd/bases/crd.lagoon.sh_relationaldatabaseproviders.yaml +++ b/config/crd/bases/crd.lagoon.sh_relationaldatabaseproviders.yaml @@ -100,9 +100,10 @@ spec: type: object minItems: 1 type: array - scope: - description: Scope is the scope of the database request, this is used - to select a provider from a pool of scopes + selector: + description: Selector is the name of the database request, this is + used to select a provider from a pool of providers with the same + selector type: string type: description: |- @@ -114,7 +115,7 @@ spec: type: string required: - connections - - scope + - selector - type type: object status: diff --git a/config/samples/crd_v1alpha1_databaserequest_mysql-scope.yaml b/config/samples/crd_v1alpha1_databaserequest_mysql-scope.yaml index e460a1b..5e76453 100644 --- a/config/samples/crd_v1alpha1_databaserequest_mysql-scope.yaml +++ b/config/samples/crd_v1alpha1_databaserequest_mysql-scope.yaml @@ -10,5 +10,5 @@ metadata: name: databaserequest-mysql-scope-sample spec: name: first-mysql-scope-db - scope: vip-development + selector: vip-development type: mysql \ No newline at end of file diff --git a/config/samples/crd_v1alpha1_databaserequest_mysql.yaml b/config/samples/crd_v1alpha1_databaserequest_mysql.yaml index 320ca0c..5e84656 100644 --- a/config/samples/crd_v1alpha1_databaserequest_mysql.yaml +++ b/config/samples/crd_v1alpha1_databaserequest_mysql.yaml @@ -10,5 +10,5 @@ metadata: name: databaserequest-mysql-sample spec: name: first-mysql-db - scope: development + selector: development type: mysql \ No newline at end of file diff --git a/config/samples/crd_v1alpha1_databaserequest_postgres.yaml b/config/samples/crd_v1alpha1_databaserequest_postgres.yaml index a1c6c0b..9b4d06b 100644 --- a/config/samples/crd_v1alpha1_databaserequest_postgres.yaml +++ b/config/samples/crd_v1alpha1_databaserequest_postgres.yaml @@ -10,5 +10,5 @@ metadata: name: databaserequest-postgres-sample spec: name: first-postgres-db - scope: development + selector: development type: postgres \ No newline at end of file diff --git a/config/samples/crd_v1alpha1_databaserequest_seed.yaml b/config/samples/crd_v1alpha1_databaserequest_seed.yaml index bbb7a51..f340017 100644 --- a/config/samples/crd_v1alpha1_databaserequest_seed.yaml +++ b/config/samples/crd_v1alpha1_databaserequest_seed.yaml @@ -13,5 +13,5 @@ spec: seed: name: seed-mysql-secret namespace: default - scope: development + selector: development type: mysql \ No newline at end of file diff --git a/config/samples/crd_v1alpha1_mongodbprovider.yaml b/config/samples/crd_v1alpha1_mongodbprovider.yaml index 80d44a2..65e692a 100644 --- a/config/samples/crd_v1alpha1_mongodbprovider.yaml +++ b/config/samples/crd_v1alpha1_mongodbprovider.yaml @@ -6,7 +6,7 @@ metadata: app.kubernetes.io/managed-by: kustomize name: mongodbprovider-sample spec: - scope: development + selector: development connections: - name: primary-test-mongodb-connection hostname: mongodb-service.mongodb diff --git a/config/samples/crd_v1alpha1_relationaldatabaseprovider_mysql-scope.yaml b/config/samples/crd_v1alpha1_relationaldatabaseprovider_mysql-scope.yaml index a305038..bf32b0e 100644 --- a/config/samples/crd_v1alpha1_relationaldatabaseprovider_mysql-scope.yaml +++ b/config/samples/crd_v1alpha1_relationaldatabaseprovider_mysql-scope.yaml @@ -7,7 +7,7 @@ metadata: name: relationaldatabaseprovider-mysql-scope-sample spec: type: mysql - scope: vip-development + selector: vip-development connections: - name: primary-test-mysql-connection hostname: mysql-service.mysql diff --git a/config/samples/crd_v1alpha1_relationaldatabaseprovider_mysql.yaml b/config/samples/crd_v1alpha1_relationaldatabaseprovider_mysql.yaml index f27e361..e1cbd23 100644 --- a/config/samples/crd_v1alpha1_relationaldatabaseprovider_mysql.yaml +++ b/config/samples/crd_v1alpha1_relationaldatabaseprovider_mysql.yaml @@ -7,7 +7,7 @@ metadata: name: relationaldatabaseprovider-mysql-sample spec: type: mysql - scope: development + selector: development connections: - name: primary-test-mysql-connection hostname: mysql-service.mysql diff --git a/config/samples/crd_v1alpha1_relationaldatabaseprovider_postgres.yaml b/config/samples/crd_v1alpha1_relationaldatabaseprovider_postgres.yaml index 2e0a1de..534bac2 100644 --- a/config/samples/crd_v1alpha1_relationaldatabaseprovider_postgres.yaml +++ b/config/samples/crd_v1alpha1_relationaldatabaseprovider_postgres.yaml @@ -7,7 +7,7 @@ metadata: name: relationaldatabaseprovider-postgres-sample spec: type: postgres - scope: development + selector: development connections: - name: primary-test-postgres-connection hostname: postgres-service.postgres diff --git a/internal/controller/databaserequest_controller.go b/internal/controller/databaserequest_controller.go index 3b08298..159ffcf 100644 --- a/internal/controller/databaserequest_controller.go +++ b/internal/controller/databaserequest_controller.go @@ -67,7 +67,7 @@ var ( Name: "databaserequest_reconcile_error_total", Help: "The total number of reconciled database requests errors", }, - []string{"name", "namespace", "scope", "type", "username", "databasename", "error"}, + []string{"name", "namespace", "selector", "type", "username", "databasename", "error"}, ) // promDatabaseRequestReconcileStatus is the status of the reconciled database requests @@ -76,7 +76,7 @@ var ( Name: "databaserequest_reconcile_status", Help: "The status of the reconciled database requests", }, - []string{"name", "namespace", "scope", "type", "username", "databasename"}, + []string{"name", "namespace", "selector", "type", "username", "databasename"}, ) ) @@ -125,7 +125,7 @@ func (r *DatabaseRequestReconciler) Reconcile(ctx context.Context, req ctrl.Requ } return ctrl.Result{}, client.IgnoreNotFound(err) } - logger = logger.WithValues("scope", databaseRequest.Spec.Scope, "type", databaseRequest.Spec.Type) + logger = logger.WithValues("selector", databaseRequest.Spec.Selector, "type", databaseRequest.Spec.Type) log.IntoContext(ctx, logger) if databaseRequest.DeletionTimestamp != nil && !databaseRequest.DeletionTimestamp.IsZero() { @@ -315,7 +315,7 @@ func (r *DatabaseRequestReconciler) handleSeed( ctx, databaseRequest.Spec.Seed, databaseRequest.Spec.Type, - databaseRequest.Spec.Scope, + databaseRequest.Spec.Selector, ) if err != nil { return nil, err @@ -567,7 +567,7 @@ func promLabels(databaseRequest *crdv1alpha1.DatabaseRequest, withError string) labels := prometheus.Labels{ "name": databaseRequest.Name, "namespace": databaseRequest.Namespace, - "scope": databaseRequest.Spec.Scope, + "selector": databaseRequest.Spec.Selector, "type": databaseRequest.Spec.Type, "username": username, "databasename": databaseName, @@ -676,8 +676,8 @@ func (r *DatabaseRequestReconciler) relationalDatabaseOperation( // get the database provider, for info and drop we use the reference which is already set on the database request // if not we error out. - // For create we list all database providers and check if the scope matches and if - // there are more than one provider with the same scope, we select the one with lower load. + // For create we list all database providers and check if the selector matches and if + // there are more than one provider with the same selector, we select the one with lower load. databaseProvider := &crdv1alpha1.RelationalDatabaseProvider{} connectionName := "" if operation == create { @@ -830,7 +830,7 @@ func (r *DatabaseRequestReconciler) relationalDatabaseInfoFromSeed( ctx context.Context, seed *v1.SecretReference, dbType string, - scope string, + selector string, ) (*seedDatabaseInfo, error) { dbInfo, err := r.seedDatabase(ctx, seed) if err != nil { @@ -852,7 +852,7 @@ func (r *DatabaseRequestReconciler) relationalDatabaseInfoFromSeed( var connection *crdv1alpha1.Connection var databaseProviderRef *crdv1alpha1.DatabaseConnectionReference for _, dbProvider := range dbProviders.Items { - if dbProvider.Spec.Scope == scope && dbProvider.Spec.Type == dbType { + if dbProvider.Spec.Selector == selector && dbProvider.Spec.Type == dbType { for _, dbConnection := range dbProvider.Spec.Connections { if dbConnection.Enabled && dbConnection.Hostname == dbInfo.hostName && dbConnection.Port == dbInfo.port { @@ -904,7 +904,7 @@ func (r *DatabaseRequestReconciler) relationalDatabaseInfoFromSeed( return &seedDatabaseInfo{dbInfo: dbInfo, conn: conn, databaseProviderRef: databaseProviderRef}, nil } -// findRelationalDatabaseProvider finds the relational database provider with the same scope and the lower load +// findRelationalDatabaseProvider finds the relational database provider with the same selector and the lower load // returns the provider, connection name and an error func (r *DatabaseRequestReconciler) findRelationalDatabaseProvider( ctx context.Context, @@ -917,13 +917,13 @@ func (r *DatabaseRequestReconciler) findRelationalDatabaseProvider( ) } - // find the provider with the same scope + // find the provider with the same selector // set load to the max int value to find the provider with the lower load := int(^uint(0) >> 1) var provider *crdv1alpha1.RelationalDatabaseProvider var connName string for _, dbProvider := range dbProviders.Items { - if dbProvider.Spec.Scope == databaseRequest.Spec.Scope && dbProvider.Spec.Type == databaseRequest.Spec.Type { + if dbProvider.Spec.Selector == databaseRequest.Spec.Selector && dbProvider.Spec.Type == databaseRequest.Spec.Type { log.FromContext(ctx).Info("Found provider", "provider", dbProvider.Name) for _, dbConnection := range dbProvider.Spec.Connections { if dbConnection.Enabled { diff --git a/internal/controller/databaserequest_controller_test.go b/internal/controller/databaserequest_controller_test.go index d858f74..092da14 100644 --- a/internal/controller/databaserequest_controller_test.go +++ b/internal/controller/databaserequest_controller_test.go @@ -75,8 +75,8 @@ var _ = Describe("DatabaseRequest Controller", func() { Name: dbMySQLProviderResource, }, Spec: crdv1alpha1.RelationalDatabaseProviderSpec{ - Type: "mysql", - Scope: "development", + Type: "mysql", + Selector: "development", Connections: []crdv1alpha1.Connection{ { Name: "test-connection", @@ -107,7 +107,7 @@ var _ = Describe("DatabaseRequest Controller", func() { Namespace: "default", }, Spec: crdv1alpha1.DatabaseRequestSpec{ - Scope: "development", + Selector: "development", Type: "mysql", Name: "mysql-test-database", DropDatabaseOnDelete: false, diff --git a/internal/controller/mongodbprovider_controller.go b/internal/controller/mongodbprovider_controller.go index 16f9a19..87fa1bd 100644 --- a/internal/controller/mongodbprovider_controller.go +++ b/internal/controller/mongodbprovider_controller.go @@ -48,7 +48,7 @@ var ( Name: "mongodbprovider_reconcile_error_total", Help: "The total number of reconciled mongodb providers errors", }, - []string{"name", "scope", "error"}, + []string{"name", "selector", "error"}, ) // promMongoDBProviderStatus is the gauge for the mongodb provider status @@ -57,7 +57,7 @@ var ( Name: "mongodbprovider_status", Help: "The status of the mongodb provider", }, - []string{"name", "scope"}, + []string{"name", "selector"}, ) // promMongoDBProviderConnectionVersion is the gauge for the mongodb provider connection version @@ -66,7 +66,7 @@ var ( Name: "mongodbprovider_connection_version", Help: "The version of the mongodb provider connection", }, - []string{"name", "scope", "hostname", "username", "version"}, + []string{"name", "selector", "hostname", "username", "version"}, ) ) @@ -105,7 +105,7 @@ func (r *MongoDBProviderReconciler) Reconcile(ctx context.Context, req ctrl.Requ promMongoDBProviderReconcileErrorCounter.WithLabelValues(req.Name, "", "get-mongodbprovider").Inc() return ctrl.Result{}, err } - logger = logger.WithValues("scope", instance.Spec.Scope) + logger = logger.WithValues("selector", instance.Spec.Selector) log.IntoContext(ctx, logger) if instance.DeletionTimestamp != nil && !instance.DeletionTimestamp.IsZero() { // The object is being deleted @@ -191,7 +191,7 @@ func (r *MongoDBProviderReconciler) Reconcile(ctx context.Context, req ctrl.Requ Status: "unavailable", }) promMongoDBProviderConnectionVersion.WithLabelValues( - conn.options.Name, instance.Spec.Scope, conn.options.Hostname, conn.options.Username, "", + conn.options.Name, instance.Spec.Selector, conn.options.Hostname, conn.options.Username, "", ).Set(0) logger.Error(err, "Failed to ping MongoDB", "hostname", conn.options.Hostname) continue @@ -207,7 +207,7 @@ func (r *MongoDBProviderReconciler) Reconcile(ctx context.Context, req ctrl.Requ Status: "unavailable", }) promMongoDBProviderConnectionVersion.WithLabelValues( - conn.options.Name, instance.Spec.Scope, conn.options.Hostname, conn.options.Username, version, + conn.options.Name, instance.Spec.Selector, conn.options.Hostname, conn.options.Username, version, ).Set(0) logger.Error(err, "Failed to get MongoDB version", "hostname", conn.options.Hostname) continue @@ -223,11 +223,11 @@ func (r *MongoDBProviderReconciler) Reconcile(ctx context.Context, req ctrl.Requ if conn.enabled { foundEnabledDatabase = true promMongoDBProviderConnectionVersion.WithLabelValues( - conn.options.Name, instance.Spec.Scope, conn.options.Hostname, conn.options.Username, version, + conn.options.Name, instance.Spec.Selector, conn.options.Hostname, conn.options.Username, version, ).Set(1) } else { promMongoDBProviderConnectionVersion.WithLabelValues( - conn.options.Name, instance.Spec.Scope, conn.options.Hostname, conn.options.Username, version, + conn.options.Name, instance.Spec.Selector, conn.options.Hostname, conn.options.Username, version, ).Set(0) } } @@ -257,13 +257,13 @@ func (r *MongoDBProviderReconciler) Reconcile(ctx context.Context, req ctrl.Requ // update the status if err := r.Status().Update(ctx, instance); err != nil { promMongoDBProviderReconcileErrorCounter.WithLabelValues( - req.Name, instance.Spec.Scope, "update-status").Inc() - promMongoDBProviderStatus.WithLabelValues(req.Name, instance.Spec.Scope).Set(0) + req.Name, instance.Spec.Selector, "update-status").Inc() + promMongoDBProviderStatus.WithLabelValues(req.Name, instance.Spec.Selector).Set(0) return ctrl.Result{}, err } r.Recorder.Event(instance, v1.EventTypeNormal, "Reconciled", "MongoDBProvider reconciled") - promMongoDBProviderStatus.WithLabelValues(req.Name, instance.Spec.Scope).Set(1) + promMongoDBProviderStatus.WithLabelValues(req.Name, instance.Spec.Selector).Set(1) return ctrl.Result{}, nil } @@ -273,8 +273,8 @@ func (r *MongoDBProviderReconciler) handleError( promErr string, err error, ) (ctrl.Result, error) { - promMongoDBProviderReconcileErrorCounter.WithLabelValues(instance.Name, instance.Spec.Scope, promErr).Inc() - promMongoDBProviderStatus.WithLabelValues(instance.Name, instance.Spec.Scope).Set(0) + promMongoDBProviderReconcileErrorCounter.WithLabelValues(instance.Name, instance.Spec.Selector, promErr).Inc() + promMongoDBProviderStatus.WithLabelValues(instance.Name, instance.Spec.Selector).Set(0) r.Recorder.Event(instance, v1.EventTypeWarning, errTypeToEventReason(promErr), err.Error()) // set the status condition @@ -287,7 +287,7 @@ func (r *MongoDBProviderReconciler) handleError( // update the status if err := r.Status().Update(ctx, instance); err != nil { - promMongoDBProviderReconcileErrorCounter.WithLabelValues(instance.Name, instance.Spec.Scope, "update-status").Inc() + promMongoDBProviderReconcileErrorCounter.WithLabelValues(instance.Name, instance.Spec.Selector, "update-status").Inc() log.FromContext(ctx).Error(err, "Failed to update status") return ctrl.Result{}, err } diff --git a/internal/controller/mongodbprovider_controller_test.go b/internal/controller/mongodbprovider_controller_test.go index 6159cb3..385f08d 100644 --- a/internal/controller/mongodbprovider_controller_test.go +++ b/internal/controller/mongodbprovider_controller_test.go @@ -74,7 +74,7 @@ var _ = Describe("MongoDBProvider Controller", func() { Namespace: "default", }, Spec: crdv1alpha1.MongoDBProviderSpec{ - Scope: "development", + Selector: "development", Connections: []crdv1alpha1.MongoDBConnection{ { Name: "test-mongodb-connection", diff --git a/internal/controller/relationaldatabaseprovider_controller.go b/internal/controller/relationaldatabaseprovider_controller.go index a19adb3..7f588c0 100644 --- a/internal/controller/relationaldatabaseprovider_controller.go +++ b/internal/controller/relationaldatabaseprovider_controller.go @@ -49,7 +49,7 @@ var ( Name: "relationaldatabaseprovider_reconcile_error_total", Help: "The total number of reconciled relational database providers errors", }, - []string{"type", "name", "scope", "error"}, + []string{"type", "name", "selector", "error"}, ) // promRelationalDatabaseProviderStatus is the gauge for the relational database provider status @@ -58,7 +58,7 @@ var ( Name: "relationaldatabaseprovider_status", Help: "The status of the relational database provider", }, - []string{"type", "name", "scope"}, + []string{"type", "name", "selector"}, ) // promRelationalDatabaseProviderConnectionVersion is the gauge for the relational database provider connection version @@ -67,7 +67,7 @@ var ( Name: "relationaldatabaseprovider_connection_version", Help: "The version of the relational database provider connection", }, - []string{"type", "name", "scope", "hostname", "username", "version"}, + []string{"type", "name", "selector", "hostname", "username", "version"}, ) ) @@ -103,7 +103,7 @@ func (r *RelationalDatabaseProviderReconciler) Reconcile(ctx context.Context, re "", req.Name, "", "get-relationaldbprovider").Inc() return ctrl.Result{}, err } - logger = logger.WithValues("type", instance.Spec.Type, "scope", instance.Spec.Scope) + logger = logger.WithValues("type", instance.Spec.Type, "selector", instance.Spec.Selector) if instance.DeletionTimestamp != nil && !instance.DeletionTimestamp.IsZero() { // The object is being deleted // To be discussed whether we need to delete all the database requests using this provider... @@ -193,7 +193,7 @@ func (r *RelationalDatabaseProviderReconciler) Reconcile(ctx context.Context, re Enabled: conn.enabled, }) promRelationalDatabaseProviderConnectionVersion.WithLabelValues( - instance.Spec.Type, req.Name, instance.Spec.Scope, conn.hostname, conn.username, "").Set(0) + instance.Spec.Type, req.Name, instance.Spec.Selector, conn.hostname, conn.username, "").Set(0) logger.Error(err, "Failed to ping the database", "hostname", conn.hostname) continue } @@ -208,7 +208,7 @@ func (r *RelationalDatabaseProviderReconciler) Reconcile(ctx context.Context, re }) logger.Error(err, "Failed to get the database version", "hostname", conn.hostname) promRelationalDatabaseProviderConnectionVersion.WithLabelValues( - instance.Spec.Type, req.Name, instance.Spec.Scope, conn.hostname, conn.username, version).Set(0) + instance.Spec.Type, req.Name, instance.Spec.Selector, conn.hostname, conn.username, version).Set(0) continue } @@ -223,7 +223,7 @@ func (r *RelationalDatabaseProviderReconciler) Reconcile(ctx context.Context, re Enabled: conn.enabled, }) promRelationalDatabaseProviderConnectionVersion.WithLabelValues( - instance.Spec.Type, req.Name, instance.Spec.Scope, conn.hostname, conn.username, version).Set(0) + instance.Spec.Type, req.Name, instance.Spec.Selector, conn.hostname, conn.username, version).Set(0) continue } @@ -237,10 +237,10 @@ func (r *RelationalDatabaseProviderReconciler) Reconcile(ctx context.Context, re if conn.enabled { foundEnabledDatabase = true promRelationalDatabaseProviderConnectionVersion.WithLabelValues( - instance.Spec.Type, req.Name, instance.Spec.Scope, conn.hostname, conn.username, version).Set(1) + instance.Spec.Type, req.Name, instance.Spec.Selector, conn.hostname, conn.username, version).Set(1) } else { promRelationalDatabaseProviderConnectionVersion.WithLabelValues( - instance.Spec.Type, req.Name, instance.Spec.Scope, conn.hostname, conn.username, version).Set(0) + instance.Spec.Type, req.Name, instance.Spec.Selector, conn.hostname, conn.username, version).Set(0) } } @@ -274,13 +274,13 @@ func (r *RelationalDatabaseProviderReconciler) Reconcile(ctx context.Context, re // update the status if err := r.Status().Update(ctx, instance); err != nil { promRelationalDatabaseProviderReconcileErrorCounter.WithLabelValues( - instance.Spec.Type, req.Name, instance.Spec.Scope, "update-status").Inc() - promRelationalDatabaseProviderStatus.WithLabelValues(instance.Spec.Type, req.Name, instance.Spec.Scope).Set(0) + instance.Spec.Type, req.Name, instance.Spec.Selector, "update-status").Inc() + promRelationalDatabaseProviderStatus.WithLabelValues(instance.Spec.Type, req.Name, instance.Spec.Selector).Set(0) return ctrl.Result{}, err } r.Recorder.Event(instance, "Normal", "Reconciled", "RelationalDatabaseProvider reconciled") - promRelationalDatabaseProviderStatus.WithLabelValues(instance.Spec.Type, req.Name, instance.Spec.Scope).Set(1) + promRelationalDatabaseProviderStatus.WithLabelValues(instance.Spec.Type, req.Name, instance.Spec.Selector).Set(1) return ctrl.Result{}, nil } @@ -292,8 +292,8 @@ func (r *RelationalDatabaseProviderReconciler) handleError( err error, ) (ctrl.Result, error) { promRelationalDatabaseProviderReconcileErrorCounter.WithLabelValues( - instance.Spec.Type, instance.Name, instance.Spec.Scope, promErr).Inc() - promRelationalDatabaseProviderStatus.WithLabelValues(instance.Spec.Type, instance.Name, instance.Spec.Scope).Set(0) + instance.Spec.Type, instance.Name, instance.Spec.Selector, promErr).Inc() + promRelationalDatabaseProviderStatus.WithLabelValues(instance.Spec.Type, instance.Name, instance.Spec.Selector).Set(0) r.Recorder.Event(instance, v1.EventTypeWarning, errTypeToEventReason(promErr), err.Error()) // set the status condition to false @@ -307,7 +307,7 @@ func (r *RelationalDatabaseProviderReconciler) handleError( // update the status if err := r.Status().Update(ctx, instance); err != nil { promRelationalDatabaseProviderReconcileErrorCounter.WithLabelValues( - instance.Spec.Type, instance.Name, instance.Spec.Scope, "update-status").Inc() + instance.Spec.Type, instance.Name, instance.Spec.Selector, "update-status").Inc() log.FromContext(ctx).Error(err, "Failed to update status") } diff --git a/internal/controller/relationaldatabaseprovider_controller_test.go b/internal/controller/relationaldatabaseprovider_controller_test.go index d3f5248..718c9e8 100644 --- a/internal/controller/relationaldatabaseprovider_controller_test.go +++ b/internal/controller/relationaldatabaseprovider_controller_test.go @@ -74,8 +74,8 @@ var _ = Describe("RelationalDatabaseProvider Controller", func() { Namespace: "default", }, Spec: crdv1alpha1.RelationalDatabaseProviderSpec{ - Type: "mysql", - Scope: "custom", + Type: "mysql", + Selector: "custom", Connections: []crdv1alpha1.Connection{ { Name: "test-connection", diff --git a/test/e2e/testdata/crd_v1alpha1_credential_broken_seed_databaserequest.yaml b/test/e2e/testdata/crd_v1alpha1_credential_broken_seed_databaserequest.yaml index 959dec4..28b7c9f 100644 --- a/test/e2e/testdata/crd_v1alpha1_credential_broken_seed_databaserequest.yaml +++ b/test/e2e/testdata/crd_v1alpha1_credential_broken_seed_databaserequest.yaml @@ -13,5 +13,5 @@ spec: name: credential-broken-seed-secret namespace: default name: credential-broken-seed-mysql-db - scope: development + selector: development type: mysql \ No newline at end of file diff --git a/test/e2e/testdata/crd_v1alpha1_non_existing_database_seed_databaserequest.yaml b/test/e2e/testdata/crd_v1alpha1_non_existing_database_seed_databaserequest.yaml index 5c551c6..bf16d6a 100644 --- a/test/e2e/testdata/crd_v1alpha1_non_existing_database_seed_databaserequest.yaml +++ b/test/e2e/testdata/crd_v1alpha1_non_existing_database_seed_databaserequest.yaml @@ -13,5 +13,5 @@ spec: name: non-existing-database-seed-secret namespace: default name: non-existing-database-seed-mysql-db - scope: development + selector: development type: mysql \ No newline at end of file