From b4c658c966441a7ff18ded02b0cd4e11ce866545 Mon Sep 17 00:00:00 2001 From: Juan Ariza Toledano Date: Tue, 14 May 2019 12:53:11 +0200 Subject: [PATCH] [stable/nats] Use a validate helper to detect invalid configurations (#13745) * [stable/nats] Use a validate helper to detect invalid configurations Signed-off-by: juan131 * Remove extra line Signed-off-by: juan131 --- stable/nats/Chart.yaml | 2 +- stable/nats/templates/NOTES.txt | 15 +++------------ stable/nats/templates/_helpers.tpl | 23 +++++++++++++++++++++++ 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/stable/nats/Chart.yaml b/stable/nats/Chart.yaml index 6a441171af..ed008053f7 100644 --- a/stable/nats/Chart.yaml +++ b/stable/nats/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v1 name: nats -version: 2.5.0 +version: 2.5.1 appVersion: 1.4.1 description: An open-source, cloud-native messaging system keywords: diff --git a/stable/nats/templates/NOTES.txt b/stable/nats/templates/NOTES.txt index 383ad96bc1..396e01de7d 100644 --- a/stable/nats/templates/NOTES.txt +++ b/stable/nats/templates/NOTES.txt @@ -1,17 +1,5 @@ ** Please be patient while the chart is being deployed ** -{{- if and (not (eq .Values.resourceType "statefulset")) (not (eq .Values.resourceType "deployment")) }} - -------------------------------------------------------------------------------- - WARNING - - "resourceType" currently only "statefulset", "deployment" are allowed - the type specified in values.yaml >> {{ .Values.resourceType }} << is not defined in white list - but it will still continuing deploy with default resource type "statefulset" - -------------------------------------------------------------------------------- -{{- end }} - {{- if or (contains .Values.client.service.type "LoadBalancer") (contains .Values.client.service.type "nodePort") }} {{- if not .Values.auth.enabled }} {{ if and (not .Values.networkPolicy.enabled) (.Values.networkPolicy.allowExternal) }} @@ -97,4 +85,7 @@ To access the Monitoring svc from outside the cluster, follow the steps below: kubectl port-forward --namespace {{ .Release.Namespace }} {{ template "nats.fullname" . }}-0 {{ .Values.metrics.port }}:{{ .Values.metrics.port }} 4. Access NATS Prometheus metrics by opening the URL obtained in a browser. + {{- end }} + +{{- include "nats.validateValues" . -}} diff --git a/stable/nats/templates/_helpers.tpl b/stable/nats/templates/_helpers.tpl index fd2f84067a..6159ca0959 100644 --- a/stable/nats/templates/_helpers.tpl +++ b/stable/nats/templates/_helpers.tpl @@ -119,3 +119,26 @@ imagePullSecrets: {{- end }} {{- end -}} {{- end -}} + +{{/* +Compile all warnings into a single message, and call fail. +*/}} +{{- define "nats.validateValues" -}} +{{- $messages := list -}} +{{- $messages := append $messages (include "nats.validateValues.resourceType" .) -}} +{{- $messages := without $messages "" -}} +{{- $message := join "\n" $messages -}} + +{{- if $message -}} +{{- printf "\nVALUES VALIDATION:\n%s" $message | fail -}} +{{- end -}} +{{- end -}} + +{{/* Validate values of NATS - must provide a valid resourceType ("deployment" or "statefulset") */}} +{{- define "nats.validateValues.resourceType" -}} +{{- if and (ne .Values.resourceType "deployment") (ne .Values.resourceType "statefulset") -}} +nats: resourceType + Invalid resourceType selected. Valid values are "deployment" and + "statefulset". Please set a valid mode (--set resourceType="xxxx") +{{- end -}} +{{- end -}}