Skip to content

Commit 3e50aaa

Browse files
colearendtwillholley
authored andcommitted
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
1 parent d732904 commit 3e50aaa

File tree

4 files changed

+51
-9
lines changed

4 files changed

+51
-9
lines changed

couchdb/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
apiVersion: v1
22
name: couchdb
3-
version: 4.6.3
3+
version: 4.6.4
44
appVersion: 3.5.1
55
description: A database featuring seamless multi-master sync, that scales from
66
big data to mobile, with an intuitive HTTP/JSON API and designed for

couchdb/templates/NOTES.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,14 @@ NOTE: You are using an auto-generated value for the Erlang Cookie
3030
kubectl -n {{ $.Release.Namespace }} get secret {{ include "couchdb.fullname" . }} --template='{{print "{{" }}index .data "erlangCookie" | base64decode{{ print "}}" }}'
3131
```
3232
{{- end }}
33+
34+
{{- $uuidVar := index (.Values.couchdbConfig.couchdb | default dict) "uuid" -}}
35+
{{- if (empty $uuidVar) }}
36+
NOTE: You are using an auto-generated value for the Couch DB UUID
37+
- We recommend making this value persistent by setting it in: `couchdbConfig.couchdb.uuid`
38+
- Changing this value can cause problems for the Couch DB installation
39+
- You can get the current value with:
40+
```
41+
kubectl -n {{ $.Release.Namespace }} get secret {{ include "couchdb.fullname" . }}-internal --template='{{print "{{" }}index .data "uuid" | base64decode{{ print "}}" }}'
42+
```
43+
{{- end }}

couchdb/templates/_helpers.tpl

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,6 @@ If serviceAccount.name is specified, use that, else use the couchdb instance nam
9494
{{- end -}}
9595
{{- end -}}
9696

97-
{{/*
98-
Fail if couchdbConfig.couchdb.uuid is undefined
99-
*/}}
100-
{{- define "couchdb.uuid" -}}
101-
{{- required "A value for couchdbConfig.couchdb.uuid must be set" (.Values.couchdbConfig.couchdb | default dict).uuid -}}
102-
{{- end -}}
103-
10497
{{/*
10598
Repurpose volume claim metadata whether using the new volume claim template
10699
or existing volume claims.
@@ -143,3 +136,28 @@ storageClassName: "{{ $context.Values.persistentVolume.storageClass }}"
143136
volumeName: {{ $claim.persistentVolumeName }}
144137
{{- end }}
145138
{{- end -}}
139+
140+
{{/*
141+
If couchdb UUID value is undefined:
142+
- if the configmap already exists, look it up
143+
- if not found or "dangerRegenerateAutomatedValues" is set, generate it
144+
- otherwise use the previous value
145+
Otherwise use what is defined in the chart
146+
147+
Also warn in NOTES.txt if this value is not persistent
148+
*/}}
149+
{{- define "couchdb.uuid" -}}
150+
151+
{{- $uuidVar := index (.Values.couchdbConfig.couchdb | default dict) "uuid" -}}
152+
{{- if (empty $uuidVar) }}
153+
{{- $secretName := print (include "couchdb.fullname" .) "-internal" }}
154+
{{- $currentSecret := lookup "v1" "Secret" $.Release.Namespace $secretName}}
155+
{{- if and $currentSecret (not .Values.dangerRegenerateAutomatedValues ) }}
156+
{{- $uuidVar = get $currentSecret.data "uuid" | b64dec }}
157+
{{- else }}
158+
{{- $uuidVar = uuidv4 -}}
159+
{{- end }}
160+
{{- end }}
161+
{{- print $uuidVar -}}
162+
163+
{{- end -}}

couchdb/templates/secrets.yaml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,17 @@ data:
1818
{{- if .Values.adminHash }}
1919
adminHash: {{ .Values.adminHash | b64enc | quote }}
2020
{{- end -}}
21-
{{- end -}}
21+
{{- end }}
22+
---
23+
apiVersion: v1
24+
kind: Secret
25+
metadata:
26+
name: {{ template "couchdb.fullname" . }}-internal
27+
labels:
28+
app: {{ template "couchdb.fullname" . }}
29+
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
30+
release: "{{ .Release.Name }}"
31+
heritage: "{{ .Release.Service }}"
32+
type: Opaque
33+
data:
34+
uuid: {{- include "couchdb.uuid" . }}

0 commit comments

Comments
 (0)