From 6b81d1ebdff2a61cf0c109130c7f8b2c236bca35 Mon Sep 17 00:00:00 2001 From: sbienkow-ninja <85104051+sbienkow-ninja@users.noreply.github.com> Date: Tue, 13 Jul 2021 13:49:11 +0200 Subject: [PATCH] Trim suffix dash from port name in gcloud-sqlproxy (#108) When your instance name has '-' as 15th character, it caused invalid name to be generated --- stable/gcloud-sqlproxy/Chart.yaml | 2 +- stable/gcloud-sqlproxy/templates/_helpers.tpl | 7 +++++++ stable/gcloud-sqlproxy/templates/deployment.yaml | 3 ++- stable/gcloud-sqlproxy/templates/svc-statefulset.yaml | 5 +++-- stable/gcloud-sqlproxy/templates/svc.yaml | 5 +++-- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/stable/gcloud-sqlproxy/Chart.yaml b/stable/gcloud-sqlproxy/Chart.yaml index 34a5665..854dee4 100755 --- a/stable/gcloud-sqlproxy/Chart.yaml +++ b/stable/gcloud-sqlproxy/Chart.yaml @@ -18,4 +18,4 @@ maintainers: name: gcloud-sqlproxy sources: - https://github.com/rimusz/charts -version: 0.20.5 +version: 0.20.6 diff --git a/stable/gcloud-sqlproxy/templates/_helpers.tpl b/stable/gcloud-sqlproxy/templates/_helpers.tpl index baf6420..27d6100 100755 --- a/stable/gcloud-sqlproxy/templates/_helpers.tpl +++ b/stable/gcloud-sqlproxy/templates/_helpers.tpl @@ -89,3 +89,10 @@ Create the name of the service account to use {{ default "default" .Values.serviceAccount.name }} {{- end -}} {{- end -}} + +{{/* +Create the short instance name +*/}} +{{- define "gcloud-sqlproxy.instanceShortName" -}} +{{ .instanceShortName | default (.instance | trunc 15 | trimSuffix "-") }} +{{- end -}} diff --git a/stable/gcloud-sqlproxy/templates/deployment.yaml b/stable/gcloud-sqlproxy/templates/deployment.yaml index 8556c5e..eed8b2a 100755 --- a/stable/gcloud-sqlproxy/templates/deployment.yaml +++ b/stable/gcloud-sqlproxy/templates/deployment.yaml @@ -61,7 +61,8 @@ spec: {{- end }} ports: {{- range .Values.cloudsql.instances }} - - name: {{ .instanceShortName | default (.instance | trunc 15) }} + {{- $instanceShortName := include "gcloud-sqlproxy.instanceShortName" . }} + - name: {{ $instanceShortName }} containerPort: {{ .port }} {{- end }} {{- if .Values.livenessProbe.enabled }} diff --git a/stable/gcloud-sqlproxy/templates/svc-statefulset.yaml b/stable/gcloud-sqlproxy/templates/svc-statefulset.yaml index a35bb6e..e82c2cb 100644 --- a/stable/gcloud-sqlproxy/templates/svc-statefulset.yaml +++ b/stable/gcloud-sqlproxy/templates/svc-statefulset.yaml @@ -10,10 +10,11 @@ spec: clusterIP: None ports: {{- range .Values.cloudsql.instances }} - - name: {{ .instanceShortName | default (.instance | trunc 15) }} + {{- $instanceShortName := include "gcloud-sqlproxy.instanceShortName" . }} + - name: {{ $instanceShortName }} protocol: TCP port: {{ .port }} - targetPort: {{ .instanceShortName | default (.instance | trunc 15) }} + targetPort: {{ $instanceShortName }} {{- end }} selector: {{- include "gcloud-sqlproxy.selectorLabels" . | nindent 4 }} diff --git a/stable/gcloud-sqlproxy/templates/svc.yaml b/stable/gcloud-sqlproxy/templates/svc.yaml index 4452d5a..7f29493 100755 --- a/stable/gcloud-sqlproxy/templates/svc.yaml +++ b/stable/gcloud-sqlproxy/templates/svc.yaml @@ -18,10 +18,11 @@ spec: {{- end }} ports: {{- range .Values.cloudsql.instances }} - - name: {{ .instanceShortName | default (.instance | trunc 15) }} + {{- $instanceShortName := include "gcloud-sqlproxy.instanceShortName" . }} + - name: {{ $instanceShortName }} protocol: TCP port: {{ .port }} - targetPort: {{ .instanceShortName | default (.instance | trunc 15) }} + targetPort: {{ $instanceShortName }} {{- end }} selector: {{- include "gcloud-sqlproxy.selectorLabels" . | nindent 4 }}