diff --git a/couchdb/templates/NOTES.txt b/couchdb/templates/NOTES.txt index 0727ca1..fe83430 100644 --- a/couchdb/templates/NOTES.txt +++ b/couchdb/templates/NOTES.txt @@ -19,6 +19,17 @@ some required system databases: Then it's time to relax. +{{- $uuidVar := index (.Values.couchdbConfig.couchdb | default dict) "uuid" -}} +{{- if (empty $uuidVar) }} +NOTE: You are using an auto-generated value for the Couch DB UUID + - We recommend making this value persistent by setting it in: `couchdbConfig.couchdb.uuid` + - Changing this value can cause problems for the Couch DB installation + - You can get the current value with: +``` +kubectl -n {{ $.Release.Namespace }} get secret {{ include "couchdb.fullname" . }}-internal --template='{{print "{{" }}index .data "uuid" | base64decode{{ print "}}" }}' +``` +{{- end }} + {{- $erlangCookie := .Values.erlangFlags.setcookie }} {{- if (empty $erlangCookie) }} diff --git a/couchdb/templates/_helpers.tpl b/couchdb/templates/_helpers.tpl index 2f5c1a4..994e095 100644 --- a/couchdb/templates/_helpers.tpl +++ b/couchdb/templates/_helpers.tpl @@ -97,8 +97,26 @@ If serviceAccount.name is specified, use that, else use the couchdb instance nam {{- end -}} {{/* -Fail if couchdbConfig.couchdb.uuid is undefined + If couchdb UUID value is undefined: + - if the configmap already exists, look it up + - if not found or "dangerRegenerateAutomatedValues" is set, generate it + - otherwise use the previous value + Otherwise use what is defined in the chart + + Also warn in NOTES.txt if this value is not persistent */}} {{- define "couchdb.uuid" -}} -{{- required "A value for couchdbConfig.couchdb.uuid must be set" (.Values.couchdbConfig.couchdb | default dict).uuid -}} + +{{- $uuidVar := index (.Values.couchdbConfig.couchdb | default dict) "uuid" -}} +{{- if (empty $uuidVar) }} + {{- $secretName := print (include "couchdb.fullname" .) "-internal" }} + {{- $currentSecret := lookup "v1" "Secret" $.Release.Namespace $secretName}} + {{- if and $currentSecret (not .Values.dangerRegenerateAutomatedValues ) }} + {{- $uuidVar = get $currentSecret.data "uuid" | b64dec }} + {{- else }} + {{- $uuidVar = uuidv4 -}} + {{- end }} +{{- end }} +{{- print $uuidVar -}} + {{- end -}} diff --git a/couchdb/templates/secrets.yaml b/couchdb/templates/secrets.yaml index 1028e53..615ada8 100644 --- a/couchdb/templates/secrets.yaml +++ b/couchdb/templates/secrets.yaml @@ -18,4 +18,17 @@ data: {{- if .Values.adminHash }} password.ini: {{ tpl (.Files.Get "password.ini") . | b64enc }} {{- end -}} -{{- end -}} +{{- end }} +--- +apiVersion: v1 +kind: Secret +metadata: + name: {{ template "couchdb.fullname" . }}-internal + labels: + app: {{ template "couchdb.fullname" . }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" + release: "{{ .Release.Name }}" + heritage: "{{ .Release.Service }}" +type: Opaque +data: + uuid: {{- include "couchdb.uuid" . }}