Skip to content

feat(labels): adopt Kubernetes recommended labels for all CNPG resources#8087

Merged
mnencia merged 22 commits intocloudnative-pg:mainfrom
JefeDavis:add-managed-by-label
Nov 3, 2025
Merged

feat(labels): adopt Kubernetes recommended labels for all CNPG resources#8087
mnencia merged 22 commits intocloudnative-pg:mainfrom
JefeDavis:add-managed-by-label

Conversation

@JefeDavis
Copy link
Contributor

@JefeDavis JefeDavis commented Jul 21, 2025

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: postgresql
  • app.kubernetes.io/instance:
  • app.kubernetes.io/version:
  • app.kubernetes.io/component: database
  • app.kubernetes.io/managed-by: cloudnative-pg

This ensures consistent labelling and improves integration with
Kubernetes-native tooling and ecosystem practices.

Closes #8066

@JefeDavis JefeDavis requested review from a team and jsilvela as code owners July 21, 2025 16:35
@cnpg-bot cnpg-bot added backport-requested ◀️ This pull request should be backported to all supported releases release-1.22 release-1.25 release-1.26 labels Jul 21, 2025
@github-actions
Copy link
Contributor

❗ By default, the pull request is configured to backport to all release branches.

  • To stop backporting this pr, remove the label: backport-requested ◀️ or add the label 'do not backport'
  • To stop backporting this pr to a certain release branch, remove the specific branch label: release-x.y

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. documentation 📖 Improvements or additions to documentation enhancement 🪄 New feature or request labels Jul 21, 2025
@JefeDavis
Copy link
Contributor Author

@jsilvela could you review when you get a moment? Let me know if you want me to change anything 😊

Copy link
Collaborator

@jsilvela jsilvela left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@JefeDavis JefeDavis force-pushed the add-managed-by-label branch from fcede6a to 75208b5 Compare July 27, 2025 03:49
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jul 27, 2025
@JefeDavis
Copy link
Contributor Author

@jsilvela I've added the requested tests! let me know if there's anything you want added or changed!

Copy link
Collaborator

@jsilvela jsilvela left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@leonardoce leonardoce force-pushed the add-managed-by-label branch 2 times, most recently from 1294e2f to 6e89c44 Compare July 29, 2025 11:38
@leonardoce
Copy link
Contributor

/test limit=local

@github-actions
Copy link
Contributor

@leonardoce, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/16595476501

@gbartolini
Copy link
Contributor

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-pg

Thoughts?

@leonardoce
Copy link
Contributor

Thoughts?

Yes, that is a good idea.

@JefeDavis
Copy link
Contributor Author

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?

@cnpg-bot cnpg-bot added the ok to merge 👌 This PR can be merged label Jul 29, 2025
@leonardoce
Copy link
Contributor

Would you like me to add those to this PR? Or I can do a follow up?

@JefeDavis If you could add them to this PR, it would be great. I won't change the selectors.
Thanks!

@leonardoce leonardoce force-pushed the add-managed-by-label branch from 6e89c44 to c3a7c7a Compare July 30, 2025 08:53
@JefeDavis
Copy link
Contributor Author

@leonardoce do you want all those labels added to all objects or just the pods, jobs, and deployments?

@JefeDavis
Copy link
Contributor Author

would component always be database? i.e. pgBouncer?

@JefeDavis
Copy link
Contributor Author

I've added labels where i think it makes sense, let me know what you think

@mnencia mnencia force-pushed the add-managed-by-label branch from cbff907 to 8c8fce5 Compare November 3, 2025 13:03
JefeDavis and others added 21 commits November 3, 2025 14:04
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>
@mnencia mnencia force-pushed the add-managed-by-label branch from 8c8fce5 to 593518c Compare November 3, 2025 13:04
Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
@mnencia mnencia removed backport-requested ◀️ This pull request should be backported to all supported releases release-1.25 release-1.26 release-1.27 labels Nov 3, 2025
@mnencia mnencia merged commit 8a42f80 into cloudnative-pg:main Nov 3, 2025
25 checks passed
Samyak2605 pushed a commit to Samyak2605/cloudnative-pg that referenced this pull request Nov 6, 2025
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation 📖 Improvements or additions to documentation enhancement 🪄 New feature or request lgtm This PR has been approved by a maintainer ok to merge 👌 This PR can be merged size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Add standard label to all CNPG-managed pods for policy targeting

9 participants