From badd745ef0c48821bd0455f8a702c1ad83e82b6a Mon Sep 17 00:00:00 2001 From: Juan Ariza Toledano Date: Mon, 29 Jul 2019 15:49:55 +0200 Subject: [PATCH] [stable/mongodb] Validate 'mongodbDatabase' and 'mongodbUsername' parameters (#15938) Signed-off-by: juan131 --- stable/mongodb/Chart.yaml | 2 +- stable/mongodb/README.md | 2 +- stable/mongodb/templates/NOTES.txt | 2 ++ stable/mongodb/templates/_helpers.tpl | 27 +++++++++++++++++++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/stable/mongodb/Chart.yaml b/stable/mongodb/Chart.yaml index b09d7552cd..b1b7f3eab3 100644 --- a/stable/mongodb/Chart.yaml +++ b/stable/mongodb/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v1 name: mongodb -version: 6.3.0 +version: 6.3.1 appVersion: 4.0.11 description: NoSQL document-oriented database that stores JSON-like documents with dynamic schemas, simplifying the integration of data in content-driven applications. keywords: diff --git a/stable/mongodb/README.md b/stable/mongodb/README.md index b97956c051..a55af3e3fe 100644 --- a/stable/mongodb/README.md +++ b/stable/mongodb/README.md @@ -67,7 +67,7 @@ The following table lists the configurable parameters of the MongoDB chart and t | `usePassword` | Enable password authentication | `true` | | `existingSecret` | Existing secret with MongoDB credentials | `nil` | | `mongodbRootPassword` | MongoDB admin password | `random alphanumeric string (10)` | -| `mongodbUsername` | MongoDB custom user | `nil` | +| `mongodbUsername` | MongoDB custom user (mandatory if `mongodbDatabase` is set) | `nil` | | `mongodbPassword` | MongoDB custom user password | `random alphanumeric string (10)` | | `mongodbDatabase` | Database to create | `nil` | | `mongodbEnableIPv6` | Switch to enable/disable IPv6 on MongoDB | `false` | diff --git a/stable/mongodb/templates/NOTES.txt b/stable/mongodb/templates/NOTES.txt index 360c05a7d1..69da5c1954 100644 --- a/stable/mongodb/templates/NOTES.txt +++ b/stable/mongodb/templates/NOTES.txt @@ -65,6 +65,8 @@ To connect to your database from outside the cluster execute the following comma {{- end }} +{{- include "mongodb.validateValues" . -}} + {{- if and (contains "bitnami/" .Values.image.repository) (not (.Values.image.tag | toString | regexFind "-r\\d+$|sha256:")) }} WARNING: Rolling tag detected ({{ .Values.image.repository }}:{{ .Values.image.tag }}), please note that it is strongly recommended to avoid using rolling tags in a production environment. diff --git a/stable/mongodb/templates/_helpers.tpl b/stable/mongodb/templates/_helpers.tpl index 0f1a1119bd..4e7c569604 100644 --- a/stable/mongodb/templates/_helpers.tpl +++ b/stable/mongodb/templates/_helpers.tpl @@ -163,3 +163,30 @@ Also, we can't use a single if because lazy evaluation is not an option {{- printf "%s/%s:%s" $registryName $repositoryName $tag -}} {{- end -}} {{- end -}} + +{{/* +Compile all warnings into a single message, and call fail. +*/}} +{{- define "mongodb.validateValues" -}} +{{- $messages := list -}} +{{- $messages := append $messages (include "mongodb.validateValues.mongodbCustomDatabase" .) -}} +{{- $messages := without $messages "" -}} +{{- $message := join "\n" $messages -}} + +{{- if $message -}} +{{- printf "\nVALUES VALIDATION:\n%s" $message | fail -}} +{{- end -}} +{{- end -}} + +{{/* +Validate values of MongoDB - both mongodbUsername and mongodbDatabase are necessary +to create a custom user and database during 1st initialization +*/}} +{{- define "mongodb.validateValues.mongodbCustomDatabase" -}} +{{- if or (and .Values.mongodbUsername (not .Values.mongodbDatabase)) (and (not .Values.mongodbUsername) .Values.mongodbDatabase) }} +mongodb: mongodbUsername, mongodbDatabase + Both mongodbUsername and mongodbDatabase must be provided to create + a custom user and database during 1st initialization. + Please set both of them (--set mongodbUsername="xxxx",mongodbDatabase="yyyy") +{{- end -}} +{{- end -}}