Skip to content

Commit

Permalink
[common-library] Fix long labels (#1553)
Browse files Browse the repository at this point in the history
#### Is this a new chart
No.

#### What this PR does / why we need it:
Name for objects [must contain the release
name](https://github.com/newrelic/helm-charts/blob/3c4caf34eb91a4139fc59ce7b05ff84331d00a41/library/common-library/templates/_naming.tpl#L57-L59)
(if user does not use `fullnameOverride`)

While `newrelic.common.naming.fullname` is truncated, it [will not be
truncated while templating
labels](https://github.com/newrelic/helm-charts/blob/3c4caf34eb91a4139fc59ce7b05ff84331d00a41/library/common-library/templates/_labels.tpl#L31).

This truncate all labels to fit into 63 chars.

#### Checklist
- [x] Chart Version bumped
- [x] Variables are documented in the README.md
- [x] Title of the PR starts with chart name (e.g. `[mychartname]`)

Co-authored-by: Daniel Budziwojski <[email protected]>
  • Loading branch information
kang-makes and dbudziwojskiNR authored Jan 7, 2025
1 parent f46b646 commit b42bd69
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
6 changes: 3 additions & 3 deletions library/CHART-TEMPLATE/Chart.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
dependencies:
- name: common-library
repository: file://../common-library
version: 1.3.0
digest: sha256:862a49e42a8198a0070eb5ddae2a2d1e535f9e2e8d75e3ec17d722552a0e7c4e
generated: "2024-08-13T16:29:35.296624+02:00"
version: 1.3.1
digest: sha256:c374be8bee22252f0314aedcb958b3a0b8c383bcc2b643d187623ac1d2e2530b
generated: "2024-12-13T13:53:06.655412+01:00"
4 changes: 2 additions & 2 deletions library/CHART-TEMPLATE/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 1.3.0
version: 1.3.1

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand All @@ -25,7 +25,7 @@ appVersion: "1.16.0"

dependencies:
- name: common-library
version: 1.3.0
version: 1.3.1
repository: file://../common-library # We keep this as a file to test things immediately locally/in the pipeline

keywords:
Expand Down
21 changes: 21 additions & 0 deletions library/CHART-TEMPLATE/tests/cl-labels_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,24 @@ tests:
helm.sh/chart: fixed
one: overwriting
two: second

- it: truncates long labels
set:
serviceAccount:
create: true
labels:
a-label-that-should-fail: a-really-long-label-that-should-break-labels-because-it-has-68-chars-with-final-dash
a-label-that-should-fail-2: a-really-long-label-that-should-break-labels-but-this-time-without-final-dash
helm.sh/chart: fixed
asserts:
- equal:
path: metadata.labels
value:
# a-label-that-should-fail: a-really-long-label-that-should-break-labels-because-it-has-68- but the final dash should be removed.
a-label-that-should-fail: a-really-long-label-that-should-break-labels-because-it-has-68
a-label-that-should-fail-2: a-really-long-label-that-should-break-labels-but-this-time-with
app.kubernetes.io/instance: my-release
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: CHART-TEMPLATE
app.kubernetes.io/version: 1.16.0
helm.sh/chart: fixed
2 changes: 1 addition & 1 deletion library/common-library/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: common-library
description: Provides helpers to provide consistency on all the charts

type: library
version: 1.3.0
version: 1.3.1

keywords:
- newrelic
Expand Down
4 changes: 4 additions & 0 deletions library/common-library/templates/_labels.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ This will render the labels that should be used in all the manifests used by the

{{- $labels = mustMergeOverwrite $labels $globalUserLabels $localUserLabels -}}

{{- range $k, $v := $labels -}}
{{- $_ := set $labels $k (include "newrelic.common.naming.truncateToDNS" $v ) -}}
{{- end -}}

{{- toYaml $labels -}}
{{- end -}}

Expand Down

0 comments on commit b42bd69

Please sign in to comment.