feat(serviceaccount): support shared ServiceAccount across clusters and poolers#9287
Conversation
|
❗ By default, the pull request is configured to backport to all release branches.
|
a4f2a4f to
cdc0384
Compare
cdc0384 to
f263f28
Compare
|
/test |
|
@armru, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/19936223914 |
|
/test |
|
@armru, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/19965529026 |
|
@bozkayasalihx pushed a partial review, can you check my changes? Could you also add e2e test coverage for the pooler? |
|
@armru I'll review your changes this weekend and add the pooler e2e test. |
@bozkayasalihx , Have you got the chance to review this PR. |
|
@armru i've reviewed your PR and thanks for adding additional tests. i've added pooler e2e test. |
|
@armru Did you have a chance to look at the commit I sent? |
|
@bozkayasalihx I pushed a few review commits on top of your work. The main changes are: added DNS name validation to the CRD fields, restructured e2e tests into unit tests keeping only slim smoke tests in e2e, and added a doc note about RBAC accumulation with shared ServiceAccounts. I also created #10276 to track the feature. |
7c1fb34 to
f725e65
Compare
|
/test |
|
@mnencia, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/22913622673 |
Add optional ServiceAccountName field to ClusterSpec and PoolerSpec to allow users to specify an existing ServiceAccount instead of having the operator create a new one. This enables sharing a single ServiceAccount across multiple clusters, which is particularly useful for cloud IAM configurations where multiple clusters need the same cloud resource access permissions. The field is mutually exclusive with ServiceAccountTemplate. If not specified, the operator will continue to create a ServiceAccount with the cluster/pooler name as before. Signed-off-by: Salih Bozkaya <[email protected]>
Add support for specifying existing ServiceAccounts for both Cluster and Pooler resources, enabling multiple resources to share the same ServiceAccount for cloud IAM configurations. Signed-off-by: Salih Bozkaya <[email protected]>
Add comprehensive unit tests for the ServiceAccountName functionality in both Cluster and Pooler resources. Signed-off-by: Salih Bozkaya <[email protected]>
Add end-to-end tests to verify shared ServiceAccount functionality across multiple clusters and error handling. Test scenarios: - Multiple clusters sharing a single ServiceAccount - Verify pods use the shared ServiceAccount correctly - Validate no auto-created ServiceAccount when custom name is provided - Confirm error handling when specified ServiceAccount doesn't exist Includes fixture files demonstrating real-world cloud IAM use case with AWS IRSA annotation example. Signed-off-by: Salih Bozkaya <[email protected]>
…s_sa.yaml` Signed-off-by: Salih Bozkaya <[email protected]>
Signed-off-by: Armando Ruocco <[email protected]>
Signed-off-by: Salih Bozkaya <[email protected]>
Signed-off-by: Armando Ruocco <[email protected]>
Signed-off-by: Salih Bozkaya <[email protected]>
Signed-off-by: Salih Bozkaya <[email protected]>
…ability Change Pooler's ServiceAccountName from *string to string to match the Cluster API convention, eliminating inconsistent nil-checking patterns and unnecessary pointer deepcopy logic. Add CEL immutability validation (self == oldSelf) to prevent changes to serviceAccountName after creation, consistent with the Cluster field behavior. Also adds documentation for Pooler shared ServiceAccount usage in the security docs Signed-off-by: Armando Ruocco <[email protected]>
Signed-off-by: Marco Nenciarini <[email protected]>
Signed-off-by: Marco Nenciarini <[email protected]>
Assisted-by: Claude Opus 4.6 Signed-off-by: Marco Nenciarini <[email protected]>
Signed-off-by: Marco Nenciarini <[email protected]>
Add RoleBinding subjects verification to rolebinding_test.go and pgbouncer/rbac_test.go, cluster controller RoleBinding test with custom SA, and pooler controller tests for validateExistingServiceAccount and updateRBAC with custom ServiceAccount. Assisted-by: Claude Opus 4.6 Signed-off-by: Marco Nenciarini <[email protected]>
Replace 4 e2e test scenarios per resource type with a single smoke test each that verifies the end-to-end happy path: create shared SA, create cluster/pooler referencing it, verify pods use it, delete the resource, and confirm the shared SA is preserved. Detailed assertions (RoleBinding subjects, non-existent SA handling, mixed mode) are now covered by unit tests. Assisted-by: Claude Opus 4.6 Signed-off-by: Marco Nenciarini <[email protected]>
Add Pattern and MaxLength kubebuilder markers to ensure the serviceAccountName field conforms to Kubernetes DNS subdomain naming rules. Clarify in the field description that the ServiceAccount must be in the same namespace. Assisted-by: Claude Opus 4.6 Signed-off-by: Marco Nenciarini <[email protected]>
Signed-off-by: Marco Nenciarini <[email protected]>
Signed-off-by: Marco Nenciarini <[email protected]>
f725e65 to
6882561
Compare
LGTM!, Thanks |
Add an optional
serviceAccountNamefield to bothClusterSpecandPoolerSpecthat allows referencing a pre-existing ServiceAccount instead of having the operator create one per resource. This enables one-time IAM configuration (AWS IRSA, GCP Workload Identity, Azure Workload Identity) that works across all clusters and poolers using that ServiceAccount.When specified, the operator validates the referenced ServiceAccount exists, skips creating an operator-managed one, and uses it in pod specs, job specs, deployments, and RoleBinding subjects. The field is immutable once set, mutually exclusive with
serviceAccountTemplateon Cluster, and validated against DNS subdomain naming rules. No breaking changes — defaults to the resource name when not specified.Closes #10276