From 129c5283d632d7175eac5bd8a4d82a2bd265f063 Mon Sep 17 00:00:00 2001 From: TJ Higgins Date: Wed, 20 Oct 2021 15:06:50 -0400 Subject: [PATCH 1/2] Truncate the statefulset pvc name to be max 63 chars --- charts/consul/templates/server-statefulset.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/charts/consul/templates/server-statefulset.yaml b/charts/consul/templates/server-statefulset.yaml index fe2dcff468..2e332cb7ae 100644 --- a/charts/consul/templates/server-statefulset.yaml +++ b/charts/consul/templates/server-statefulset.yaml @@ -257,7 +257,7 @@ spec: -config-file=/consul/extra-config/extra-from-values.json \ -server volumeMounts: - - name: data-{{ .Release.Namespace }} + - name: data-{{ .Release.Namespace | trunc 58 | trimSuffix "-" }} mountPath: /consul/data - name: config mountPath: /consul/config @@ -365,7 +365,7 @@ spec: {{- end }} volumeClaimTemplates: - metadata: - name: data-{{ .Release.Namespace }} + name: data-{{ .Release.Namespace | trunc 58 | trimSuffix "-" }} spec: accessModes: - ReadWriteOnce From f76257754e9974ebbf30d811eab0a7dfcebec42d Mon Sep 17 00:00:00 2001 From: TJ Higgins Date: Sun, 7 Nov 2021 21:07:30 -0500 Subject: [PATCH 2/2] Add unit tests for pvc name truncation --- .../consul/test/unit/server-statefulset.bats | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/charts/consul/test/unit/server-statefulset.bats b/charts/consul/test/unit/server-statefulset.bats index 6418cef313..ea10cc163d 100755 --- a/charts/consul/test/unit/server-statefulset.bats +++ b/charts/consul/test/unit/server-statefulset.bats @@ -138,6 +138,28 @@ load _helpers [ "${actual}" = "2" ] } +#-------------------------------------------------------------------- +# volumeClaim name + +@test "server/StatefulSet: no truncation for namespace <= 58 chars" { + cd `chart_dir` + local actual=$(helm template \ + -s templates/server-statefulset.yaml \ + . | tee /dev/stderr | + yq -r '.spec.volumeClaimTemplates[0].metadata.name' | tee /dev/stderr) + [ "${actual}" = "data-default" ] +} + +@test "server/StatefulSet: truncation for namespace > 58 chars" { + cd `chart_dir` + local actual=$(helm template \ + -n really-really-really-really-really-really-really-long-namespace \ + -s templates/server-statefulset.yaml \ + . | tee /dev/stderr | + yq -r '.spec.volumeClaimTemplates[0].metadata.name' | tee /dev/stderr) + [ "${actual}" = "data-really-really-really-really-really-really-really-long-name" ] +} + #-------------------------------------------------------------------- # storageClass