From 22795db26032ba6c8223777581d4bfaf61314a02 Mon Sep 17 00:00:00 2001 From: Alex Kabakaev Date: Wed, 8 Nov 2023 13:44:27 +0100 Subject: [PATCH] allow names shorter than three characters (#548) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Description** It is currently not possible to render charts with namespace name shorter than 3 characters. This PR fixes the corresponding regex in the common library chart to also allow the short valid k8s namespaces consisting of one and two alphanumeric characters. The regression was introduced in recent [addition of namespace metadata](https://github.com/truecharts/library-charts/commit/07d4558f5e8e02c0d3d3ca48cfdfe1b2a24594a1). This PR fixes both appearances of `mustRegexMatch()`. **โš™๏ธ Type of change** - [ ] โš™๏ธ Feature/App addition - [x] ๐Ÿช› Bugfix - [ ] โš ๏ธ Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] ๐Ÿ”ƒ Refactor of current code **๐Ÿงช How Has This Been Tested?** ```bash helm template --namespace ha --create-namespace ha TrueCharts/home-assistant # Error: execution error at (home-assistant/templates/common.yaml:5:3): Configmap - Namespace [ha] is not valid. Must start and end with an alphanumeric lowercase character. It can contain '-'. And must be at most 63 characters. git checkout fix-short-release-name helm template --namespace ha --create-namespace ha ./home-assistant/ | head -n2 # --- # Source: home-assistant/templates/common.yaml helm template --namespace ha --create-namespace h ./home-assistant/ -f values.yaml | head -n2 # --- # Source: home-assistant/templates/common.yaml helm template --namespace "-a" --create-namespace h ./home-assistant/ -f values.yaml # Error: execution error at (home-assistant/templates/common.yaml:5:3): Configmap - Namespace [-a] is not valid. Must start and end with an alphanumeric lowercase character. It can contain '-'. And must be at most 63 characters. ``` The updated regex allows one- and two-character namespaces. Validation still works, as shown above. **โœ”๏ธ Checklist:** - [x] โš–๏ธ My code follows the style guidelines of this project - [x] ๐Ÿ‘€ I have performed a self-review of my own code - [ ] #๏ธโƒฃ I have commented my code, particularly in hard-to-understand areas - [ ] ๐Ÿ“„ I have made corresponding changes to the documentation - [x] โš ๏ธ My changes generate no new warnings - [ ] ๐Ÿงช I have added tests to this description that prove my fix is effective or that my feature works - [x] โฌ†๏ธ I increased versions for any altered app according to semantic versioning --- _Please don't blindly check all the boxes. Read them and only check those that apply. Those checkboxes are there for the reviewer to see what is this all about and the status of this PR with a quick glance._ --------- Co-authored-by: Kjeld Schouten --- library/common/Chart.yaml | 2 +- library/common/templates/lib/chart/_names.tpl | 2 +- library/common/templates/lib/metadata/_namespace.tpl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library/common/Chart.yaml b/library/common/Chart.yaml index d2b87d1b..175d5a05 100644 --- a/library/common/Chart.yaml +++ b/library/common/Chart.yaml @@ -15,4 +15,4 @@ maintainers: name: common sources: null type: library -version: 14.3.2 +version: 14.3.3 diff --git a/library/common/templates/lib/chart/_names.tpl b/library/common/templates/lib/chart/_names.tpl index 56e2efc2..9f62422e 100644 --- a/library/common/templates/lib/chart/_names.tpl +++ b/library/common/templates/lib/chart/_names.tpl @@ -38,7 +38,7 @@ {{- $length = 63 -}} {{- end -}} - {{- if not (and (mustRegexMatch "^[a-z0-9](-?[a-z0-9]-?)+[a-z0-9]$" $name) (le (len $name) $length)) -}} + {{- if not (and (mustRegexMatch "^[a-z0-9]((-?[a-z0-9]-?)*[a-z0-9])?$" $name) (le (len $name) $length)) -}} {{- fail (printf "Name [%s] is not valid. Must start and end with an alphanumeric lowercase character. It can contain '-'. And must be at most %v characters." $name $length) -}} {{- end -}} diff --git a/library/common/templates/lib/metadata/_namespace.tpl b/library/common/templates/lib/metadata/_namespace.tpl index 10b048db..0a9fa980 100644 --- a/library/common/templates/lib/metadata/_namespace.tpl +++ b/library/common/templates/lib/metadata/_namespace.tpl @@ -17,7 +17,7 @@ {{- $namespace = tpl . $rootCtx -}} {{- end -}} - {{- if not (and (mustRegexMatch "^[a-z0-9](-?[a-z0-9]-?)+[a-z0-9]$" $namespace) (le (len $namespace) 63)) -}} + {{- if not (and (mustRegexMatch "^[a-z0-9]((-?[a-z0-9]-?)*[a-z0-9])?$" $namespace) (le (len $namespace) 63)) -}} {{- fail (printf "%s - Namespace [%s] is not valid. Must start and end with an alphanumeric lowercase character. It can contain '-'. And must be at most 63 characters." $caller $namespace) -}} {{- end -}}