Commit Graph

6 Commits

Author SHA1 Message Date
Armando Ruocco
807e862422 fix: align label values with issue #545 spec
The original PR set the recommended labels to:
  app.kubernetes.io/name="postgresql"  (utils.AppName, the cnpg
                                         operator's identity)
  app.kubernetes.io/version=<cluster PG major>

Per issue #545 the plugin's RBAC objects should advertise the
plugin's own identity:
  app.kubernetes.io/name="barman-cloud-plugin"
  app.kubernetes.io/version=<plugin semver>

Use metadata.Data.Version for the version value (always set,
never conditional on cluster image), drop the cnpg
GetPostgresqlMajorVersion lookup (irrelevant to plugin RBAC and
fragile against the cnpg PostgresImageName default), and extract
the plugin-local AppLabelValue and ManagedByLabelValue constants
so test and production share a single source of truth. The
labels_test.go helper now also asserts the version's value, not
just the key.

Document on metadata.ClusterLabelName that it's a discovery
contract for objectstore_controller.go (which selects on the
key), so the dual-labeling scheme (the legacy cluster label
alongside the K8s recommended labels) is explicit and the
legacy key cannot be silently removed by a later cleanup.

Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
2026-04-29 10:54:54 +02:00
Armando Ruocco
a4b0f428b8 refactor: rename label builder to BuildLabels, move into labels.go
The package is already named specs, the file content is label
construction, and a separate metadata package exists at
internal/cnpgi/metadata; labels.go describes the file directly
without the package-name collision. BuildLabels also matches
the verb convention already used elsewhere in the package
(BuildRole, BuildRoleBinding, BuildRoleRules).

No behavior change.

Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
2026-04-29 10:54:54 +02:00
Gabriele Fedi
b03fd973f1 test: unit tests
Signed-off-by: Gabriele Fedi <gabriele.fedi@enterprisedb.com>
2026-04-29 10:54:54 +02:00
Gabriele Fedi
48575f5f8c fix: merge labels instead of replacing
Signed-off-by: Gabriele Fedi <gabriele.fedi@enterprisedb.com>
2026-04-29 10:54:54 +02:00
Gabriele Fedi
3b6c25c2dc feat: configure k8s recommended labels on subresources
Signed-off-by: Gabriele Fedi <gabriele.fedi@enterprisedb.com>
2026-04-29 10:54:54 +02:00
Armando Ruocco
8971a397f4
fix(rbac): reconcile Role when ObjectStore spec changes (#823)
When an ObjectStore's credentials change (e.g., secret rename), the
RBAC Role granting the Cluster's ServiceAccount access to those
secrets was not updated because nothing triggered a Cluster
reconciliation.

Implement the ObjectStore controller's Reconcile to detect affected
Roles and update their rules directly, without needing access to
Cluster objects. The controller lists Roles by a label set by the
Pre hook, inspects their rules to find which ObjectStores they
reference, fetches those ObjectStores, and patches the rules to
match the current specs.

Replace the custom setOwnerReference helper with
controllerutil.SetControllerReference. Add dynamic CNPG scheme
registration (internal/scheme) to the operator, instance, and
restore managers.

Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
Signed-off-by: Gabriele Quaresima <gabriele.quaresima@enterprisedb.com>
Co-authored-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
Co-authored-by: Gabriele Quaresima <gabriele.quaresima@enterprisedb.com>
2026-04-13 15:48:35 +02:00