This is an automated email from the ASF dual-hosted git repository.

willholley pushed a commit to branch colearendt-close-39
in repository https://gitbox.apache.org/repos/asf/couchdb-helm.git

commit b3785f3c180a0f3d99c537ce42faa6c1213bfad4
Author: Cole Arendt <[email protected]>
AuthorDate: Tue May 10 06:28:37 2022 -0400

    allow uuid being created and managed by kubernetes
    
    We utilize Helm's `lookup` command to store a generated `uuid` in an 
"internal" secret in Kubernetes. This allows generating the `uuid`, making it 
persistent, and notifying the user (in `NOTES.txt`) that this auto-generation 
happened. We also tell the user how to disable the message by making that value 
persistent in values.
    
    close #39
---
 couchdb/Chart.yaml             |  2 +-
 couchdb/templates/NOTES.txt    | 11 +++++++++++
 couchdb/templates/_helpers.tpl | 31 ++++++++++++++++++++++++-------
 couchdb/templates/secrets.yaml | 15 ++++++++++++++-
 4 files changed, 50 insertions(+), 9 deletions(-)

diff --git a/couchdb/Chart.yaml b/couchdb/Chart.yaml
index a2ad72f..1015f31 100644
--- a/couchdb/Chart.yaml
+++ b/couchdb/Chart.yaml
@@ -1,6 +1,6 @@
 apiVersion: v1
 name: couchdb
-version: 4.6.3
+version: 4.6.4
 appVersion: 3.5.1
 description: A database featuring seamless multi-master sync, that scales from
   big data to mobile, with an intuitive HTTP/JSON API and designed for
diff --git a/couchdb/templates/NOTES.txt b/couchdb/templates/NOTES.txt
index 7a9dccd..95c239f 100644
--- a/couchdb/templates/NOTES.txt
+++ b/couchdb/templates/NOTES.txt
@@ -30,3 +30,14 @@ NOTE: You are using an auto-generated value for the Erlang 
Cookie
 kubectl -n {{ $.Release.Namespace }} get secret {{ include "couchdb.fullname" 
. }} --template='{{print "{{" }}index .data "erlangCookie" | base64decode{{ 
print "}}" }}'
 ```
 {{- end }}
+
+{{- $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 }}
diff --git a/couchdb/templates/_helpers.tpl b/couchdb/templates/_helpers.tpl
index e33f85c..94c02b7 100644
--- a/couchdb/templates/_helpers.tpl
+++ b/couchdb/templates/_helpers.tpl
@@ -94,13 +94,6 @@ If serviceAccount.name is specified, use that, else use the 
couchdb instance nam
 {{- end -}}
 {{- end -}}
 
-{{/*
-Fail if couchdbConfig.couchdb.uuid is undefined
-*/}}
-{{- define "couchdb.uuid" -}}
-{{- required "A value for couchdbConfig.couchdb.uuid must be set" 
(.Values.couchdbConfig.couchdb | default dict).uuid -}}
-{{- end -}}
-
 {{/*
 Repurpose volume claim metadata whether using the new volume claim template
 or existing volume claims.
@@ -142,4 +135,28 @@ storageClassName: "{{ 
$context.Values.persistentVolume.storageClass }}"
 {{- if $claim.persistentVolumeName }}
 volumeName: {{ $claim.persistentVolumeName }}
 {{- end }}
+
+{{/*
+    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" -}}
+
+{{- $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 38dace0..ff80dca 100644
--- a/couchdb/templates/secrets.yaml
+++ b/couchdb/templates/secrets.yaml
@@ -18,4 +18,17 @@ data:
 {{- if  .Values.adminHash  }}
   adminHash: {{ .Values.adminHash | b64enc | quote }}
 {{- 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" . }}

Reply via email to