From 5b62b07d7bb9396212a844318d894996e7cd3962 Mon Sep 17 00:00:00 2001 From: jarebudev <23311805+jarebudev@users.noreply.github.com> Date: Tue, 20 May 2025 21:58:53 +0100 Subject: [PATCH 1/5] wip Signed-off-by: jarebudev <23311805+jarebudev@users.noreply.github.com> --- hips/hip-9999.md | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 hips/hip-9999.md diff --git a/hips/hip-9999.md b/hips/hip-9999.md new file mode 100644 index 000000000..df662f368 --- /dev/null +++ b/hips/hip-9999.md @@ -0,0 +1,60 @@ +--- +hip: 9999 +title: "Automatically truncate names and labels to reduce the amount of boilerplate chart code" +authors: [ "@jarebudev" ] +created: "2025-04-29" +type: "feature" +status: "draft" +--- + +## Abstract + +At present, chart developers routinely add logic to their templates to truncate names and labels if the value supplied is greater than 63 characters long. If Helm was changed so that names and labels were automatically truncated to 63 characters this would reduce the amount of boilerplate code chart developers are required to maintain. + + +## Motivation + +By truncating the values for names and labels we will reduce the amount of boilerplate code that chart developers need to maintain. + +If chart developers do not include this boilerplate code, and a chart user provides a value for the template name or label greater than what the template supports then this will result in the chart failing to be applied. + + +K8s rules.... + + +## Rationale + +Leveraging the same validation rules that are applied by Kubernetes will result in a consistent experience. + +## Specification + + +## Backwards compatibility + +This change will not break any existing chart as chart users that try to supply names or labels greater than 63 characters will fail when applying the templates. +Charts that already truncate names and labels to 63 characters will not notice the change as they are already doing this. + + +## Security implications + +None + +## How to teach this + +- Update documentation + +## Reference implementation + +TBC + +## Rejected ideas + +N/A + +## Open issues + +N/A + +## References + +N/A \ No newline at end of file From 276e34bb0fa09f2abdab7ba1df078d7f67a022cf Mon Sep 17 00:00:00 2001 From: jarebudev <23311805+jarebudev@users.noreply.github.com> Date: Sun, 8 Jun 2025 22:03:04 +0100 Subject: [PATCH 2/5] added truncate names hip Signed-off-by: jarebudev <23311805+jarebudev@users.noreply.github.com> --- hips/hip-9999.md | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/hips/hip-9999.md b/hips/hip-9999.md index df662f368..44e980be0 100644 --- a/hips/hip-9999.md +++ b/hips/hip-9999.md @@ -1,38 +1,42 @@ --- hip: 9999 -title: "Automatically truncate names and labels to reduce the amount of boilerplate chart code" +title: "Automatically truncate names and labels to reduce the amount of bloat chart code" authors: [ "@jarebudev" ] -created: "2025-04-29" +created: "2025-06-08" type: "feature" status: "draft" --- ## Abstract -At present, chart developers routinely add logic to their templates to truncate names and labels if the value supplied is greater than 63 characters long. If Helm was changed so that names and labels were automatically truncated to 63 characters this would reduce the amount of boilerplate code chart developers are required to maintain. - +At present, templates contain unnecessary 'bloat' logic to truncate names and labels if the value supplied to them is greater than 63 characters long. If Helm was changed so that names and labels were automatically truncated to 63 characters, this would reduce the amount of bloat in charts which will improve readability. ## Motivation -By truncating the values for names and labels we will reduce the amount of boilerplate code that chart developers need to maintain. - -If chart developers do not include this boilerplate code, and a chart user provides a value for the template name or label greater than what the template supports then this will result in the chart failing to be applied. +By truncating the values for names and labels we will reduce the amount of boilerplate code that chart developers have to read. +The code to truncate and trim that is frequently seen is `| trunc 63 | trimSuffix "-"` -K8s rules.... - +Charts created using `helm create` contain this within the generated `templates/_helpers.tpl`, which is generated by `pkg/chart/v2/util/create.go`. ## Rationale -Leveraging the same validation rules that are applied by Kubernetes will result in a consistent experience. +Helm templating is a powerful capability, but large templates and associated helpers can be verbose for a developer or user to read. + +By reducing, where possible, the amount of bloat in charts, we enable chart users and developers to focus on the relevant chart logic. ## Specification +Templates should validate the name Leveraging the same validation rules that are applied by Kubernetes will result in a consistent experience. + ## Backwards compatibility -This change will not break any existing chart as chart users that try to supply names or labels greater than 63 characters will fail when applying the templates. -Charts that already truncate names and labels to 63 characters will not notice the change as they are already doing this. +The main behavioural difference by introducing this change will be for existing charts that may potentially supply values to names/labels without truncating and trimming values greater than 63 characters in length. + +Instead of failing to apply the chart when users try to supply names or labels in a template greater than 63 characters long, Helm will ensure that the value is truncated and trimmed. + +Charts that already truncate names and labels to 63 characters will not be impacted by this change (as they are already ensuring the name/label is not more than 63 characters long). ## Security implications From 9da78e522d59c23a44d04d52536455901d298137 Mon Sep 17 00:00:00 2001 From: jarebudev <23311805+jarebudev@users.noreply.github.com> Date: Tue, 29 Jul 2025 22:43:19 +0100 Subject: [PATCH 3/5] updated hip proposal Signed-off-by: jarebudev <23311805+jarebudev@users.noreply.github.com> --- hips/hip-9999.md | 53 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/hips/hip-9999.md b/hips/hip-9999.md index 44e980be0..ebd904397 100644 --- a/hips/hip-9999.md +++ b/hips/hip-9999.md @@ -1,43 +1,59 @@ --- hip: 9999 -title: "Automatically truncate names and labels to reduce the amount of bloat chart code" +title: "Automatically validate the length of names and labels instead of relying on truncation" authors: [ "@jarebudev" ] -created: "2025-06-08" +created: "2025-07-29" type: "feature" status: "draft" --- ## Abstract -At present, templates contain unnecessary 'bloat' logic to truncate names and labels if the value supplied to them is greater than 63 characters long. If Helm was changed so that names and labels were automatically truncated to 63 characters, this would reduce the amount of bloat in charts which will improve readability. +To prevent errors arising from names and labels being longer than 63 characters, chart templates by convention contain logic to truncate and trim values that are longer than 63 characters before applying these to Kubernetes + +This proposal is to make changes to Helm so that the length of names and labels are validated by Helm before applying to Kubernetes, failing if any name is greater than 63 characters. ## Motivation -By truncating the values for names and labels we will reduce the amount of boilerplate code that chart developers have to read. +Currently, the approach for handling too long name values for names is to 'truncate and trim' these if they are greater than 63 characters. + +Helm encourages this convention by creating helper methods in charts created using the `helm create` command. + +These charts contain this pattern within the generated `templates/_helpers.tpl`, which is generated by `pkg/chart/v2/util/create.go`. + +This requires chart developers to ensure that they are applying this throughout their templates. + +Apart from additional boilerplate code that is added to charts, this approach has a drawback as it attempts to shield chart users from their choices of invalid names which exceed the naming limit. + +By changing Helm so that it checks any resource name or label value to be less than 63 characters, it forces the chart user to reconsider their naming of charts and releases to fit their Kubernetes deployment strategy. -The code to truncate and trim that is frequently seen is `| trunc 63 | trimSuffix "-"` -Charts created using `helm create` contain this within the generated `templates/_helpers.tpl`, which is generated by `pkg/chart/v2/util/create.go`. ## Rationale -Helm templating is a powerful capability, but large templates and associated helpers can be verbose for a developer or user to read. +Ensuring that Kubernetes workloads are deployed with consistent and meaningful names is a large part of Kubernetes deployment engineering. -By reducing, where possible, the amount of bloat in charts, we enable chart users and developers to focus on the relevant chart logic. +Most resources in Kubernetes have a 253 character limit. The 63 character limit applies to pods, services, labels, and CronJobs. -## Specification +Blanket truncating to 63 characters, as Helm currently encourages, ensures that names supplied to a template will fit within Kubernetes naming limits and not lead to a Helm deployment failure. -Templates should validate the name Leveraging the same validation rules that are applied by Kubernetes will result in a consistent experience. +Truncation however is in effect an attempt to avoid a configuration error by the chart user as it's hiding the error rather than making the chart user ensure their configuration does not violate Kubernetes naming restrictions. +Truncation can also lead to naming collisions when deploying multiple times to the same namespace. -## Backwards compatibility +Instead of truncating, Helm should fail before applying if the template resource name or labels, forcing chart users to adjust their resource names to suit. -The main behavioural difference by introducing this change will be for existing charts that may potentially supply values to names/labels without truncating and trimming values greater than 63 characters in length. +By reducing the need for truncation and trimming logic in chart templates, this will also lead to a small reduction of bloat in charts, enabling chart users and developers to focus on the relevant chart logic. -Instead of failing to apply the chart when users try to supply names or labels in a template greater than 63 characters long, Helm will ensure that the value is truncated and trimmed. -Charts that already truncate names and labels to 63 characters will not be impacted by this change (as they are already ensuring the name/label is not more than 63 characters long). +## Specification + +- Resource names or label values fail template validation if a value provided is greater than 63 characters. +- `pkg/chart/v2/util/create.go` to be changed so that `templates/_helpers.tpl` no longer contains the logic to truncate and trim names to 63 characters. + +## Backwards compatibility +Charts that already truncate names and labels to 63 characters will not be impacted by this change (as they are already ensuring the name/label is not more than 63 characters long by truncating. ## Security implications @@ -45,7 +61,7 @@ None ## How to teach this -- Update documentation +Via documentation ## Reference implementation @@ -53,7 +69,10 @@ TBC ## Rejected ideas -N/A +Automatically truncating and trimming names and labels. + +Adding a new function for chart developers to use that will fail the validation of a template if a value supplied to be used for the name is greater than a chart developer specified length. This would be useful for `Deployment`s which names are recommended to be less than or equal to 47 characters as greater than this has implications for the names of Pods generated by the Deployments. This should be proposed and discussed in another H4HIP. + ## Open issues @@ -61,4 +80,4 @@ N/A ## References -N/A \ No newline at end of file +- [kubernetes dns-subdomain-names](https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-label-names) \ No newline at end of file From ce52c26a93e46e6b0c9882b08207c35ff62f4251 Mon Sep 17 00:00:00 2001 From: jarebudev <23311805+jarebudev@users.noreply.github.com> Date: Sun, 19 Oct 2025 23:17:23 +0100 Subject: [PATCH 4/5] merge main, updated date Signed-off-by: jarebudev <23311805+jarebudev@users.noreply.github.com> --- hips/hip-9999.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hips/hip-9999.md b/hips/hip-9999.md index ebd904397..272b5371a 100644 --- a/hips/hip-9999.md +++ b/hips/hip-9999.md @@ -2,7 +2,7 @@ hip: 9999 title: "Automatically validate the length of names and labels instead of relying on truncation" authors: [ "@jarebudev" ] -created: "2025-07-29" +created: "2025-10-19" type: "feature" status: "draft" --- From f5f9e8a91e64e96a210a9b773d0e83e81e037b6f Mon Sep 17 00:00:00 2001 From: jarebudev <23311805+jarebudev@users.noreply.github.com> Date: Sun, 19 Oct 2025 23:37:45 +0100 Subject: [PATCH 5/5] minor alterations Signed-off-by: jarebudev <23311805+jarebudev@users.noreply.github.com> --- hips/hip-9999.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hips/hip-9999.md b/hips/hip-9999.md index 272b5371a..dfa5ebb53 100644 --- a/hips/hip-9999.md +++ b/hips/hip-9999.md @@ -37,7 +37,7 @@ Most resources in Kubernetes have a 253 character limit. The 63 character limit Blanket truncating to 63 characters, as Helm currently encourages, ensures that names supplied to a template will fit within Kubernetes naming limits and not lead to a Helm deployment failure. -Truncation however is in effect an attempt to avoid a configuration error by the chart user as it's hiding the error rather than making the chart user ensure their configuration does not violate Kubernetes naming restrictions. +Truncation however is in effect an attempt to avoid a configuration error by the chart user as it's hiding the error, rather than making the chart user ensure that their configuration does not violate Kubernetes naming restrictions. Truncation can also lead to naming collisions when deploying multiple times to the same namespace. @@ -53,7 +53,7 @@ By reducing the need for truncation and trimming logic in chart templates, this ## Backwards compatibility -Charts that already truncate names and labels to 63 characters will not be impacted by this change (as they are already ensuring the name/label is not more than 63 characters long by truncating. +Charts that already truncate names and labels to 63 characters will not be impacted by this change (as they are already ensuring the name/label is not more than 63 characters long by truncating). ## Security implications