diff --git a/charts/library/common-test/tests/configmap/names_test.yaml b/charts/library/common-test/tests/configmap/names_test.yaml index 57cbdd03..fb7521df 100644 --- a/charts/library/common-test/tests/configmap/names_test.yaml +++ b/charts/library/common-test/tests/configmap/names_test.yaml @@ -87,3 +87,21 @@ tests: equal: path: metadata.name value: RELEASE-NAME-http + + - it: with templated nameOverride should pass + set: + configMaps: + config: + data: + test: test + nameOverride: "{{ .Release.Name }}" + asserts: + - hasDocuments: + count: 2 + - documentIndex: &ConfigmapDocument 1 + isKind: + of: ConfigMap + - documentIndex: *ConfigmapDocument + equal: + path: metadata.name + value: RELEASE-NAME diff --git a/charts/library/common-test/tests/controller/type_test.yaml b/charts/library/common-test/tests/controller/type_test.yaml index 6705e7c5..9cb561b9 100644 --- a/charts/library/common-test/tests/controller/type_test.yaml +++ b/charts/library/common-test/tests/controller/type_test.yaml @@ -56,6 +56,8 @@ tests: - it: additional controllers with nameOverride should pass set: controllers: + main: + nameOverride: "{{ .Release.Name }}" second: nameOverride: testOverride containers: @@ -72,7 +74,7 @@ tests: - documentIndex: *firstDeploymentDoc equal: path: metadata.name - value: RELEASE-NAME-main + value: RELEASE-NAME - documentIndex: *firstDeploymentDoc equal: path: metadata.labels['app.kubernetes.io/component'] diff --git a/charts/library/common-test/tests/ingress/values_test.yaml b/charts/library/common-test/tests/ingress/values_test.yaml index f00dc139..8d813990 100644 --- a/charts/library/common-test/tests/ingress/values_test.yaml +++ b/charts/library/common-test/tests/ingress/values_test.yaml @@ -23,6 +23,32 @@ tests: path: spec.rules[0].http.paths[0].path value: "/" + - it: nameOverride should pass + set: + ingress.main: + nameOverride: test + asserts: + - documentIndex: &IngressDocument 2 + isKind: + of: Ingress + - documentIndex: *IngressDocument + equal: + path: metadata.name + value: RELEASE-NAME-test + + - it: nameOverride with template should pass + set: + ingress.main: + nameOverride: "{{ .Release.Name }}" + asserts: + - documentIndex: &IngressDocument 2 + isKind: + of: Ingress + - documentIndex: *IngressDocument + equal: + path: metadata.name + value: RELEASE-NAME + - it: custom host and path should pass set: ingress.main: diff --git a/charts/library/common-test/tests/service/names_test.yaml b/charts/library/common-test/tests/service/names_test.yaml index 1fc35c75..2fa07caf 100644 --- a/charts/library/common-test/tests/service/names_test.yaml +++ b/charts/library/common-test/tests/service/names_test.yaml @@ -32,6 +32,20 @@ tests: path: metadata.name value: RELEASE-NAME-http + - it: custom name suffix with template should pass + values: + - ../_values/service_main_default.yaml + set: + service.main.nameOverride: "{{ .Release.Name }}" + asserts: + - documentIndex: &ServiceDocument 1 + isKind: + of: Service + - documentIndex: *ServiceDocument + equal: + path: metadata.name + value: RELEASE-NAME + - it: multiple should pass values: - ../_values/service_main_default.yaml diff --git a/charts/library/common/Chart.yaml b/charts/library/common/Chart.yaml index 33ea9ca6..966c3d02 100644 --- a/charts/library/common/Chart.yaml +++ b/charts/library/common/Chart.yaml @@ -3,7 +3,7 @@ apiVersion: v2 name: common description: Function library for Helm charts type: library -version: 3.0.1 +version: 3.0.2 kubeVersion: ">=1.22.0-0" keywords: - common @@ -14,6 +14,9 @@ maintainers: email: me@bjw-s.dev annotations: artifacthub.io/changes: |- + - kind: fixed + description: |- + Fixed nameOverride logic to prevent duplicated name - kind: changed description: |- BREAKING: Default objects (they used to be called main) have been commented out and will therefore no longer provide any (both expected and unexpected) default values. diff --git a/charts/library/common/README.md b/charts/library/common/README.md index 18f28661..62f599ed 100644 --- a/charts/library/common/README.md +++ b/charts/library/common/README.md @@ -1,6 +1,6 @@ # common -![Version: 3.0.1](https://img.shields.io/badge/Version-3.0.1-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square) +![Version: 3.0.2](https://img.shields.io/badge/Version-3.0.2-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square) Function library for Helm charts @@ -27,7 +27,7 @@ Include this chart as a dependency in your `Chart.yaml` e.g. # Chart.yaml dependencies: - name: common - version: 3.0.1 + version: 3.0.2 repository: https://bjw-s.github.io/helm-charts/ ``` diff --git a/charts/library/common/templates/lib/configMap/_valuesToObject.tpl b/charts/library/common/templates/lib/configMap/_valuesToObject.tpl index 5621441f..0e9286d4 100644 --- a/charts/library/common/templates/lib/configMap/_valuesToObject.tpl +++ b/charts/library/common/templates/lib/configMap/_valuesToObject.tpl @@ -10,9 +10,14 @@ Convert configMap values to an object {{- $objectName := (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}} {{- if $objectValues.nameOverride -}} - {{- $objectName = printf "%s-%s" $objectName $objectValues.nameOverride -}} + {{- $override := tpl $objectValues.nameOverride $rootContext -}} + {{- if not (eq $objectName $override) -}} + {{- $objectName = printf "%s-%s" $objectName $override -}} + {{- end -}} {{- else -}} - {{- $objectName = printf "%s-%s" $objectName $identifier -}} + {{- if not (eq $objectName $identifier) -}} + {{- $objectName = printf "%s-%s" $objectName $identifier -}} + {{- end -}} {{- end -}} {{- $_ := set $objectValues "name" $objectName -}} {{- $_ := set $objectValues "identifier" $identifier -}} diff --git a/charts/library/common/templates/lib/controller/_valuesToObject.tpl b/charts/library/common/templates/lib/controller/_valuesToObject.tpl index 241644aa..ef4be269 100644 --- a/charts/library/common/templates/lib/controller/_valuesToObject.tpl +++ b/charts/library/common/templates/lib/controller/_valuesToObject.tpl @@ -15,11 +15,16 @@ Convert controller values to an object {{- $objectName := (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}} {{- if $objectValues.nameOverride -}} - {{- $objectName = printf "%s-%s" $objectName $objectValues.nameOverride -}} + {{- $override := tpl $objectValues.nameOverride $rootContext -}} + {{- if not (eq $objectName $override) -}} + {{- $objectName = printf "%s-%s" $objectName $override -}} + {{- end -}} {{- else -}} {{- $enabledControllers := (include "bjw-s.common.lib.controller.enabledControllers" (dict "rootContext" $rootContext) | fromYaml ) }} {{- if gt (len $enabledControllers) 1 -}} - {{- $objectName = printf "%s-%s" $objectName $identifier -}} + {{- if not (eq $objectName $identifier) -}} + {{- $objectName = printf "%s-%s" $objectName $identifier -}} + {{- end -}} {{- end -}} {{- end -}} {{- $_ := set $objectValues "name" $objectName -}} diff --git a/charts/library/common/templates/lib/ingress/_valuesToObject.tpl b/charts/library/common/templates/lib/ingress/_valuesToObject.tpl index f8275c40..0c798759 100644 --- a/charts/library/common/templates/lib/ingress/_valuesToObject.tpl +++ b/charts/library/common/templates/lib/ingress/_valuesToObject.tpl @@ -10,11 +10,16 @@ Convert ingress values to an object {{- $objectName := (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}} {{- if $objectValues.nameOverride -}} - {{- $objectName = printf "%s-%s" $objectName $objectValues.nameOverride -}} + {{- $override := tpl $objectValues.nameOverride $rootContext -}} + {{- if not (eq $objectName $override) -}} + {{- $objectName = printf "%s-%s" $objectName $override -}} + {{- end -}} {{- else -}} {{- $enabledIngresses := (include "bjw-s.common.lib.ingress.enabledIngresses" (dict "rootContext" $rootContext) | fromYaml ) }} {{- if gt (len $enabledIngresses) 1 -}} - {{- $objectName = printf "%s-%s" $objectName $identifier -}} + {{- if not (eq $objectName $identifier) -}} + {{- $objectName = printf "%s-%s" $objectName $identifier -}} + {{- end -}} {{- end -}} {{- end -}} {{- $_ := set $objectValues "name" $objectName -}} diff --git a/charts/library/common/templates/lib/networkpolicy/_valuesToObject.tpl b/charts/library/common/templates/lib/networkpolicy/_valuesToObject.tpl index 572ca818..fefd459e 100644 --- a/charts/library/common/templates/lib/networkpolicy/_valuesToObject.tpl +++ b/charts/library/common/templates/lib/networkpolicy/_valuesToObject.tpl @@ -10,11 +10,16 @@ Convert networkPolicy values to an object {{- $objectName := (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}} {{- if $objectValues.nameOverride -}} - {{- $objectName = printf "%s-%s" $objectName $objectValues.nameOverride -}} + {{- $override := tpl $objectValues.nameOverride $rootContext -}} + {{- if not (eq $objectName $override) -}} + {{- $objectName = printf "%s-%s" $objectName $override -}} + {{- end -}} {{- else -}} {{- $enabledNetworkPolicies := (include "bjw-s.common.lib.networkPolicy.enabledNetworkPolicies" (dict "rootContext" $rootContext) | fromYaml ) }} {{- if gt (len $enabledNetworkPolicies) 1 -}} - {{- $objectName = printf "%s-%s" $objectName $identifier -}} + {{- if not (eq $objectName $identifier) -}} + {{- $objectName = printf "%s-%s" $objectName $identifier -}} + {{- end -}} {{- end -}} {{- end -}} {{- $_ := set $objectValues "name" $objectName -}} diff --git a/charts/library/common/templates/lib/pvc/_valuesToObject.tpl b/charts/library/common/templates/lib/pvc/_valuesToObject.tpl index 99878382..bfbf958e 100644 --- a/charts/library/common/templates/lib/pvc/_valuesToObject.tpl +++ b/charts/library/common/templates/lib/pvc/_valuesToObject.tpl @@ -14,7 +14,9 @@ Convert PVC values to an object {{- $objectName = printf "%s-%s" $objectName $objectValues.nameOverride -}} {{- end -}} {{- else -}} - {{- $objectName = printf "%s-%s" $objectName $identifier -}} + {{- if not (eq $objectName $identifier) -}} + {{- $objectName = printf "%s-%s" $objectName $identifier -}} + {{- end -}} {{- end -}} {{- $_ := set $objectValues "name" $objectName -}} {{- $_ := set $objectValues "identifier" $identifier -}} diff --git a/charts/library/common/templates/lib/routes/_valuesToObject.tpl b/charts/library/common/templates/lib/routes/_valuesToObject.tpl index 1b436631..66a9a476 100644 --- a/charts/library/common/templates/lib/routes/_valuesToObject.tpl +++ b/charts/library/common/templates/lib/routes/_valuesToObject.tpl @@ -10,10 +10,15 @@ Convert Route values to an object {{- $objectName := (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}} {{- if $objectValues.nameOverride -}} - {{- $objectName = printf "%s-%s" $objectName $objectValues.nameOverride -}} + {{- $override := tpl $objectValues.nameOverride $rootContext -}} + {{- if not (eq $objectName $override) -}} + {{- $objectName = printf "%s-%s" $objectName $override -}} + {{- end -}} {{- else -}} {{- if ne $identifier (include "bjw-s.common.lib.route.primary" $rootContext) -}} - {{- $objectName = printf "%s-%s" $objectName $identifier -}} + {{- if not (eq $objectName $identifier) -}} + {{- $objectName = printf "%s-%s" $objectName $identifier -}} + {{- end -}} {{- end -}} {{- end -}} {{- $_ := set $objectValues "name" $objectName -}} diff --git a/charts/library/common/templates/lib/secret/_valuesToObject.tpl b/charts/library/common/templates/lib/secret/_valuesToObject.tpl index e29a68d1..4b24d2ab 100644 --- a/charts/library/common/templates/lib/secret/_valuesToObject.tpl +++ b/charts/library/common/templates/lib/secret/_valuesToObject.tpl @@ -10,9 +10,14 @@ Convert Secret values to an object {{- $objectName := (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}} {{- if $objectValues.nameOverride -}} - {{- $objectName = printf "%s-%s" $objectName $objectValues.nameOverride -}} + {{- $override := tpl $objectValues.nameOverride $rootContext -}} + {{- if not (eq $objectName $override) -}} + {{- $objectName = printf "%s-%s" $objectName $override -}} + {{- end -}} {{- else -}} - {{- $objectName = printf "%s-%s" $objectName $identifier -}} + {{- if not (eq $objectName $identifier) -}} + {{- $objectName = printf "%s-%s" $objectName $identifier -}} + {{- end -}} {{- end -}} {{- $_ := set $objectValues "name" $objectName -}} {{- $_ := set $objectValues "identifier" $identifier -}} diff --git a/charts/library/common/templates/lib/service/_valuesToObject.tpl b/charts/library/common/templates/lib/service/_valuesToObject.tpl index ff74ecb5..85df0742 100644 --- a/charts/library/common/templates/lib/service/_valuesToObject.tpl +++ b/charts/library/common/templates/lib/service/_valuesToObject.tpl @@ -10,11 +10,16 @@ Convert Service values to an object {{- $objectName := (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}} {{- if $objectValues.nameOverride -}} - {{- $objectName = printf "%s-%s" $objectName $objectValues.nameOverride -}} + {{- $override := tpl $objectValues.nameOverride $rootContext -}} + {{- if not (eq $objectName $override) -}} + {{- $objectName = printf "%s-%s" $objectName $override -}} + {{- end -}} {{- else -}} {{- $enabledServices := (include "bjw-s.common.lib.service.enabledServices" (dict "rootContext" $rootContext) | fromYaml ) }} {{- if and (not $objectValues.primary) (gt (len $enabledServices) 1) -}} - {{- $objectName = printf "%s-%s" $objectName $identifier -}} + {{- if not (eq $objectName $identifier) -}} + {{- $objectName = printf "%s-%s" $objectName $identifier -}} + {{- end -}} {{- end -}} {{- end -}} {{- $_ := set $objectValues "name" $objectName -}} diff --git a/charts/library/common/templates/lib/serviceMonitor/_valuesToObject.tpl b/charts/library/common/templates/lib/serviceMonitor/_valuesToObject.tpl index 7095f64d..f1d6b364 100644 --- a/charts/library/common/templates/lib/serviceMonitor/_valuesToObject.tpl +++ b/charts/library/common/templates/lib/serviceMonitor/_valuesToObject.tpl @@ -10,11 +10,16 @@ Convert ServiceMonitor values to an object {{- $objectName := (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}} {{- if $objectValues.nameOverride -}} - {{- $objectName = printf "%s-%s" $objectName $objectValues.nameOverride -}} + {{- $override := tpl $objectValues.nameOverride $rootContext -}} + {{- if not (eq $objectName $override) -}} + {{- $objectName = printf "%s-%s" $objectName $override -}} + {{- end -}} {{- else -}} {{- $enabledServiceMonitors := (include "bjw-s.common.lib.serviceMonitor.enabledServiceMonitors" (dict "rootContext" $rootContext) | fromYaml ) }} {{- if gt (len $enabledServiceMonitors) 1 -}} - {{- $objectName = printf "%s-%s" $objectName $identifier -}} + {{- if not (eq $objectName $identifier) -}} + {{- $objectName = printf "%s-%s" $objectName $identifier -}} + {{- end -}} {{- end -}} {{- end -}} {{- $_ := set $objectValues "name" $objectName -}} diff --git a/charts/library/common/values.schema.json b/charts/library/common/values.schema.json index ec06b4e0..4d7889c8 100644 --- a/charts/library/common/values.schema.json +++ b/charts/library/common/values.schema.json @@ -1,6 +1,6 @@ { "$schema": "http://json-schema.org/draft-07/schema", - "$id": "https://raw.githubusercontent.com/bjw-s/helm-charts/common-3.0.1/charts/library/common/values.schema.json", + "$id": "https://raw.githubusercontent.com/bjw-s/helm-charts/common-3.0.2/charts/library/common/values.schema.json", "type": "object", "properties": {