feat(labels): adopt Kubernetes recommended labels for all CNPG resources#8087
feat(labels): adopt Kubernetes recommended labels for all CNPG resources#8087mnencia merged 22 commits intocloudnative-pg:mainfrom
Conversation
|
❗ By default, the pull request is configured to backport to all release branches.
|
|
@jsilvela could you review when you get a moment? Let me know if you want me to change anything 😊 |
There was a problem hiding this comment.
Very good stuff.
I think it would be good to add simple tests in the various test files for these.
E.g. in services_test.go, the unit tests check for labels like "cnpg.io/instanceRole".
Will not add insight right now, but I'd consider it insurance against inadvertent removal.
fcede6a to
75208b5
Compare
|
@jsilvela I've added the requested tests! let me know if there's anything you want added or changed! |
jsilvela
left a comment
There was a problem hiding this comment.
Good stuff.
The one bit is the tests where the instance name is "-0". Added a suggestion to fix that.
Worth fixing that way or some other way you may think.
Aside from that, looking good.
1294e2f to
6e89c44
Compare
|
/test limit=local |
|
@leonardoce, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/16595476501 |
|
In the maintainers' chat, @sxd rightly pointed out that we should add the other labels that @JefeDavis pointed out initially (see again https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/#labels). Ideally: app.kubernetes.io/name: postgresql
app.kubernetes.io/instance: <CLUSTER NAME>
app.kubernetes.io/version: <POSTGRESQL VERSION OF THE PRIMARY OR THE RUNNING POD (for replicas)>
app.kubernetes.io/component: database
app.kubernetes.io/managed-by: cloudnative-pgThoughts? |
Yes, that is a good idea. |
|
Would you like me to add those to this PR? Or I can do a follow up? Would this affect the selector labels? Or should those be left alone? |
@JefeDavis If you could add them to this PR, it would be great. I won't change the selectors. |
6e89c44 to
c3a7c7a
Compare
|
@leonardoce do you want all those labels added to all objects or just the pods, jobs, and deployments? |
|
would component always be database? i.e. pgBouncer? |
|
I've added labels where i think it makes sense, let me know what you think |
cbff907 to
8c8fce5
Compare
Signed-off-by: Jeff Davis <mr.jefedavis@gmail.com>
Signed-off-by: Jeff Davis <mr.jefedavis@gmail.com>
Signed-off-by: Leonardo Cecchi <leonardo.cecchi@enterprisedb.com>
Co-authored-by: Jaime Silvela <jaime.silvela@mailfence.com> Signed-off-by: Leonardo Cecchi <leonardo.cecchi@gmail.com>
Co-authored-by: Jaime Silvela <jaime.silvela@mailfence.com> Signed-off-by: Leonardo Cecchi <leonardo.cecchi@gmail.com>
Co-authored-by: Jaime Silvela <jaime.silvela@mailfence.com> Signed-off-by: Leonardo Cecchi <leonardo.cecchi@gmail.com>
Co-authored-by: Christian Rolland <c.rolland@protonmail.com> Signed-off-by: Jeff Davis <mr.jefedavis@gmail.com>
Signed-off-by: Jeff Davis <mr.jefedavis@gmail.com>
Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
Signed-off-by: Niccolò Fei <niccolo.fei@enterprisedb.com>
Signed-off-by: Niccolò Fei <niccolo.fei@enterprisedb.com>
Signed-off-by: Niccolò Fei <niccolo.fei@enterprisedb.com>
Signed-off-by: Niccolò Fei <niccolo.fei@enterprisedb.com>
Signed-off-by: Niccolò Fei <niccolo.fei@enterprisedb.com>
…ccount Signed-off-by: Niccolò Fei <niccolo.fei@enterprisedb.com>
Signed-off-by: Niccolò Fei <niccolo.fei@enterprisedb.com>
Signed-off-by: Niccolò Fei <niccolo.fei@enterprisedb.com>
Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
…sion" This reverts commit 2b9fae5. Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
8c8fce5 to
593518c
Compare
Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
…ces (cloudnative-pg#8087) This commit adds the recommended Kubernetes labels to all resources generated by the operator for a cluster. This improves discoverability and allows users to reliably target CNPG-managed resources with `matchLabels` selectors in policy engines, service meshes, and other Kubernetes-native tooling. The following labels are now applied: - `app.kubernetes.io/name`: postgresql - `app.kubernetes.io/instance`: <cluster-name> - `app.kubernetes.io/version`: <postgres-major-version> - `app.kubernetes.io/component`: database - `app.kubernetes.io/managed-by`: cloudnative-pg This change follows the best practices outlined in the official Kubernetes and Helm documentation, ensuring the labels are intuitive and consistent with the broader ecosystem. Closes: cloudnative-pg#8066
Apply Kubernetes recommended labels
(https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/#labels)
to every object managed by CloudNativePG in a PostgreSQL cluster:
app.kubernetes.io/name: postgresqlapp.kubernetes.io/instance:app.kubernetes.io/version:app.kubernetes.io/component: databaseapp.kubernetes.io/managed-by: cloudnative-pgThis ensures consistent labelling and improves integration with
Kubernetes-native tooling and ecosystem practices.
Closes #8066