From 7de4ddfe940644af3ded3ce64601105ce56ad36c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=E1=B4=87=CA=80=C9=B4=E1=B4=85=20S=E1=B4=84=CA=9C?= =?UTF-8?q?=E1=B4=8F=CA=80=C9=A2=E1=B4=87=CA=80s?= Date: Tue, 9 Aug 2022 11:00:07 +0200 Subject: [PATCH] feat(app-template): Set default nameOverride (#20) --- charts/other/app-template/Chart.yaml | 6 ++--- .../other/app-template/templates/common.yaml | 13 ++++++++++ .../tests/addons/codeserver_test.yaml | 10 ++++---- .../app-template/tests/addons/vpn_test.yaml | 4 +-- .../tests/configmap/metadata_test.yaml | 12 ++++----- .../tests/configmap/names_test.yaml | 4 +-- .../tests/configmap/pod_metadata_test.yaml | 2 +- .../tests/container/envfrom_test.yaml | 2 +- .../controller/metadata_daemonset_test.yaml | 12 ++++----- .../controller/metadata_deployment_test.yaml | 12 ++++----- .../controller/metadata_statefulset_test.yaml | 12 ++++----- .../tests/controller/type_test.yaml | 6 ++--- .../tests/ingress/metadata_test.yaml | 12 ++++----- .../tests/ingress/service_reference_test.yaml | 2 +- .../tests/misc/nameoverride_test.yaml | 25 +++++++++++++++++++ .../tests/persistence/claimnames_test.yaml | 6 ++--- .../tests/persistence/types_test.yaml | 2 +- .../app-template/tests/pvc/metadata_test.yaml | 16 ++++++------ .../app-template/tests/pvc/names_test.yaml | 6 ++--- .../tests/service/metadata_test.yaml | 12 ++++----- .../tests/service/names_test.yaml | 4 +-- 21 files changed, 109 insertions(+), 71 deletions(-) create mode 100644 charts/other/app-template/tests/misc/nameoverride_test.yaml diff --git a/charts/other/app-template/Chart.yaml b/charts/other/app-template/Chart.yaml index 72560db5..de544cdf 100644 --- a/charts/other/app-template/Chart.yaml +++ b/charts/other/app-template/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 description: A common powered chart template. This can be useful for small projects that don't have their own chart. name: app-template -version: 0.1.0 +version: 0.1.1 maintainers: - name: bjw-s email: me@bjw-s.dev @@ -12,5 +12,5 @@ dependencies: version: 0.1.0 annotations: artifacthub.io/changes: |- - - kind: changed - description: Set `common` chart dependency to version 0.1.0 + - kind: added + description: Automatically set `global.nameOverride` to release name diff --git a/charts/other/app-template/templates/common.yaml b/charts/other/app-template/templates/common.yaml index 7a9d0361..9e25cf24 100644 --- a/charts/other/app-template/templates/common.yaml +++ b/charts/other/app-template/templates/common.yaml @@ -1,2 +1,15 @@ --- +{{- include "common.values.setup" . }} + +{{- define "app-template.hardcodedValues" -}} + +# Set the nameOverride based on the release name if no override has been set +{{ if not .Values.global.nameOverride }} +global: + nameOverride: "{{ .Release.Name }}" +{{ end }} + +{{- end -}} +{{- $_ := mergeOverwrite .Values (include "app-template.hardcodedValues" . | fromYaml) -}} + {{ include "common.all" . }} diff --git a/charts/other/app-template/tests/addons/codeserver_test.yaml b/charts/other/app-template/tests/addons/codeserver_test.yaml index c2b16993..2e780ffa 100644 --- a/charts/other/app-template/tests/addons/codeserver_test.yaml +++ b/charts/other/app-template/tests/addons/codeserver_test.yaml @@ -45,7 +45,7 @@ tests: - documentIndex: *AddonServiceDocument equal: path: metadata.name - value: RELEASE-NAME-app-template + value: RELEASE-NAME - it: addon enabled with deployKey should pass set: @@ -83,11 +83,11 @@ tests: items: - key: id_rsa path: id_rsa - secretName: RELEASE-NAME-app-template-deploykey + secretName: RELEASE-NAME-deploykey - documentIndex: *AddonDeployKeySecretDocument equal: path: metadata.name - value: RELEASE-NAME-app-template-deploykey + value: RELEASE-NAME-deploykey - it: addon enabled with InlineBase64 deployKey should pass set: @@ -125,11 +125,11 @@ tests: items: - key: id_rsa path: id_rsa - secretName: RELEASE-NAME-app-template-deploykey + secretName: RELEASE-NAME-deploykey - documentIndex: *AddonDeployKeySecretDocument equal: path: metadata.name - value: RELEASE-NAME-app-template-deploykey + value: RELEASE-NAME-deploykey - it: addon enabled with existingSecret deployKey should pass set: diff --git a/charts/other/app-template/tests/addons/vpn_test.yaml b/charts/other/app-template/tests/addons/vpn_test.yaml index 905ee2f5..07bd51a0 100644 --- a/charts/other/app-template/tests/addons/vpn_test.yaml +++ b/charts/other/app-template/tests/addons/vpn_test.yaml @@ -68,11 +68,11 @@ tests: items: - key: vpnConfigfile path: vpnConfigfile - secretName: RELEASE-NAME-app-template-vpnconfig + secretName: RELEASE-NAME-vpnconfig - documentIndex: *AddonVPNConfigSecretDocument equal: path: metadata.name - value: RELEASE-NAME-app-template-vpnconfig + value: RELEASE-NAME-vpnconfig - it: addon enabled with existing configFile secret should pass set: diff --git a/charts/other/app-template/tests/configmap/metadata_test.yaml b/charts/other/app-template/tests/configmap/metadata_test.yaml index 6aa6afe9..8e8a5c92 100644 --- a/charts/other/app-template/tests/configmap/metadata_test.yaml +++ b/charts/other/app-template/tests/configmap/metadata_test.yaml @@ -20,8 +20,8 @@ tests: value: app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: app-template - helm.sh/chart: app-template-0.1.0 + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: app-template-0.1.1 - it: custom metadata should pass set: @@ -47,8 +47,8 @@ tests: value: app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: app-template - helm.sh/chart: app-template-0.1.0 + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: app-template-0.1.1 test_label: test - it: custom metadata with global metadata should pass @@ -81,7 +81,7 @@ tests: value: app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: app-template + app.kubernetes.io/name: RELEASE-NAME global_label: test - helm.sh/chart: app-template-0.1.0 + helm.sh/chart: app-template-0.1.1 test_label: test diff --git a/charts/other/app-template/tests/configmap/names_test.yaml b/charts/other/app-template/tests/configmap/names_test.yaml index 8230f243..0f9a36da 100644 --- a/charts/other/app-template/tests/configmap/names_test.yaml +++ b/charts/other/app-template/tests/configmap/names_test.yaml @@ -71,7 +71,7 @@ tests: - documentIndex: 0 equal: path: metadata.name - value: RELEASE-NAME-app-template-config + value: RELEASE-NAME-config - it: with nameOverride should pass set: @@ -88,4 +88,4 @@ tests: - documentIndex: 0 equal: path: metadata.name - value: RELEASE-NAME-app-template-http + value: RELEASE-NAME-http diff --git a/charts/other/app-template/tests/configmap/pod_metadata_test.yaml b/charts/other/app-template/tests/configmap/pod_metadata_test.yaml index 013e1a31..f4bb1f42 100644 --- a/charts/other/app-template/tests/configmap/pod_metadata_test.yaml +++ b/charts/other/app-template/tests/configmap/pod_metadata_test.yaml @@ -15,4 +15,4 @@ tests: equal: path: spec.template.metadata.annotations value: - checksum/config: 4ab90b837c946c225b999f7a09f7ace4acd22f5e691b006e0d4c6b97cf34fbd0 + checksum/config: df9353f1f56b09774c9982674bda7fde05cde68ad7bcbf9594a66f3610bce501 diff --git a/charts/other/app-template/tests/container/envfrom_test.yaml b/charts/other/app-template/tests/container/envfrom_test.yaml index a39f240a..0d98da96 100644 --- a/charts/other/app-template/tests/container/envfrom_test.yaml +++ b/charts/other/app-template/tests/container/envfrom_test.yaml @@ -40,4 +40,4 @@ tests: path: spec.template.spec.containers[0].envFrom[0] value: secretRef: - name: RELEASE-NAME-app-template + name: RELEASE-NAME diff --git a/charts/other/app-template/tests/controller/metadata_daemonset_test.yaml b/charts/other/app-template/tests/controller/metadata_daemonset_test.yaml index 5bc91de9..ccf9822d 100644 --- a/charts/other/app-template/tests/controller/metadata_daemonset_test.yaml +++ b/charts/other/app-template/tests/controller/metadata_daemonset_test.yaml @@ -18,8 +18,8 @@ tests: value: app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: app-template - helm.sh/chart: app-template-0.1.0 + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: app-template-0.1.1 - it: custom metadata should pass set: @@ -44,8 +44,8 @@ tests: value: app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: app-template - helm.sh/chart: app-template-0.1.0 + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: app-template-0.1.1 test_label: test - it: custom metadata with global metadata should pass @@ -77,7 +77,7 @@ tests: value: app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: app-template + app.kubernetes.io/name: RELEASE-NAME global_label: test - helm.sh/chart: app-template-0.1.0 + helm.sh/chart: app-template-0.1.1 test_label: test diff --git a/charts/other/app-template/tests/controller/metadata_deployment_test.yaml b/charts/other/app-template/tests/controller/metadata_deployment_test.yaml index 874c37b3..4a7819e5 100644 --- a/charts/other/app-template/tests/controller/metadata_deployment_test.yaml +++ b/charts/other/app-template/tests/controller/metadata_deployment_test.yaml @@ -18,8 +18,8 @@ tests: value: app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: app-template - helm.sh/chart: app-template-0.1.0 + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: app-template-0.1.1 - it: custom metadata should pass set: @@ -44,8 +44,8 @@ tests: value: app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: app-template - helm.sh/chart: app-template-0.1.0 + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: app-template-0.1.1 test_label: test - it: custom metadata with global metadata should pass @@ -77,7 +77,7 @@ tests: value: app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: app-template + app.kubernetes.io/name: RELEASE-NAME global_label: test - helm.sh/chart: app-template-0.1.0 + helm.sh/chart: app-template-0.1.1 test_label: test diff --git a/charts/other/app-template/tests/controller/metadata_statefulset_test.yaml b/charts/other/app-template/tests/controller/metadata_statefulset_test.yaml index 2b29f472..591d1b59 100644 --- a/charts/other/app-template/tests/controller/metadata_statefulset_test.yaml +++ b/charts/other/app-template/tests/controller/metadata_statefulset_test.yaml @@ -18,8 +18,8 @@ tests: value: app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: app-template - helm.sh/chart: app-template-0.1.0 + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: app-template-0.1.1 - it: custom metadata should pass set: @@ -44,8 +44,8 @@ tests: value: app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: app-template - helm.sh/chart: app-template-0.1.0 + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: app-template-0.1.1 test_label: test - it: custom metadata with global metadata should pass @@ -77,7 +77,7 @@ tests: value: app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: app-template + app.kubernetes.io/name: RELEASE-NAME global_label: test - helm.sh/chart: app-template-0.1.0 + helm.sh/chart: app-template-0.1.1 test_label: test diff --git a/charts/other/app-template/tests/controller/type_test.yaml b/charts/other/app-template/tests/controller/type_test.yaml index fa812ff6..6dbad3f0 100644 --- a/charts/other/app-template/tests/controller/type_test.yaml +++ b/charts/other/app-template/tests/controller/type_test.yaml @@ -10,7 +10,7 @@ tests: - documentIndex: *ControllerDoc equal: path: metadata.name - value: RELEASE-NAME-app-template + value: RELEASE-NAME - it: daemonset should pass set: @@ -22,7 +22,7 @@ tests: - documentIndex: *ControllerDoc equal: path: metadata.name - value: RELEASE-NAME-app-template + value: RELEASE-NAME - it: statefulset should pass set: @@ -34,7 +34,7 @@ tests: - documentIndex: *ControllerDoc equal: path: metadata.name - value: RELEASE-NAME-app-template + value: RELEASE-NAME - it: disabled should pass set: diff --git a/charts/other/app-template/tests/ingress/metadata_test.yaml b/charts/other/app-template/tests/ingress/metadata_test.yaml index c6a81a5d..0f0f2654 100644 --- a/charts/other/app-template/tests/ingress/metadata_test.yaml +++ b/charts/other/app-template/tests/ingress/metadata_test.yaml @@ -18,8 +18,8 @@ tests: value: app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: app-template - helm.sh/chart: app-template-0.1.0 + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: app-template-0.1.1 - it: custom metadata should pass set: @@ -44,8 +44,8 @@ tests: value: app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: app-template - helm.sh/chart: app-template-0.1.0 + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: app-template-0.1.1 test_label: test - it: custom metadata with global metadata should pass @@ -77,7 +77,7 @@ tests: value: app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: app-template + app.kubernetes.io/name: RELEASE-NAME global_label: test - helm.sh/chart: app-template-0.1.0 + helm.sh/chart: app-template-0.1.1 test_label: test diff --git a/charts/other/app-template/tests/ingress/service_reference_test.yaml b/charts/other/app-template/tests/ingress/service_reference_test.yaml index 92ccfb2f..3f105dd4 100644 --- a/charts/other/app-template/tests/ingress/service_reference_test.yaml +++ b/charts/other/app-template/tests/ingress/service_reference_test.yaml @@ -13,7 +13,7 @@ tests: equal: path: spec.rules[0].http.paths[0].backend value: - serviceName: RELEASE-NAME-app-template + serviceName: RELEASE-NAME servicePort: null - it: custom service reference should pass diff --git a/charts/other/app-template/tests/misc/nameoverride_test.yaml b/charts/other/app-template/tests/misc/nameoverride_test.yaml new file mode 100644 index 00000000..ad81db9b --- /dev/null +++ b/charts/other/app-template/tests/misc/nameoverride_test.yaml @@ -0,0 +1,25 @@ +suite: nameOverride tests +templates: + - common.yaml +tests: + - it: default name is set to release name + asserts: + - documentIndex: &ControllerDoc 0 + isKind: + of: Deployment + - documentIndex: *ControllerDoc + equal: + path: metadata.name + value: RELEASE-NAME + + - it: global.nameOverride can be set + set: + global.nameOverride: custom-name + asserts: + - documentIndex: &ControllerDoc 0 + isKind: + of: Deployment + - documentIndex: *ControllerDoc + equal: + path: metadata.name + value: RELEASE-NAME-custom-name diff --git a/charts/other/app-template/tests/persistence/claimnames_test.yaml b/charts/other/app-template/tests/persistence/claimnames_test.yaml index e730ae80..7e361a1a 100644 --- a/charts/other/app-template/tests/persistence/claimnames_test.yaml +++ b/charts/other/app-template/tests/persistence/claimnames_test.yaml @@ -17,7 +17,7 @@ tests: value: name: config persistentVolumeClaim: - claimName: RELEASE-NAME-app-template-config + claimName: RELEASE-NAME-config - it: with existingClaim should pass set: @@ -55,7 +55,7 @@ tests: value: name: claimWithoutSuffix persistentVolumeClaim: - claimName: RELEASE-NAME-app-template + claimName: RELEASE-NAME - it: custom suffix should pass set: @@ -75,4 +75,4 @@ tests: value: name: claimWithNameOverride persistentVolumeClaim: - claimName: RELEASE-NAME-app-template-suffix + claimName: RELEASE-NAME-suffix diff --git a/charts/other/app-template/tests/persistence/types_test.yaml b/charts/other/app-template/tests/persistence/types_test.yaml index 51fda878..3bced08f 100644 --- a/charts/other/app-template/tests/persistence/types_test.yaml +++ b/charts/other/app-template/tests/persistence/types_test.yaml @@ -65,7 +65,7 @@ tests: value: name: configmap configMap: - name: RELEASE-NAME-app-template-config + name: RELEASE-NAME-config - it: secret persistence type should pass set: diff --git a/charts/other/app-template/tests/pvc/metadata_test.yaml b/charts/other/app-template/tests/pvc/metadata_test.yaml index c2811e01..967f81aa 100644 --- a/charts/other/app-template/tests/pvc/metadata_test.yaml +++ b/charts/other/app-template/tests/pvc/metadata_test.yaml @@ -18,8 +18,8 @@ tests: value: app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: app-template - helm.sh/chart: app-template-0.1.0 + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: app-template-0.1.1 - it: retain enabled should pass set: @@ -41,8 +41,8 @@ tests: value: app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: app-template - helm.sh/chart: app-template-0.1.0 + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: app-template-0.1.1 - it: custom metadata should pass set: @@ -67,8 +67,8 @@ tests: value: app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: app-template - helm.sh/chart: app-template-0.1.0 + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: app-template-0.1.1 test_label: test - it: custom metadata with global metadata should pass @@ -100,7 +100,7 @@ tests: value: app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: app-template + app.kubernetes.io/name: RELEASE-NAME global_label: test - helm.sh/chart: app-template-0.1.0 + helm.sh/chart: app-template-0.1.1 test_label: test diff --git a/charts/other/app-template/tests/pvc/names_test.yaml b/charts/other/app-template/tests/pvc/names_test.yaml index fe94ba8b..d9c6a2b4 100644 --- a/charts/other/app-template/tests/pvc/names_test.yaml +++ b/charts/other/app-template/tests/pvc/names_test.yaml @@ -35,7 +35,7 @@ tests: - documentIndex: *PersistentVolumeClaimDocument equal: path: metadata.name - value: RELEASE-NAME-app-template-config + value: RELEASE-NAME-config - it: without suffix should pass set: @@ -49,7 +49,7 @@ tests: - documentIndex: *PersistentVolumeClaimDocument equal: path: metadata.name - value: RELEASE-NAME-app-template + value: RELEASE-NAME - it: with custom suffix should pass set: @@ -63,4 +63,4 @@ tests: - documentIndex: *PersistentVolumeClaimDocument equal: path: metadata.name - value: RELEASE-NAME-app-template-custom + value: RELEASE-NAME-custom diff --git a/charts/other/app-template/tests/service/metadata_test.yaml b/charts/other/app-template/tests/service/metadata_test.yaml index e4d5d3e6..06394113 100644 --- a/charts/other/app-template/tests/service/metadata_test.yaml +++ b/charts/other/app-template/tests/service/metadata_test.yaml @@ -16,8 +16,8 @@ tests: value: app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: app-template - helm.sh/chart: app-template-0.1.0 + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: app-template-0.1.1 - it: custom metadata should pass set: @@ -42,8 +42,8 @@ tests: value: app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: app-template - helm.sh/chart: app-template-0.1.0 + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: app-template-0.1.1 test_label: test - it: custom metadata with global metadata should pass @@ -75,7 +75,7 @@ tests: value: app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: app-template + app.kubernetes.io/name: RELEASE-NAME global_label: test - helm.sh/chart: app-template-0.1.0 + helm.sh/chart: app-template-0.1.1 test_label: test diff --git a/charts/other/app-template/tests/service/names_test.yaml b/charts/other/app-template/tests/service/names_test.yaml index 3b253e03..518665d2 100644 --- a/charts/other/app-template/tests/service/names_test.yaml +++ b/charts/other/app-template/tests/service/names_test.yaml @@ -12,7 +12,7 @@ tests: - documentIndex: *ServiceDocument equal: path: metadata.name - value: RELEASE-NAME-app-template + value: RELEASE-NAME - it: custom name suffix should pass set: @@ -26,4 +26,4 @@ tests: - documentIndex: *ServiceDocument equal: path: metadata.name - value: RELEASE-NAME-app-template-http + value: RELEASE-NAME-http