feat(chart): apply commonLabels to all rendered resources - #739
Merged
Conversation
## What this PR does
Adds `commonLabels` support to the helm-dashboard chart, allowing users
to define a set of labels that are applied to all chart-managed resources.
## Why
Teams running helm-dashboard in shared or multi-tenant clusters commonly
need to attach labels to all resources for:
- Cost allocation and chargeback (e.g. `team:`, `env:`, `cost-center:`)
- Network policy targeting
- Label-based selectors and queries (e.g. in Prometheus, Grafana, kubectl)
- Compliance and audit requirements
Currently the chart only supports labels on the PersistentVolumeClaim
(`dashboard.persistence.labels`). There is no way to label the
Deployment, Service, ServiceAccount, Ingress, or pod template without
forking the chart.
## Changes
- Add `commonLabels: {}` to `values.yaml`
- Apply the helper to all chart-managed resources:
- Deployment (metadata + pod template)
- Service
- ServiceAccount
- Ingress
## Usage
```yaml
commonLabels:
team: platform
env: production
cost-center: infra
```
## References
- Similar implementation in prometheus-community charts:
prometheus-community/helm-charts#6608
The commonLabels value was declared but never referenced by any template, so setting it had no effect. Merge it into the helm-dashboard.labels helper, which every resource already includes, and into the Deployment pod template. Pod selector labels are deliberately left alone: spec.selector is immutable, so folding commonLabels in there would break helm upgrade on existing releases. ClusterRole and ClusterRoleBinding carried no labels at all; they now get the standard label block, which is the only change to the default render. Also wires up dashboard.persistence.labels, documented in values.yaml but likewise referenced by no template, and adds the missing README rows. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #739 +/- ##
==========================================
+ Coverage 21.92% 28.42% +6.49%
==========================================
Files 14 15 +1
Lines 2239 2565 +326
==========================================
+ Hits 491 729 +238
- Misses 1701 1764 +63
- Partials 47 72 +25 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
|
Thanks for improving on my MR and taking it forward with #739. Appreciate it! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #730 — carries @ashutoshbhardwaj007's original commit and adds the templating that makes the value do something.
Problem
commonLabelswas declared invalues.yamlbut referenced by no template, so setting it produced no labels anywhere.dashboard.persistence.labelshas the same defect: documented invalues.yaml, used by nothing.Change
commonLabelsmerged into thehelm-dashboard.labelshelper, which every resource already includesspec.selector.matchLabels, which is immutable; folding them in there would breakhelm upgradeon existing releasesdashboard.persistence.labelswired into the PVCcommonLabels,dashboard.persistence.labelsanddashboard.persistence.annotationsVerification
helm lintclean. WithcommonLabelsset, all 8 rendered resources carry them (ServiceAccount, PVC, ClusterRole, ClusterRoleBinding, Service, Deployment metadata + pod template, Ingress, test Pod) whilespec.selectorrenders byte-identical tomain.Rendered with defaults, the only diff against
mainis the new label block on ClusterRole/ClusterRoleBinding. Keys containing dots and values like"1.0"or""round-trip correctly throughtoYaml.Closes #730
🤖 Generated with Claude Code