From 6763d5558b478f55152ec6d85ded089e47bee02b Mon Sep 17 00:00:00 2001 From: Tomas Pizarro Date: Fri, 4 Jan 2019 09:32:02 +0100 Subject: [PATCH] [stable/phpbb] Avoid setting SMTP env. variables when SMTP parameters are not set (#10394) * [stable/phpbb] Avoid setting SMTP env. variables when SMTP parameters are not set Signed-off-by: tompizmor * Not create smtpPassword secret if not needed Signed-off-by: tompizmor * Remove extra whitespaces when render template Signed-off-by: tompizmor --- stable/phpbb/Chart.yaml | 2 +- stable/phpbb/templates/NOTES.txt | 10 ++--- stable/phpbb/templates/_helpers.tpl | 7 ++++ stable/phpbb/templates/apache-pvc.yaml | 10 ++--- stable/phpbb/templates/deployment.yaml | 40 ++++++++++++------- .../phpbb/templates/externaldb-secrets.yaml | 6 +-- stable/phpbb/templates/phpbb-pvc.yaml | 10 ++--- stable/phpbb/templates/secrets.yaml | 18 +++++---- stable/phpbb/templates/svc.yaml | 12 +++--- 9 files changed, 67 insertions(+), 48 deletions(-) diff --git a/stable/phpbb/Chart.yaml b/stable/phpbb/Chart.yaml index fe86b6f304..87d26103df 100644 --- a/stable/phpbb/Chart.yaml +++ b/stable/phpbb/Chart.yaml @@ -1,5 +1,5 @@ name: phpbb -version: 4.0.0 +version: 4.0.1 appVersion: 3.2.4 description: Community forum that supports the notion of users and groups, file attachments, full-text search, notifications and more. diff --git a/stable/phpbb/templates/NOTES.txt b/stable/phpbb/templates/NOTES.txt index d9267ac6a7..81381d08bb 100644 --- a/stable/phpbb/templates/NOTES.txt +++ b/stable/phpbb/templates/NOTES.txt @@ -4,16 +4,16 @@ {{- if contains "NodePort" .Values.service.type }} - export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "phpbb.fullname" . }}) + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services "{{ template "phpbb.fullname" . }}") export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") echo "phpBB URL: http://$NODE_IP:$NODE_PORT/" {{- else if contains "LoadBalancer" .Values.service.type }} NOTE: It may take a few minutes for the LoadBalancer IP to be available. - Watch the status with: 'kubectl get svc --namespace {{ .Release.Namespace }} -w {{ template "phpbb.fullname" . }}' + Watch the status with: 'kubectl get svc --namespace {{ .Release.Namespace }} -w "{{ template "phpbb.fullname" . }}"' - export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "phpbb.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} "{{ template "phpbb.fullname" . }}" --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") {{- $port:=.Values.service.port | toString }} echo "phpBB URL: http://$SERVICE_IP{{- if ne $port "80" }}:{{ .Values.service.port }}{{ end }}/" @@ -21,14 +21,14 @@ {{- else if contains "ClusterIP" .Values.service.type }} echo "phpBB URL: http://127.0.0.1:8080/" - kubectl port-forward --namespace {{ .Release.Namespace }} svc/{{ template "phpbb.fullname" . }} 8080:{{ .Values.service.port }} + kubectl port-forward --namespace {{ .Release.Namespace }} svc/"{{ template "phpbb.fullname" . }}" 8080:{{ .Values.service.port }} {{- end }} 2. Get your phpBB login credentials by running: echo Username: {{ .Values.phpbbUser }} - echo Password: $(kubectl get secret --namespace {{ .Release.Namespace }} {{ template "phpbb.fullname" . }} -o jsonpath="{.data.phpbb-password}" | base64 --decode) + echo Password: $(kubectl get secret --namespace {{ .Release.Namespace }} "{{ template "phpbb.fullname" . }}" -o jsonpath="{.data.phpbb-password}" | base64 --decode) {{- else -}} diff --git a/stable/phpbb/templates/_helpers.tpl b/stable/phpbb/templates/_helpers.tpl index 0cd37d5d45..36950493a6 100644 --- a/stable/phpbb/templates/_helpers.tpl +++ b/stable/phpbb/templates/_helpers.tpl @@ -15,6 +15,13 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} {{- end -}} +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "phpbb.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + {{/* Create a default fully qualified app name. We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). diff --git a/stable/phpbb/templates/apache-pvc.yaml b/stable/phpbb/templates/apache-pvc.yaml index f0a258eddf..52773276b7 100644 --- a/stable/phpbb/templates/apache-pvc.yaml +++ b/stable/phpbb/templates/apache-pvc.yaml @@ -2,12 +2,12 @@ kind: PersistentVolumeClaim apiVersion: v1 metadata: - name: {{ template "phpbb.fullname" . }}-apache + name: "{{ template "phpbb.fullname" . }}-apache" labels: - app: {{ template "phpbb.fullname" . }} - chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" - release: "{{ .Release.Name }}" - heritage: "{{ .Release.Service }}" + app: "{{ template "phpbb.fullname" . }}" + chart: "{{ template "phpbb.chart" . }}" + release: {{ .Release.Name | quote }} + heritage: {{ .Release.Service | quote }} spec: accessModes: - {{ .Values.persistence.apache.accessMode | quote }} diff --git a/stable/phpbb/templates/deployment.yaml b/stable/phpbb/templates/deployment.yaml index a1540c01b2..19221cf55b 100644 --- a/stable/phpbb/templates/deployment.yaml +++ b/stable/phpbb/templates/deployment.yaml @@ -2,24 +2,24 @@ apiVersion: extensions/v1beta1 kind: Deployment metadata: - name: {{ template "phpbb.fullname" . }} + name: "{{ template "phpbb.fullname" . }}" labels: - app: {{ template "phpbb.fullname" . }} - chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" - release: "{{ .Release.Name }}" - heritage: "{{ .Release.Service }}" + app: "{{ template "phpbb.fullname" . }}" + chart: "{{ template "phpbb.chart" . }}" + release: {{ .Release.Name | quote }} + heritage: {{ .Release.Service | quote }} spec: selector: matchLabels: - app: {{ template "phpbb.fullname" . }} - release: "{{ .Release.Name }}" + app: "{{ template "phpbb.fullname" . }}" + release: {{ .Release.Name | quote }} replicas: 1 template: metadata: labels: - app: {{ template "phpbb.fullname" . }} - chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" - release: "{{ .Release.Name }}" + app: "{{ template "phpbb.fullname" . }}" + chart: "{{ template "phpbb.chart" . }}" + release: {{ .Release.Name | quote }} {{- if or .Values.podAnnotations .Values.metrics.enabled }} annotations: {{- if .Values.podAnnotations }} @@ -41,7 +41,7 @@ spec: hostnames: - "status.localhost" containers: - - name: {{ template "phpbb.fullname" . }} + - name: "{{ template "phpbb.fullname" . }}" image: {{ template "phpbb.image" . }} imagePullPolicy: {{ .Values.image.pullPolicy | quote }} env: @@ -86,23 +86,33 @@ spec: - name: PHPBB_PASSWORD valueFrom: secretKeyRef: - name: {{ template "phpbb.fullname" . }} + name: "{{ template "phpbb.fullname" . }}" key: phpbb-password - name: PHPBB_EMAIL value: {{ .Values.phpbbEmail | quote }} + {{- if .Values.smtpHost }} - name: SMTP_HOST value: {{ .Values.smtpHost | quote }} + {{- end }} + {{- if .Values.smtpPort }} - name: SMTP_PORT value: {{ .Values.smtpPort | quote }} + {{- end }} + {{- if .Values.smtpUser }} - name: SMTP_USER value: {{ .Values.smtpUser | quote }} + {{- end }} + {{- if .Values.smtpPassword }} - name: SMTP_PASSWORD valueFrom: secretKeyRef: - name: {{ template "phpbb.fullname" . }} + name: "{{ template "phpbb.fullname" . }}" key: smtp-password + {{- end }} + {{- if .Values.smtpProtocol }} - name: SMTP_PROTOCOL value: {{ default "" .Values.smtpProtocol | quote }} + {{- end }} ports: - name: http containerPort: 80 @@ -152,14 +162,14 @@ spec: - name: phpbb-data {{- if .Values.persistence.enabled }} persistentVolumeClaim: - claimName: {{ template "phpbb.fullname" . }}-phpbb + claimName: "{{ template "phpbb.fullname" . }}-phpbb" {{- else }} emptyDir: {} {{- end }} - name: apache-data {{- if .Values.persistence.enabled }} persistentVolumeClaim: - claimName: {{ template "phpbb.fullname" . }}-apache + claimName: "{{ template "phpbb.fullname" . }}-apache" {{- else }} emptyDir: {} {{- end }} diff --git a/stable/phpbb/templates/externaldb-secrets.yaml b/stable/phpbb/templates/externaldb-secrets.yaml index b189c76487..4cb9c9df80 100644 --- a/stable/phpbb/templates/externaldb-secrets.yaml +++ b/stable/phpbb/templates/externaldb-secrets.yaml @@ -5,9 +5,9 @@ metadata: name: {{ printf "%s-%s" .Release.Name "externaldb" }} labels: app: {{ printf "%s-%s" .Release.Name "externaldb" }} - chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" - release: "{{ .Release.Name }}" - heritage: "{{ .Release.Service }}" + chart: "{{ template "phpbb.chart" . }}" + release: {{ .Release.Name | quote }} + heritage: {{ .Release.Service | quote }} type: Opaque data: db-password: {{ default "" .Values.externalDatabase.password | b64enc | quote }} diff --git a/stable/phpbb/templates/phpbb-pvc.yaml b/stable/phpbb/templates/phpbb-pvc.yaml index 051325b1a5..2326c41530 100644 --- a/stable/phpbb/templates/phpbb-pvc.yaml +++ b/stable/phpbb/templates/phpbb-pvc.yaml @@ -2,12 +2,12 @@ kind: PersistentVolumeClaim apiVersion: v1 metadata: - name: {{ template "phpbb.fullname" . }}-phpbb + name: "{{ template "phpbb.fullname" . }}-phpbb" labels: - app: {{ template "phpbb.fullname" . }} - chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" - release: "{{ .Release.Name }}" - heritage: "{{ .Release.Service }}" + app: "{{ template "phpbb.fullname" . }}" + chart: "{{ template "phpbb.chart" . }}" + release: {{ .Release.Name | quote }} + heritage: {{ .Release.Service | quote }} spec: accessModes: - {{ .Values.persistence.phpbb.accessMode | quote }} diff --git a/stable/phpbb/templates/secrets.yaml b/stable/phpbb/templates/secrets.yaml index ee754c5aa6..fefcdaadd2 100644 --- a/stable/phpbb/templates/secrets.yaml +++ b/stable/phpbb/templates/secrets.yaml @@ -1,17 +1,19 @@ apiVersion: v1 kind: Secret metadata: - name: {{ template "phpbb.fullname" . }} + name: "{{ template "phpbb.fullname" . }}" labels: - app: {{ template "phpbb.fullname" . }} - chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" - release: "{{ .Release.Name }}" - heritage: "{{ .Release.Service }}" + app: "{{ template "phpbb.fullname" . }}" + chart: "{{ template "phpbb.chart" . }}" + release: {{ .Release.Name | quote }} + heritage: {{ .Release.Service | quote }} type: Opaque data: - {{ if .Values.phpbbPassword }} + {{- if .Values.phpbbPassword }} phpbb-password: {{ .Values.phpbbPassword | b64enc | quote }} - {{ else }} + {{- else }} phpbb-password: {{ randAlphaNum 10 | b64enc | quote }} - {{ end }} + {{- end }} + {{- if .Values.smtpPassword }} smtp-password: {{ default "" .Values.smtpPassword | b64enc | quote }} + {{- end }} diff --git a/stable/phpbb/templates/svc.yaml b/stable/phpbb/templates/svc.yaml index beeeffabe0..256fccf505 100644 --- a/stable/phpbb/templates/svc.yaml +++ b/stable/phpbb/templates/svc.yaml @@ -1,12 +1,12 @@ apiVersion: v1 kind: Service metadata: - name: {{ template "phpbb.fullname" . }} + name: "{{ template "phpbb.fullname" . }}" labels: - app: {{ template "phpbb.fullname" . }} - chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" - release: "{{ .Release.Name }}" - heritage: "{{ .Release.Service }}" + app: "{{ template "phpbb.fullname" . }}" + chart: "{{ template "phpbb.chart" . }}" + release: {{ .Release.Name | quote }} + heritage: {{ .Release.Service | quote }} spec: type: {{ .Values.service.type }} {{- if eq .Values.service.type "LoadBalancer" }} @@ -29,4 +29,4 @@ spec: nodePort: {{ .Values.service.nodePorts.https }} {{- end }} selector: - app: {{ template "phpbb.fullname" . }} + app: "{{ template "phpbb.fullname" . }}"