charts icon indicating copy to clipboard operation
charts copied to clipboard

Any way to add pod labels ?

Open apresse-orisha opened this issue 8 months ago • 5 comments

Hello,

An issue have already been raised about this: PR merged but it seems to have been rollbacked. https://github.com/cloudnative-pg/charts/issues/94

Is there any way to add labels to pods from chart ? (like .Values.podLabels)

Looking forward for any tips or resolution.

Regards, AP

apresse-orisha avatar Sep 08 '25 15:09 apresse-orisha

Hi @apresse-orisha! I'm Dosu and I’m helping the charts team.

There isn't currently a supported way to add pod labels directly via Helm chart values like .Values.podLabels in CloudNativePG. Although the values.yaml file includes a podLabels field, the feature was rolled back after an earlier PR and is not functional in the current chart templates or operator logic. No workaround is documented for this approach, and this remains an open feature request in the project discussions.

The recommended method is to define your desired labels in the metadata.labels section of your Cluster manifest and configure the operator to enable label inheritance. This way, the labels will be propagated to all pods created by the cluster. You can find more details and examples in the official documentation: CloudNativePG labels and annotations.

If you need to add labels for other resources like PodMonitor, note that similar limitations exist and manual edits may be required for now. Keep an eye on the linked issue for any updates on this feature.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

dosubot[bot] avatar Sep 08 '25 15:09 dosubot[bot]

Thanks @dosu but having this in my operator values

podLabels:
  environment: "test"

config:
  data:
    INHERITED_LABELS: "environment"

If i'm trying to deploy a cluster the environment label doesn't inherit. Could you please explain ?

apresse-orisha avatar Sep 08 '25 16:09 apresse-orisha

Hi @apresse-orisha , I was struggling with the same, but for annotations, in order to use k8up for automatic backups.

This worked on me:

  • Helm release for the operator (adding values there did not help).
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
  name: cnpg-operator
  namespace: cnpg
spec:
  interval: 30m
  chart:
    spec:
      chart: cloudnative-pg
      version: "0.26.0"
      sourceRef:
        kind: HelmRepository
        name: cnpg
        namespace: cnpg
  values: {}
  • Then I had to create a config map where I added my annotations:
apiVersion: v1
kind: ConfigMap
metadata:
  name: cnpg-controller-manager-config
  namespace: cnpg
data:
  INHERITED_ANNOTATIONS: k8up.io/backupcommand,k8up.io/file-extension

  • And finally in my Cluster:
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
  name: cnpg
  namespace: cnpg
  annotations:
    k8up.io/backupcommand: >-
      sh -c 'PGDATABASE=immich pg_dump --clean'
    k8up.io/file-extension: .sql

JanBenisek avatar Sep 14 '25 08:09 JanBenisek

Thanks @JanBenisek, i'll try this out for Labels ;)

apresse-orisha avatar Sep 15 '25 07:09 apresse-orisha

@JanBenisek thanks, your comment probably saved me quite some time figuring this out! This worked for my use case (same as yours) as well. On my side (using the helm chart) all that was required was

config:
  data:
    INHERITED_ANNOTATIONS: k8up.io/backupcommand,k8up.io/file-extension

in the operator's helm chart values file.

akosiaris avatar Oct 23 '25 19:10 akosiaris

Hi, @apresse-orisha. I'm Dosu, and I'm helping the charts team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You inquired about adding custom pod labels via the Helm chart after a previous PR was reverted.
  • It was clarified that direct support for podLabels is currently not functional.
  • The recommended approach is to use label inheritance by setting labels in the Cluster manifest and configuring the operator.
  • A working example for inheriting annotations was shared and appreciated, with confirmation from other users that this method works for labels as well.
  • The issue was effectively resolved using this label inheritance method.

Next Steps:

  • Please let me know if this issue is still relevant with the latest version of the charts by commenting here.
  • Otherwise, I will automatically close this issue in 7 days.

Thank you for your understanding and contribution!

dosubot[bot] avatar Jan 22 '26 16:01 dosubot[bot]