diff --git a/docs/cluster-connection.md b/docs/cluster-connection.md index d65f2ae..0b88e39 100644 --- a/docs/cluster-connection.md +++ b/docs/cluster-connection.md @@ -12,15 +12,15 @@ Other Custom Resources (like `Database`, `Role`, `Schema`, `Grant`, `DefaultPriv | `host` | `string` | The hostname of the PostgreSQL instance. | Yes | | `port` | `integer` | The port of the PostgreSQL instance (1-65535). | Yes | | `database` | `string` | The database to connect to (usually `postgres` for admin operations). | Yes | -| `adminSecretRef` | `SecretRef` | Reference to the secret containing admin credentials. | Yes | +| `adminSecretRef` | `ResourceRef` | Reference to the Kubernetes Secret containing the admin credentials. | Yes | | `parameters` | `map[string]string` | Additional connection parameters. | No | -### SecretRef +### ResourceRef (`adminSecretRef`) -| Field | Type | Description | Required | -|-------------|----------|---------------------------------------------------------------------|----------| -| `name` | `string` | Name of the secret. | Yes | -| `namespace` | `string` | Namespace of the secret. If not specified, uses the CR's namespace. | No | +| Field | Type | Description | Required | +|-------------|----------|----------------------------------------------------------------------------------------------------|----------| +| `namespace` | `string` | Namespace of the referenced Kubernetes `Secret`. If not specified, uses the owning CR's namespace. | No | +| `name` | `string` | Name of the referenced Kubernetes `Secret`. | Yes | The referenced secret must be of type `kubernetes.io/basic-auth` and contain the keys `username` and `password`. diff --git a/docs/database.md b/docs/database.md index 4f4a88c..d1c7df4 100644 --- a/docs/database.md +++ b/docs/database.md @@ -4,19 +4,19 @@ The `Database` Custom Resource Definition (CRD) is responsible for managing Post ## Spec -| Field | Type | Description | Required | Immutable | -|-----------------|--------------------|------------------------------------------------------------------------------------------------------|----------|-----------| -| `clusterRef` | `ClusterReference` | Reference to the `ClusterConnection` to use. | Yes | No | -| `name` | `string` | The name of the database to create. | Yes | Yes | -| `owner` | `string` | The owner of the database. | No | No | -| `reclaimPolicy` | `string` | The policy for reclaiming the database when the CR is deleted. Values: `Retain` (Default), `Delete`. | No | No | - -### ClusterReference - -| Field | Type | Description | Required | -|-------------|----------|----------------------------------------------------------------------------------|----------| -| `name` | `string` | Name of the `ClusterConnection`. | Yes | -| `namespace` | `string` | Namespace of the `ClusterConnection`. If not specified, uses the CR's namespace. | No | +| Field | Type | Description | Required | Immutable | +|-----------------|---------------|------------------------------------------------------------------------------------------------------|----------|-----------| +| `clusterRef` | `ResourceRef` | Reference to the `ClusterConnection` to use. | Yes | No | +| `name` | `string` | The name of the database to create. | Yes | Yes | +| `owner` | `string` | The owner of the database. | No | No | +| `reclaimPolicy` | `string` | The policy for reclaiming the database when the CR is deleted. Values: `Retain` (Default), `Delete`. | No | No | + +### ResourceRef (`clusterRef`) + +| Field | Type | Description | Required | +|-------------|----------|----------------------------------------------------------------------------------------------------|----------| +| `namespace` | `string` | Namespace of the referenced `ClusterConnection`. If not specified, uses the owning CR's namespace. | No | +| `name` | `string` | Name of the referenced `ClusterConnection`. | Yes | ### Reclaim Policy diff --git a/docs/default-privilege.md b/docs/default-privilege.md index e532671..19d24ae 100644 --- a/docs/default-privilege.md +++ b/docs/default-privilege.md @@ -4,15 +4,15 @@ The `DefaultPrivilege` Custom Resource Definition (CRD) manages default privileg ## Spec -| Field | Type | Description | Required | Immutable | -|--------------|--------------------|---------------------------------------------------------------------------------------------------------|-------------|-----------| -| `clusterRef` | `ClusterReference` | Reference to the `ClusterConnection` to use. | Yes | No | -| `database` | `string` | The database where default privileges apply. | Yes | Yes | -| `role` | `string` | The role to which default privileges are granted. | Yes | Yes | -| `owner` | `string` | The role that owns the objects (the creator). Default privileges apply to objects created by this role. | Yes | Yes | -| `schema` | `string` | The schema where default privileges apply. Required, unless `objectType` is `schema`. | Conditional | Yes | -| `objectType` | `string` | The type of object. | Yes | Yes | -| `privileges` | `array[string]` | List of privileges to grant. | Yes | No | +| Field | Type | Description | Required | Immutable | +|--------------|-----------------|---------------------------------------------------------------------------------------------------------|-------------|-----------| +| `clusterRef` | `ResourceRef` | Reference to the `ClusterConnection` to use. | Yes | No | +| `database` | `string` | The database where default privileges apply. | Yes | Yes | +| `role` | `string` | The role to which default privileges are granted. | Yes | Yes | +| `owner` | `string` | The role that owns the objects (the creator). Default privileges apply to objects created by this role. | Yes | Yes | +| `schema` | `string` | The schema where default privileges apply. Required, unless `objectType` is `schema`. | Conditional | Yes | +| `objectType` | `string` | The type of object. | Yes | Yes | +| `privileges` | `array[string]` | List of privileges to grant. | Yes | No | ### Object Types @@ -39,12 +39,12 @@ Supported privileges depend on the `objectType`: - `update` - `usage` -### ClusterReference +### ResourceRef (`clusterRef`) -| Field | Type | Description | Required | -|-------------|----------|----------------------------------------------------------------------------------|----------| -| `name` | `string` | Name of the `ClusterConnection`. | Yes | -| `namespace` | `string` | Namespace of the `ClusterConnection`. If not specified, uses the CR's namespace. | No | +| Field | Type | Description | Required | +|-------------|----------|----------------------------------------------------------------------------------------------------|----------| +| `namespace` | `string` | Namespace of the referenced `ClusterConnection`. If not specified, uses the owning CR's namespace. | No | +| `name` | `string` | Name of the referenced `ClusterConnection`. | Yes | ## Example diff --git a/docs/grant.md b/docs/grant.md index 1517d1f..7c24d9f 100644 --- a/docs/grant.md +++ b/docs/grant.md @@ -4,15 +4,15 @@ The `Grant` Custom Resource Definition (CRD) is responsible for managing privile ## Spec -| Field | Type | Description | Required | Immutable | -|--------------|--------------------|--------------------------------------------------------------------------------------------------------------------------------------------|-------------|-----------| -| `clusterRef` | `ClusterReference` | Reference to the `ClusterConnection` to use. | Yes | No | -| `database` | `string` | The database containing the objects. | Yes | Yes | -| `role` | `string` | The role to which privileges are granted. | Yes | Yes | -| `schema` | `string` | The schema containing the objects. Required, unless `objectType` is `database`. | Conditional | Yes | -| `objectType` | `string` | The type of object. | Yes | Yes | -| `objects` | `array[string]` | List of object names. If empty, all objects of this `objectType` will be granted. Required, unless `objectType` is `database` or `schema`. | Conditional | No | -| `privileges` | `array[string]` | List of privileges to grant. | Yes | No | +| Field | Type | Description | Required | Immutable | +|--------------|-----------------|--------------------------------------------------------------------------------------------------------------------------------------------|-------------|-----------| +| `clusterRef` | `ResourceRef` | Reference to the `ClusterConnection` to use. | Yes | No | +| `database` | `string` | The database containing the objects. | Yes | Yes | +| `role` | `string` | The role to which privileges are granted. | Yes | Yes | +| `schema` | `string` | The schema containing the objects. Required, unless `objectType` is `database`. | Conditional | Yes | +| `objectType` | `string` | The type of object. | Yes | Yes | +| `objects` | `array[string]` | List of object names. If empty, all objects of this `objectType` will be granted. Required, unless `objectType` is `database` or `schema`. | Conditional | No | +| `privileges` | `array[string]` | List of privileges to grant. | Yes | No | ### Object Types @@ -40,12 +40,12 @@ Supported privileges depend on the `objectType`: - `update` - `usage` -### ClusterReference +### ResourceRef (`clusterRef`) -| Field | Type | Description | Required | -|-------------|----------|----------------------------------------------------------------------------------|----------| -| `name` | `string` | Name of the `ClusterConnection`. | Yes | -| `namespace` | `string` | Namespace of the `ClusterConnection`. If not specified, uses the CR's namespace. | No | +| Field | Type | Description | Required | +|-------------|----------|----------------------------------------------------------------------------------------------------|----------| +| `namespace` | `string` | Namespace of the referenced `ClusterConnection`. If not specified, uses the owning CR's namespace. | No | +| `name` | `string` | Name of the referenced `ClusterConnection`. | Yes | ## Example diff --git a/docs/role.md b/docs/role.md index 75ee361..dddeb59 100644 --- a/docs/role.md +++ b/docs/role.md @@ -4,20 +4,24 @@ The `Role` Custom Resource Definition (CRD) manages PostgreSQL roles (users). ## Spec -| Field | Type | Description | Required | Immutable | -|---------------------|--------------------|-------------------------------------------------------------------------------------|----------|-----------| -| `clusterRef` | `ClusterReference` | Reference to the `ClusterConnection` to use. | Yes | No | -| `name` | `string` | The name of the role to create in the database. | Yes | Yes | -| `comment` | `string` | A comment to add to the role. | No | No | -| `passwordSecretRef` | `SecretRef` | Reference to a secret containing the password for the role to make it a LOGIN role. | No | No | -| `flags` | `RoleFlags` | Flags and attributes for the role. | No | No | +| Field | Type | Description | Required | Immutable | +|---------------------|---------------|-------------------------------------------------------------------------------------|----------|-----------| +| `clusterRef` | `ResourceRef` | Reference to the `ClusterConnection` to use. | Yes | No | +| `name` | `string` | The name of the role to create in the database. | Yes | Yes | +| `comment` | `string` | A comment to add to the role. | No | No | +| `passwordSecretRef` | `ResourceRef` | Reference to a secret containing the password for the role to make it a LOGIN role. | No | No | +| `flags` | `RoleFlags` | Flags and attributes for the role. | No | No | -### ClusterReference +### ResourceRef (`clusterRef` and `passwordSecretRef`) -| Field | Type | Description | Required | -|-------------|----------|----------------------------------------------------------------------------------|----------| -| `name` | `string` | Name of the `ClusterConnection`. | Yes | -| `namespace` | `string` | Namespace of the `ClusterConnection`. If not specified, uses the CR's namespace. | No | +| Field | Type | Description | Required | +|-------------|----------|-----------------------------------------------------------------------------------------|----------| +| `namespace` | `string` | Namespace of the referenced resource. If not specified, uses the owning CR's namespace. | No | +| `name` | `string` | Name of the referenced Kubernetes resource. | Yes | + +**Note**: +When used as `passwordSecretRef`, the referenced Kubernetes Secret must be of type `kubernetes.io/basic-auth`. +The `username` key in the Secret is not strictly required, as the role name is specified by the `name` field in the CRD. Only the `password` key is used. ### RoleFlags @@ -34,17 +38,6 @@ The `Role` Custom Resource Definition (CRD) manages PostgreSQL roles (users). | `superuser` | `boolean` | `false` | Superuser status. | | `validUntil` | `string` | `null` | Date and time until the password is valid (ISO 8601). | -### SecretRef - -| Field | Type | Description | Required | -|-------------|----------|---------------------------------------------------------------------|----------| -| `name` | `string` | Name of the secret. | Yes | -| `namespace` | `string` | Namespace of the secret. If not specified, uses the CR's namespace. | No | - -The referenced secret must be of type `kubernetes.io/basic-auth`. - -**Note**: The `username` key in the secret is not strictly required, as the role name is specified by the `name` field in the CRD. Only the `password` key is used. - ### Login vs No-Login Roles The operator uses the presence of the `passwordSecretRef` field to determine if the role should have the `LOGIN` privilege (User) or not (Group). diff --git a/docs/schema.md b/docs/schema.md index 0d08235..edd70a4 100644 --- a/docs/schema.md +++ b/docs/schema.md @@ -4,20 +4,20 @@ The `Schema` Custom Resource Definition (CRD) is responsible for managing Postgr ## Spec -| Field | Type | Description | Required | Immutable | -|-----------------|--------------------|----------------------------------------------------------------------------------------------------|----------|-----------| -| `clusterRef` | `ClusterReference` | Reference to the `ClusterConnection` to use. | Yes | No | -| `database` | `string` | The name of the database in which the schema is created. | Yes | Yes | -| `name` | `string` | The name of the schema to create. | Yes | Yes | -| `owner` | `string` | The owner of the schema. | No | No | -| `reclaimPolicy` | `string` | The policy for reclaiming the schema when the CR is deleted. Values: `Retain` (Default), `Delete`. | No | No | - -### ClusterReference - -| Field | Type | Description | Required | -|-------------|----------|----------------------------------------------------------------------------------|----------| -| `name` | `string` | Name of the `ClusterConnection`. | Yes | -| `namespace` | `string` | Namespace of the `ClusterConnection`. If not specified, uses the CR's namespace. | No | +| Field | Type | Description | Required | Immutable | +|-----------------|---------------|----------------------------------------------------------------------------------------------------|----------|-----------| +| `clusterRef` | `ResourceRef` | Reference to the `ClusterConnection` to use. | Yes | No | +| `database` | `string` | The name of the database in which the schema is created. | Yes | Yes | +| `name` | `string` | The name of the schema to create. | Yes | Yes | +| `owner` | `string` | The owner of the schema. | No | No | +| `reclaimPolicy` | `string` | The policy for reclaiming the schema when the CR is deleted. Values: `Retain` (Default), `Delete`. | No | No | + +### ResourceRef (`clusterRef`) + +| Field | Type | Description | Required | +|-------------|----------|----------------------------------------------------------------------------------------------------|----------| +| `namespace` | `string` | Namespace of the referenced `ClusterConnection`. If not specified, uses the owning CR's namespace. | No | +| `name` | `string` | Name of the referenced `ClusterConnection`. | Yes | ### Reclaim Policy diff --git a/operator/src/main/java/it/aboutbits/postgresql/core/BaseReconciler.java b/operator/src/main/java/it/aboutbits/postgresql/core/BaseReconciler.java index f12d71d..306b069 100644 --- a/operator/src/main/java/it/aboutbits/postgresql/core/BaseReconciler.java +++ b/operator/src/main/java/it/aboutbits/postgresql/core/BaseReconciler.java @@ -49,7 +49,7 @@ public String getResourceNamespaceOrOwn( public Optional getReferencedClusterConnection( KubernetesClient kubernetesClient, CR resource, - ClusterReference clusterRef + ResourceRef clusterRef ) { var connectionName = clusterRef.getName(); var connectionNamespace = getResourceNamespaceOrOwn(resource, clusterRef.getNamespace()); diff --git a/operator/src/main/java/it/aboutbits/postgresql/core/ClusterReference.java b/operator/src/main/java/it/aboutbits/postgresql/core/ClusterReference.java deleted file mode 100644 index 735b444..0000000 --- a/operator/src/main/java/it/aboutbits/postgresql/core/ClusterReference.java +++ /dev/null @@ -1,30 +0,0 @@ -package it.aboutbits.postgresql.core; - -import io.fabric8.crdv2.generator.v1.SchemaCustomizer; -import io.fabric8.generator.annotation.Max; -import io.fabric8.generator.annotation.Required; -import io.fabric8.generator.annotation.ValidationRule; -import it.aboutbits.postgresql.core.schema_customizer.KubernetesNameCustomizer; -import lombok.Getter; -import lombok.Setter; -import org.jspecify.annotations.NullMarked; -import org.jspecify.annotations.Nullable; - -@NullMarked -@Getter -@Setter -@SchemaCustomizer(KubernetesNameCustomizer.class) -public class ClusterReference { - @Required - @Max(63) - @ValidationRule( - value = "self.trim().size() > 0", - message = "The ClusterReference name must not be empty." - ) - private String name = ""; - - @Nullable - @Max(63) - @io.fabric8.generator.annotation.Nullable - private String namespace; -} diff --git a/operator/src/main/java/it/aboutbits/postgresql/core/KubernetesService.java b/operator/src/main/java/it/aboutbits/postgresql/core/KubernetesService.java index 2252b1a..203cdd5 100644 --- a/operator/src/main/java/it/aboutbits/postgresql/core/KubernetesService.java +++ b/operator/src/main/java/it/aboutbits/postgresql/core/KubernetesService.java @@ -28,7 +28,7 @@ public Credentials getSecretRefCredentials( public Credentials getSecretRefCredentials( KubernetesClient kubernetesClient, - SecretRef secretRef, + ResourceRef secretRef, String defaultNamespace ) { var secretNamespace = secretRef.getNamespace() != null @@ -43,14 +43,14 @@ public Credentials getSecretRefCredentials( .get(); if (secret == null) { - throw new IllegalStateException("SecretRef not found [secret.namespace=%s, secret.name=%s]".formatted( + throw new IllegalStateException("Secret reference not found [secret.namespace=%s, secret.name=%s]".formatted( secretNamespace, secretName )); } if (!secret.getType().equals(SECRET_TYPE_BASIC_AUTH)) { - throw new IllegalArgumentException("The SecretRef is of the wrong type [secret.namespace=%s, secret.name=%s, expected.secret.type=%s, actual.secret.type=%s]".formatted( + throw new IllegalArgumentException("The Secret reference is of the wrong type [secret.namespace=%s, secret.name=%s, expected.secret.type=%s, actual.secret.type=%s]".formatted( secretNamespace, secretName, SECRET_TYPE_BASIC_AUTH, @@ -60,7 +60,7 @@ public Credentials getSecretRefCredentials( var data = secret.getData(); if (data == null || data.isEmpty()) { - throw new IllegalStateException("The SecretRef has no data set [secret.namespace=%s, secret.name=%s]".formatted( + throw new IllegalStateException("The Secret reference has no data set [secret.namespace=%s, secret.name=%s]".formatted( secretNamespace, secretName )); @@ -76,7 +76,7 @@ public Credentials getSecretRefCredentials( var passwordBase64 = data.get(SECRET_DATA_BASIC_AUTH_PASSWORD_KEY); if (passwordBase64 == null) { - throw new IllegalStateException("The SecretRef is missing required data password [secret.namespace=%s, secret.name=%s]".formatted( + throw new IllegalStateException("The Secret reference is missing required data password [secret.namespace=%s, secret.name=%s]".formatted( secretNamespace, secretName )); diff --git a/operator/src/main/java/it/aboutbits/postgresql/core/ResourceRef.java b/operator/src/main/java/it/aboutbits/postgresql/core/ResourceRef.java new file mode 100644 index 0000000..549380e --- /dev/null +++ b/operator/src/main/java/it/aboutbits/postgresql/core/ResourceRef.java @@ -0,0 +1,48 @@ +package it.aboutbits.postgresql.core; + +import io.fabric8.crdv2.generator.v1.SchemaCustomizer; +import io.fabric8.generator.annotation.Max; +import io.fabric8.generator.annotation.Required; +import io.fabric8.generator.annotation.ValidationRule; +import it.aboutbits.postgresql.core.schema_customizer.KubernetesNameCustomizer; +import lombok.Getter; +import lombok.Setter; +import org.jspecify.annotations.NullMarked; +import org.jspecify.annotations.Nullable; + +/// A reference to a Kubernetes resource identified by [#namespace] (optional) and [#name]. +/// +/// This class is used wherever a CRD spec needs to point to another Kubernetes resource. +/// +/// ### Namespace resolution +/// +/// The [#namespace] field is **nullable**. When it is `null` (or omitted +/// in the CR manifest), the operator resolves the target resource in the +/// **same namespace as the CR that contains the reference**. This convention +/// keeps single-namespace deployments simple — users only need to set +/// `namespace` when referring to a resource in a *different* namespace. +/// +/// | `namespace` value | Resolved namespace | +/// |-------------------|-----------------------------------------------------| +/// | non-null | the explicit namespace | +/// | `null` (omitted) | the namespace of the CR that owns this reference | +@NullMarked +@Getter +@Setter +@SchemaCustomizer(KubernetesNameCustomizer.class) +public class ResourceRef { + /// The namespace of the referenced Kubernetes resource. + /// If `null`, defaults to the namespace of the CR that defines this reference. + @Nullable + @Max(63) + @io.fabric8.generator.annotation.Nullable + private String namespace; + + @Required + @Max(63) + @ValidationRule( + value = "self.trim().size() > 0", + message = "The name must not be empty." + ) + private String name = ""; +} diff --git a/operator/src/main/java/it/aboutbits/postgresql/core/SecretRef.java b/operator/src/main/java/it/aboutbits/postgresql/core/SecretRef.java deleted file mode 100644 index 628dfca..0000000 --- a/operator/src/main/java/it/aboutbits/postgresql/core/SecretRef.java +++ /dev/null @@ -1,34 +0,0 @@ -package it.aboutbits.postgresql.core; - -import io.fabric8.crdv2.generator.v1.SchemaCustomizer; -import io.fabric8.generator.annotation.Max; -import io.fabric8.generator.annotation.Required; -import io.fabric8.generator.annotation.ValidationRule; -import it.aboutbits.postgresql.core.schema_customizer.KubernetesNameCustomizer; -import lombok.Getter; -import lombok.Setter; -import org.jspecify.annotations.NullMarked; -import org.jspecify.annotations.Nullable; - -@NullMarked -@Getter -@Setter -@SchemaCustomizer(KubernetesNameCustomizer.class) -public class SecretRef { - @Required - @Max(63) - @ValidationRule( - value = "self.trim().size() > 0", - message = "The SecretRef name must not be empty." - ) - private String name = ""; - - /** - * The namespace where the Secret is located. - * If it is null, it means the Secret is in the same namespace as the resource referencing it. - */ - @Nullable - @Max(63) - @io.fabric8.generator.annotation.Nullable - private String namespace; -} diff --git a/operator/src/main/java/it/aboutbits/postgresql/crd/clusterconnection/ClusterConnectionReconciler.java b/operator/src/main/java/it/aboutbits/postgresql/crd/clusterconnection/ClusterConnectionReconciler.java index 56430f0..a5aca3a 100644 --- a/operator/src/main/java/it/aboutbits/postgresql/crd/clusterconnection/ClusterConnectionReconciler.java +++ b/operator/src/main/java/it/aboutbits/postgresql/crd/clusterconnection/ClusterConnectionReconciler.java @@ -26,8 +26,8 @@ public UpdateControl reconcile( ) { var status = initializeStatus(resource); - var name = resource.getMetadata().getName(); var namespace = resource.getMetadata().getNamespace(); + var name = resource.getMetadata().getName(); log.info( "Reconciling ClusterConnection [resource={}/{}, status.phase={}]", diff --git a/operator/src/main/java/it/aboutbits/postgresql/crd/clusterconnection/ClusterConnectionSpec.java b/operator/src/main/java/it/aboutbits/postgresql/crd/clusterconnection/ClusterConnectionSpec.java index b4c472c..0fe7123 100644 --- a/operator/src/main/java/it/aboutbits/postgresql/crd/clusterconnection/ClusterConnectionSpec.java +++ b/operator/src/main/java/it/aboutbits/postgresql/crd/clusterconnection/ClusterConnectionSpec.java @@ -5,7 +5,7 @@ import io.fabric8.generator.annotation.Min; import io.fabric8.generator.annotation.Required; import io.fabric8.generator.annotation.ValidationRule; -import it.aboutbits.postgresql.core.SecretRef; +import it.aboutbits.postgresql.core.ResourceRef; import it.aboutbits.postgresql.core.schema_customizer.HostCustomizer; import lombok.Getter; import lombok.Setter; @@ -39,7 +39,7 @@ public class ClusterConnectionSpec { private String database = "postgres"; @Required - private SecretRef adminSecretRef = new SecretRef(); + private ResourceRef adminSecretRef = new ResourceRef(); @io.fabric8.generator.annotation.Nullable private Map parameters = new HashMap<>(); diff --git a/operator/src/main/java/it/aboutbits/postgresql/crd/database/DatabaseReconciler.java b/operator/src/main/java/it/aboutbits/postgresql/crd/database/DatabaseReconciler.java index 8e96de0..111af70 100644 --- a/operator/src/main/java/it/aboutbits/postgresql/crd/database/DatabaseReconciler.java +++ b/operator/src/main/java/it/aboutbits/postgresql/crd/database/DatabaseReconciler.java @@ -38,8 +38,8 @@ public UpdateControl reconcile( var spec = resource.getSpec(); var status = initializeStatus(resource); - var name = resource.getMetadata().getName(); var namespace = resource.getMetadata().getNamespace(); + var name = resource.getMetadata().getName(); log.info( "Reconciling Database [resource={}/{}, status.phase={}]", @@ -97,8 +97,8 @@ public DeleteControl cleanup( var spec = resource.getSpec(); var status = initializeStatus(resource); - var name = resource.getMetadata().getName(); var namespace = resource.getMetadata().getNamespace(); + var name = resource.getMetadata().getName(); log.info( "{}ing Database [resource={}/{}, spec.name={}, status.phase={}]", @@ -183,8 +183,8 @@ private UpdateControl reconcile( Database resource, CRStatus status ) { - var name = resource.getMetadata().getName(); var namespace = resource.getMetadata().getNamespace(); + var name = resource.getMetadata().getName(); var spec = resource.getSpec(); diff --git a/operator/src/main/java/it/aboutbits/postgresql/crd/database/DatabaseSpec.java b/operator/src/main/java/it/aboutbits/postgresql/crd/database/DatabaseSpec.java index 0eadc44..168d1c7 100644 --- a/operator/src/main/java/it/aboutbits/postgresql/crd/database/DatabaseSpec.java +++ b/operator/src/main/java/it/aboutbits/postgresql/crd/database/DatabaseSpec.java @@ -2,8 +2,8 @@ import io.fabric8.generator.annotation.Required; import io.fabric8.generator.annotation.ValidationRule; -import it.aboutbits.postgresql.core.ClusterReference; import it.aboutbits.postgresql.core.ReclaimPolicy; +import it.aboutbits.postgresql.core.ResourceRef; import lombok.Getter; import lombok.Setter; import org.jspecify.annotations.NullMarked; @@ -14,7 +14,7 @@ @Setter public class DatabaseSpec { @Required - private ClusterReference clusterRef = new ClusterReference(); + private ResourceRef clusterRef = new ResourceRef(); @Required @ValidationRule( diff --git a/operator/src/main/java/it/aboutbits/postgresql/crd/defaultprivilege/DefaultPrivilegeReconciler.java b/operator/src/main/java/it/aboutbits/postgresql/crd/defaultprivilege/DefaultPrivilegeReconciler.java index 6b2c315..038c131 100644 --- a/operator/src/main/java/it/aboutbits/postgresql/crd/defaultprivilege/DefaultPrivilegeReconciler.java +++ b/operator/src/main/java/it/aboutbits/postgresql/crd/defaultprivilege/DefaultPrivilegeReconciler.java @@ -41,8 +41,8 @@ public UpdateControl reconcile( var spec = resource.getSpec(); var status = initializeStatus(resource); - var name = resource.getMetadata().getName(); var namespace = resource.getMetadata().getNamespace(); + var name = resource.getMetadata().getName(); log.info( "Reconciling DefaultPrivilege [resource={}/{}, status.phase={}]", @@ -124,8 +124,8 @@ public DeleteControl cleanup( var spec = resource.getSpec(); var status = initializeStatus(resource); - var name = resource.getMetadata().getName(); var namespace = resource.getMetadata().getNamespace(); + var name = resource.getMetadata().getName(); log.info( "Deleting DefaultPrivilege [resource={}/{}, status.phase={}]", @@ -213,8 +213,8 @@ private UpdateControl reconcileInTransaction( ) { var spec = resource.getSpec(); - var name = resource.getMetadata().getName(); var namespace = resource.getMetadata().getNamespace(); + var name = resource.getMetadata().getName(); var expectedPrivileges = Set.copyOf(spec.getPrivileges()); diff --git a/operator/src/main/java/it/aboutbits/postgresql/crd/defaultprivilege/DefaultPrivilegeSpec.java b/operator/src/main/java/it/aboutbits/postgresql/crd/defaultprivilege/DefaultPrivilegeSpec.java index 51e8ef0..a29afa0 100644 --- a/operator/src/main/java/it/aboutbits/postgresql/crd/defaultprivilege/DefaultPrivilegeSpec.java +++ b/operator/src/main/java/it/aboutbits/postgresql/crd/defaultprivilege/DefaultPrivilegeSpec.java @@ -4,8 +4,8 @@ import com.fasterxml.jackson.annotation.JsonInclude; import io.fabric8.generator.annotation.Required; import io.fabric8.generator.annotation.ValidationRule; -import it.aboutbits.postgresql.core.ClusterReference; import it.aboutbits.postgresql.core.Privilege; +import it.aboutbits.postgresql.core.ResourceRef; import lombok.Getter; import lombok.Setter; import org.jspecify.annotations.NullMarked; @@ -23,7 +23,7 @@ ) public class DefaultPrivilegeSpec { @Required - private ClusterReference clusterRef = new ClusterReference(); + private ResourceRef clusterRef = new ResourceRef(); /// The database to grant default privileges on for this role. @Required diff --git a/operator/src/main/java/it/aboutbits/postgresql/crd/grant/GrantReconciler.java b/operator/src/main/java/it/aboutbits/postgresql/crd/grant/GrantReconciler.java index cfd8a25..4739683 100644 --- a/operator/src/main/java/it/aboutbits/postgresql/crd/grant/GrantReconciler.java +++ b/operator/src/main/java/it/aboutbits/postgresql/crd/grant/GrantReconciler.java @@ -46,8 +46,8 @@ public UpdateControl reconcile( var spec = resource.getSpec(); var status = initializeStatus(resource); - var name = resource.getMetadata().getName(); var namespace = resource.getMetadata().getNamespace(); + var name = resource.getMetadata().getName(); log.info( "Reconciling Grant [resource={}/{}, status.phase={}]", @@ -129,8 +129,8 @@ public DeleteControl cleanup( var spec = resource.getSpec(); var status = initializeStatus(resource); - var name = resource.getMetadata().getName(); var namespace = resource.getMetadata().getNamespace(); + var name = resource.getMetadata().getName(); log.info( "Deleting Grant [resource={}/{}, status.phase={}]", @@ -220,8 +220,8 @@ private UpdateControl reconcileInTransaction( Grant resource, CRStatus status ) { - var name = resource.getMetadata().getName(); var namespace = resource.getMetadata().getNamespace(); + var name = resource.getMetadata().getName(); var spec = resource.getSpec(); diff --git a/operator/src/main/java/it/aboutbits/postgresql/crd/grant/GrantSpec.java b/operator/src/main/java/it/aboutbits/postgresql/crd/grant/GrantSpec.java index 62ccafe..09b3568 100644 --- a/operator/src/main/java/it/aboutbits/postgresql/crd/grant/GrantSpec.java +++ b/operator/src/main/java/it/aboutbits/postgresql/crd/grant/GrantSpec.java @@ -4,8 +4,8 @@ import com.fasterxml.jackson.annotation.JsonInclude; import io.fabric8.generator.annotation.Required; import io.fabric8.generator.annotation.ValidationRule; -import it.aboutbits.postgresql.core.ClusterReference; import it.aboutbits.postgresql.core.Privilege; +import it.aboutbits.postgresql.core.ResourceRef; import lombok.Getter; import lombok.Setter; import org.jspecify.annotations.NullMarked; @@ -27,7 +27,7 @@ ) public class GrantSpec { @Required - private ClusterReference clusterRef = new ClusterReference(); + private ResourceRef clusterRef = new ResourceRef(); /// The database to grant privileges on for this role. @Required diff --git a/operator/src/main/java/it/aboutbits/postgresql/crd/role/RoleReconciler.java b/operator/src/main/java/it/aboutbits/postgresql/crd/role/RoleReconciler.java index d7a062b..6ac0d10 100644 --- a/operator/src/main/java/it/aboutbits/postgresql/crd/role/RoleReconciler.java +++ b/operator/src/main/java/it/aboutbits/postgresql/crd/role/RoleReconciler.java @@ -60,8 +60,8 @@ public UpdateControl reconcile( var spec = resource.getSpec(); var status = initializeStatus(resource); - var name = resource.getMetadata().getName(); var namespace = resource.getMetadata().getNamespace(); + var name = resource.getMetadata().getName(); log.info( "Reconciling Role [resource={}/{}, status.phase={}]", @@ -140,8 +140,8 @@ public DeleteControl cleanup( var spec = resource.getSpec(); var status = initializeStatus(resource); - var name = resource.getMetadata().getName(); var namespace = resource.getMetadata().getNamespace(); + var name = resource.getMetadata().getName(); log.info( "Deleting Role [resource={}/{}, spec.name={}, status.phase={}]", @@ -249,8 +249,8 @@ private UpdateControl reconcileInTransaction( CRStatus status, @Nullable String password ) { - var name = resource.getMetadata().getName(); var namespace = resource.getMetadata().getNamespace(); + var name = resource.getMetadata().getName(); var spec = resource.getSpec(); var expectedFlags = spec.getFlags(); diff --git a/operator/src/main/java/it/aboutbits/postgresql/crd/role/RoleSpec.java b/operator/src/main/java/it/aboutbits/postgresql/crd/role/RoleSpec.java index 1207cfe..55775db 100644 --- a/operator/src/main/java/it/aboutbits/postgresql/crd/role/RoleSpec.java +++ b/operator/src/main/java/it/aboutbits/postgresql/crd/role/RoleSpec.java @@ -2,8 +2,7 @@ import io.fabric8.generator.annotation.Required; import io.fabric8.generator.annotation.ValidationRule; -import it.aboutbits.postgresql.core.ClusterReference; -import it.aboutbits.postgresql.core.SecretRef; +import it.aboutbits.postgresql.core.ResourceRef; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; @@ -19,7 +18,7 @@ @Setter public class RoleSpec { @Required - private ClusterReference clusterRef = new ClusterReference(); + private ResourceRef clusterRef = new ResourceRef(); @Required @ValidationRule( @@ -38,7 +37,7 @@ public class RoleSpec { @Nullable @io.fabric8.generator.annotation.Nullable - private SecretRef passwordSecretRef; + private ResourceRef passwordSecretRef; @io.fabric8.generator.annotation.Nullable private Flags flags = new Flags(); diff --git a/operator/src/main/java/it/aboutbits/postgresql/crd/schema/SchemaReconciler.java b/operator/src/main/java/it/aboutbits/postgresql/crd/schema/SchemaReconciler.java index 9b56749..b05f6d9 100644 --- a/operator/src/main/java/it/aboutbits/postgresql/crd/schema/SchemaReconciler.java +++ b/operator/src/main/java/it/aboutbits/postgresql/crd/schema/SchemaReconciler.java @@ -38,8 +38,8 @@ public UpdateControl reconcile( var spec = resource.getSpec(); var status = initializeStatus(resource); - var name = resource.getMetadata().getName(); var namespace = resource.getMetadata().getNamespace(); + var name = resource.getMetadata().getName(); log.info( "Reconciling Schema [resource={}/{}, status.phase={}]", @@ -100,8 +100,8 @@ public DeleteControl cleanup( var spec = resource.getSpec(); var status = initializeStatus(resource); - var name = resource.getMetadata().getName(); var namespace = resource.getMetadata().getNamespace(); + var name = resource.getMetadata().getName(); log.info( "{}ing Schema [resource={}/{}, spec.name={}, status.phase={}]", @@ -187,8 +187,8 @@ private UpdateControl reconcileInTransaction( Schema resource, CRStatus status ) { - var name = resource.getMetadata().getName(); var namespace = resource.getMetadata().getNamespace(); + var name = resource.getMetadata().getName(); var spec = resource.getSpec(); diff --git a/operator/src/main/java/it/aboutbits/postgresql/crd/schema/SchemaSpec.java b/operator/src/main/java/it/aboutbits/postgresql/crd/schema/SchemaSpec.java index b9568a8..6843400 100644 --- a/operator/src/main/java/it/aboutbits/postgresql/crd/schema/SchemaSpec.java +++ b/operator/src/main/java/it/aboutbits/postgresql/crd/schema/SchemaSpec.java @@ -2,8 +2,8 @@ import io.fabric8.generator.annotation.Required; import io.fabric8.generator.annotation.ValidationRule; -import it.aboutbits.postgresql.core.ClusterReference; import it.aboutbits.postgresql.core.ReclaimPolicy; +import it.aboutbits.postgresql.core.ResourceRef; import lombok.Getter; import lombok.Setter; import org.jspecify.annotations.NullMarked; @@ -14,7 +14,7 @@ @Setter public class SchemaSpec { @Required - private ClusterReference clusterRef = new ClusterReference(); + private ResourceRef clusterRef = new ResourceRef(); @Required @ValidationRule( diff --git a/operator/src/test/java/it/aboutbits/postgresql/_support/testdata/persisted/creator/ClusterConnectionCreate.java b/operator/src/test/java/it/aboutbits/postgresql/_support/testdata/persisted/creator/ClusterConnectionCreate.java index 169fd19..d1f1699 100644 --- a/operator/src/test/java/it/aboutbits/postgresql/_support/testdata/persisted/creator/ClusterConnectionCreate.java +++ b/operator/src/test/java/it/aboutbits/postgresql/_support/testdata/persisted/creator/ClusterConnectionCreate.java @@ -4,7 +4,7 @@ import io.fabric8.kubernetes.client.KubernetesClient; import it.aboutbits.postgresql._support.testdata.base.TestDataCreator; import it.aboutbits.postgresql._support.testdata.persisted.Given; -import it.aboutbits.postgresql.core.SecretRef; +import it.aboutbits.postgresql.core.ResourceRef; import it.aboutbits.postgresql.crd.clusterconnection.ClusterConnection; import it.aboutbits.postgresql.crd.clusterconnection.ClusterConnectionSpec; import lombok.AccessLevel; @@ -44,7 +44,7 @@ public class ClusterConnectionCreate extends TestDataCreator private String withDatabase; @Nullable - private SecretRef withAdminSecretRef; + private ResourceRef withAdminSecretRef; @Nullable private String withApplicationName; @@ -161,7 +161,7 @@ private String getDatabase() { return withDatabase; } - private SecretRef getAdminSecretRef() { + private ResourceRef getAdminSecretRef() { if (withAdminSecretRef != null) { return withAdminSecretRef; } diff --git a/operator/src/test/java/it/aboutbits/postgresql/_support/testdata/persisted/creator/DatabaseCreate.java b/operator/src/test/java/it/aboutbits/postgresql/_support/testdata/persisted/creator/DatabaseCreate.java index f4988ba..9125706 100644 --- a/operator/src/test/java/it/aboutbits/postgresql/_support/testdata/persisted/creator/DatabaseCreate.java +++ b/operator/src/test/java/it/aboutbits/postgresql/_support/testdata/persisted/creator/DatabaseCreate.java @@ -4,8 +4,8 @@ import io.fabric8.kubernetes.client.KubernetesClient; import it.aboutbits.postgresql._support.testdata.base.TestDataCreator; import it.aboutbits.postgresql._support.testdata.persisted.Given; -import it.aboutbits.postgresql.core.ClusterReference; import it.aboutbits.postgresql.core.ReclaimPolicy; +import it.aboutbits.postgresql.core.ResourceRef; import it.aboutbits.postgresql.crd.database.Database; import it.aboutbits.postgresql.crd.database.DatabaseSpec; import lombok.AccessLevel; @@ -72,7 +72,7 @@ protected Database create(int index) { .build() ); - var clusterRef = new ClusterReference(); + var clusterRef = new ResourceRef(); clusterRef.setName(getClusterConnectionName()); clusterRef.setNamespace(withClusterConnectionNamespace); diff --git a/operator/src/test/java/it/aboutbits/postgresql/_support/testdata/persisted/creator/DefaultPrivilegeCreate.java b/operator/src/test/java/it/aboutbits/postgresql/_support/testdata/persisted/creator/DefaultPrivilegeCreate.java index 50b1cf0..ec88f17 100644 --- a/operator/src/test/java/it/aboutbits/postgresql/_support/testdata/persisted/creator/DefaultPrivilegeCreate.java +++ b/operator/src/test/java/it/aboutbits/postgresql/_support/testdata/persisted/creator/DefaultPrivilegeCreate.java @@ -4,8 +4,8 @@ import io.fabric8.kubernetes.client.KubernetesClient; import it.aboutbits.postgresql._support.testdata.base.TestDataCreator; import it.aboutbits.postgresql._support.testdata.persisted.Given; -import it.aboutbits.postgresql.core.ClusterReference; import it.aboutbits.postgresql.core.Privilege; +import it.aboutbits.postgresql.core.ResourceRef; import it.aboutbits.postgresql.crd.defaultprivilege.DefaultPrivilege; import it.aboutbits.postgresql.crd.defaultprivilege.DefaultPrivilegeObjectType; import it.aboutbits.postgresql.crd.defaultprivilege.DefaultPrivilegeSpec; @@ -101,7 +101,7 @@ protected DefaultPrivilege create(int index) { .build() ); - var clusterRef = new ClusterReference(); + var clusterRef = new ResourceRef(); clusterRef.setName(getClusterConnectionName()); clusterRef.setNamespace(withClusterConnectionNamespace); diff --git a/operator/src/test/java/it/aboutbits/postgresql/_support/testdata/persisted/creator/GrantCreate.java b/operator/src/test/java/it/aboutbits/postgresql/_support/testdata/persisted/creator/GrantCreate.java index 4314969..0dd78f9 100644 --- a/operator/src/test/java/it/aboutbits/postgresql/_support/testdata/persisted/creator/GrantCreate.java +++ b/operator/src/test/java/it/aboutbits/postgresql/_support/testdata/persisted/creator/GrantCreate.java @@ -4,8 +4,8 @@ import io.fabric8.kubernetes.client.KubernetesClient; import it.aboutbits.postgresql._support.testdata.base.TestDataCreator; import it.aboutbits.postgresql._support.testdata.persisted.Given; -import it.aboutbits.postgresql.core.ClusterReference; import it.aboutbits.postgresql.core.Privilege; +import it.aboutbits.postgresql.core.ResourceRef; import it.aboutbits.postgresql.crd.grant.Grant; import it.aboutbits.postgresql.crd.grant.GrantObjectType; import it.aboutbits.postgresql.crd.grant.GrantSpec; @@ -114,7 +114,7 @@ protected Grant create(int index) { .build() ); - var clusterRef = new ClusterReference(); + var clusterRef = new ResourceRef(); clusterRef.setName(getClusterConnectionName()); clusterRef.setNamespace(withClusterConnectionNamespace); diff --git a/operator/src/test/java/it/aboutbits/postgresql/_support/testdata/persisted/creator/RoleCreate.java b/operator/src/test/java/it/aboutbits/postgresql/_support/testdata/persisted/creator/RoleCreate.java index b0d48da..9d5ca0e 100644 --- a/operator/src/test/java/it/aboutbits/postgresql/_support/testdata/persisted/creator/RoleCreate.java +++ b/operator/src/test/java/it/aboutbits/postgresql/_support/testdata/persisted/creator/RoleCreate.java @@ -4,8 +4,7 @@ import io.fabric8.kubernetes.client.KubernetesClient; import it.aboutbits.postgresql._support.testdata.base.TestDataCreator; import it.aboutbits.postgresql._support.testdata.persisted.Given; -import it.aboutbits.postgresql.core.ClusterReference; -import it.aboutbits.postgresql.core.SecretRef; +import it.aboutbits.postgresql.core.ResourceRef; import it.aboutbits.postgresql.crd.role.Role; import it.aboutbits.postgresql.crd.role.RoleSpec; import lombok.AccessLevel; @@ -42,7 +41,7 @@ public class RoleCreate extends TestDataCreator { private String withClusterConnectionNamespace; @Nullable - private SecretRef withPasswordSecretRef; + private ResourceRef withPasswordSecretRef; private RoleSpec.@Nullable Flags withFlags; @@ -93,7 +92,7 @@ protected Role create(int index) { .build() ); - var clusterRef = new ClusterReference(); + var clusterRef = new ResourceRef(); clusterRef.setName(getClusterConnectionName()); clusterRef.setNamespace(withClusterConnectionNamespace); diff --git a/operator/src/test/java/it/aboutbits/postgresql/_support/testdata/persisted/creator/SchemaCreate.java b/operator/src/test/java/it/aboutbits/postgresql/_support/testdata/persisted/creator/SchemaCreate.java index 9136b9c..14ac58f 100644 --- a/operator/src/test/java/it/aboutbits/postgresql/_support/testdata/persisted/creator/SchemaCreate.java +++ b/operator/src/test/java/it/aboutbits/postgresql/_support/testdata/persisted/creator/SchemaCreate.java @@ -4,8 +4,8 @@ import io.fabric8.kubernetes.client.KubernetesClient; import it.aboutbits.postgresql._support.testdata.base.TestDataCreator; import it.aboutbits.postgresql._support.testdata.persisted.Given; -import it.aboutbits.postgresql.core.ClusterReference; import it.aboutbits.postgresql.core.ReclaimPolicy; +import it.aboutbits.postgresql.core.ResourceRef; import it.aboutbits.postgresql.crd.schema.Schema; import it.aboutbits.postgresql.crd.schema.SchemaSpec; import lombok.AccessLevel; @@ -80,7 +80,7 @@ protected Schema create(int index) { // We have to create the database first which also modifies the specified withClusterConnectionName so the connection points to the newly created DB var database = getDatabase(); - var clusterRef = new ClusterReference(); + var clusterRef = new ResourceRef(); clusterRef.setName(getClusterConnectionName()); clusterRef.setNamespace(withClusterConnectionNamespace); diff --git a/operator/src/test/java/it/aboutbits/postgresql/_support/testdata/persisted/creator/SecretRefCreate.java b/operator/src/test/java/it/aboutbits/postgresql/_support/testdata/persisted/creator/SecretRefCreate.java index 11ccb49..d085751 100644 --- a/operator/src/test/java/it/aboutbits/postgresql/_support/testdata/persisted/creator/SecretRefCreate.java +++ b/operator/src/test/java/it/aboutbits/postgresql/_support/testdata/persisted/creator/SecretRefCreate.java @@ -3,7 +3,7 @@ import io.fabric8.kubernetes.api.model.SecretBuilder; import io.fabric8.kubernetes.client.KubernetesClient; import it.aboutbits.postgresql._support.testdata.base.TestDataCreator; -import it.aboutbits.postgresql.core.SecretRef; +import it.aboutbits.postgresql.core.ResourceRef; import lombok.AccessLevel; import lombok.Setter; import lombok.experimental.Accessors; @@ -17,7 +17,7 @@ @NullMarked @Setter @Accessors(fluent = true, chain = true) -public class SecretRefCreate extends TestDataCreator { +public class SecretRefCreate extends TestDataCreator { private final KubernetesClient kubernetesClient; @Nullable @@ -65,7 +65,7 @@ public SecretRefCreate withoutPassword() { } @Override - protected SecretRef create(int index) { + protected ResourceRef create(int index) { var namespace = getNamespace(); var name = getName(); @@ -84,7 +84,7 @@ protected SecretRef create(int index) { .resource(secret) .serverSideApply(); - var secretRef = new SecretRef(); + var secretRef = new ResourceRef(); secretRef.setName(name); secretRef.setNamespace(namespace); diff --git a/operator/src/test/java/it/aboutbits/postgresql/crd/role/RoleReconcilerTest.java b/operator/src/test/java/it/aboutbits/postgresql/crd/role/RoleReconcilerTest.java index 41df236..16b312b 100644 --- a/operator/src/test/java/it/aboutbits/postgresql/crd/role/RoleReconcilerTest.java +++ b/operator/src/test/java/it/aboutbits/postgresql/crd/role/RoleReconcilerTest.java @@ -9,7 +9,7 @@ import it.aboutbits.postgresql.core.CRStatus; import it.aboutbits.postgresql.core.PostgreSQLAuthenticationService; import it.aboutbits.postgresql.core.PostgreSQLContextFactory; -import it.aboutbits.postgresql.core.SecretRef; +import it.aboutbits.postgresql.core.ResourceRef; import lombok.RequiredArgsConstructor; import org.jooq.DSLContext; import org.jooq.Field; @@ -203,7 +203,7 @@ void createRole_withMissingClusterConnection_setsPending() { var now = OffsetDateTime.now(ZoneOffset.UTC); - var dummySecretRef = new SecretRef(); + var dummySecretRef = new ResourceRef(); dummySecretRef.setName("dummy"); // when