Skip to content

Commit 5299ffe

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 5299ffe

File tree

7 files changed

+77
-54
lines changed

7 files changed

+77
-54
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/NEWS.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
# NEWS
22

3+
## 4.6.4
4+
5+
- Auto-generate `couchdb.uuid` value on first deployment
6+
37
## 4.6.3
8+
49
- Update default CouchDB version to 3.5.1
510

611
## 4.6.2
12+
713
- Added options to specify `erlangCookie` and `cookieAuthSecret` within the extra secret
814

915
## 4.6.1
16+
1017
- Update default CouchDB version to 3.5.0
1118

1219
## 4.5.7

couchdb/README.md

Lines changed: 19 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@ storage volumes to each Pod in the Deployment.
1616
## TL;DR
1717

1818
```bash
19-
$ helm repo add couchdb https://apache.github.io/couchdb-helm
20-
$ helm install couchdb/couchdb \
21-
--version=4.6.3 \
22-
--set allowAdminParty=true \
23-
--set couchdbConfig.couchdb.uuid=$(curl https://www.uuidgenerator.net/api/version4 2>/dev/null | tr -d -)
19+
helm repo add couchdb https://apache.github.io/couchdb-helm
20+
helm install couchdb/couchdb \
21+
--version=4.6.4 \
22+
--set allowAdminParty=true
2423
```
2524

2625
## Prerequisites
@@ -35,39 +34,32 @@ To install the chart with the release name `my-release`:
3534
Add the CouchDB Helm repository:
3635

3736
```bash
38-
$ helm repo add couchdb https://apache.github.io/couchdb-helm
39-
```
40-
41-
Afterwards install the chart replacing the UUID
42-
`decafbaddecafbaddecafbaddecafbad` with a custom one:
43-
44-
```bash
45-
$ helm install \
37+
helm repo add couchdb https://apache.github.io/couchdb-helm
38+
helm install \
4639
--name my-release \
47-
--version=4.6.3 \
48-
--set couchdbConfig.couchdb.uuid=decafbaddecafbaddecafbaddecafbad \
40+
--version=4.6.4 \
4941
couchdb/couchdb
5042
```
5143

5244
This will create a Secret containing the admin credentials for the cluster.
5345
Those credentials can be retrieved as follows:
5446

5547
```bash
56-
$ kubectl get secret my-release-couchdb -o go-template='{{ .data.adminPassword }}' | base64 --decode
48+
kubectl get secret my-release-couchdb -o go-template='{{ .data.adminPassword }}' | base64 --decode
5749
```
5850

5951
If you prefer to configure the admin credentials directly you can create a
60-
Secret containing `adminUsername`, `adminPassword` and `cookieAuthSecret` keys:
52+
Secret containing `adminUsername`, `adminPassword`, `cookieAuthSecret` and `erlangCookie` keys:
6153

6254
```bash
63-
$ kubectl create secret generic my-release-couchdb --from-literal=adminUsername=foo --from-literal=adminPassword=bar --from-literal=cookieAuthSecret=baz
55+
kubectl create secret generic my-release-couchdb --from-literal=adminUsername=foo --from-literal=adminPassword=bar --from-literal=cookieAuthSecret=baz --from-literal=cookieAuthSecret=beep
6456
```
6557

6658
If you want to set the `adminHash` directly to achieve consistent salts between
6759
different nodes you need to add it to the secret:
6860

6961
```bash
70-
$ kubectl create secret generic my-release-couchdb \
62+
kubectl create secret generic my-release-couchdb \
7163
--from-literal=adminUsername=foo \
7264
--from-literal=cookieAuthSecret=baz \
7365
--from-literal=adminHash=-pbkdf2-d4b887da....
@@ -76,11 +68,10 @@ $ kubectl create secret generic my-release-couchdb \
7668
and then install the chart while overriding the `createAdminSecret` setting:
7769

7870
```bash
79-
$ helm install \
71+
helm install \
8072
--name my-release \
81-
--version=4.6.3 \
73+
--version=4.6.4 \
8274
--set createAdminSecret=false \
83-
--set couchdbConfig.couchdb.uuid=decafbaddecafbaddecafbaddecafbad \
8475
couchdb/couchdb
8576
```
8677

@@ -95,7 +86,7 @@ the parameters that can be configured during installation.
9586
To uninstall/delete the `my-release` Deployment:
9687

9788
```bash
98-
$ helm delete my-release
89+
helm delete my-release
9990
```
10091

10192
The command removes all the Kubernetes components associated with the chart and
@@ -106,20 +97,6 @@ deletes the release.
10697
A major chart version change (like v0.2.3 -> v1.0.0) indicates that there is an
10798
incompatible breaking change needing manual actions.
10899

109-
### Upgrade to 3.0.0
110-
111-
Since version 3.0.0 setting the CouchDB server instance UUID is mandatory.
112-
Therefore, you need to generate a UUID and supply it as a value during the
113-
upgrade as follows:
114-
115-
```bash
116-
$ helm upgrade <release-name> \
117-
--version=3.6.4 \
118-
--reuse-values \
119-
--set couchdbConfig.couchdb.uuid=<UUID> \
120-
couchdb/couchdb
121-
```
122-
123100
### Upgrade to 4.0.0
124101

125102
Breaking change between v3 and v4 is the `adminHash` in the secret that no longer uses
@@ -132,8 +109,8 @@ This chart replaces the `stable/couchdb` chart previously hosted by Helm and con
132109
version semantics. You can upgrade directly from `stable/couchdb` to this chart using:
133110

134111
```bash
135-
$ helm repo add couchdb https://apache.github.io/couchdb-helm
136-
$ helm upgrade my-release --version=4.6.3 couchdb/couchdb
112+
helm repo add couchdb https://apache.github.io/couchdb-helm
113+
helm upgrade my-release --version=4.6.4 couchdb/couchdb
137114
```
138115

139116
## Configuration
@@ -143,10 +120,10 @@ CouchDB chart and their default values:
143120

144121
| Key | Type | Default | Description |
145122
|-----|------|---------|-------------|
146-
| allowAdminParty | bool | `false` | If allowAdminParty is enabled the cluster will start up without any database administrator account; i.e., all users will be granted administrative access. Otherwise, the system will look for a Secret called <ReleaseName>-couchdb containing `adminUsername`, `adminPassword` and `cookieAuthSecret` keys. See the `createAdminSecret` flag. ref: https://kubernetes.io/docs/concepts/configuration/secret/ |
123+
| allowAdminParty | bool | `false` | If allowAdminParty is enabled the cluster will start up without any database administrator account; i.e., all users will be granted administrative access. Otherwise, the system will look for a Secret called <ReleaseName>-couchdb containing `adminUsername`, `adminPassword`, `cookieAuthSecret`, and `erlangCookie` keys. See the `createAdminSecret` flag. ref: https://kubernetes.io/docs/concepts/configuration/secret/ |
147124
| clusterSize | int | `3` | the initial number of nodes in the CouchDB cluster. |
148125
| couchdbConfig | object | `{"chttpd":{"bind_address":"any","require_valid_user":false}}` | couchdbConfig will override default CouchDB configuration settings. The contents of this map are reformatted into a .ini file laid down by a ConfigMap object. ref: http://docs.couchdb.org/en/latest/config/index.html |
149-
| createAdminSecret | bool | `true` | If createAdminSecret is enabled a Secret called <ReleaseName>-couchdb will be created containing auto-generated credentials. Users who prefer to set these values themselves have a couple of options: 1) The `adminUsername`, `adminPassword`, `adminHash`, and `cookieAuthSecret` can be defined directly in the chart's values. Note that all of a chart's values are currently stored in plaintext in a ConfigMap in the tiller namespace. 2) This flag can be disabled and a Secret with the required keys can be created ahead of time. |
126+
| createAdminSecret | bool | `true` | If createAdminSecret is enabled a Secret called <ReleaseName>-couchdb will be created containing auto-generated credentials. Users who prefer to set these values themselves have a couple of options: 1) The `adminUsername`, `adminPassword`, `adminHash` and `cookieAuthSecret` can be defined directly in the chart's values. Note that all of a chart's values are currently stored in plaintext in a ConfigMap in the tiller namespace. 2) This flag can be disabled and a Secret with the required keys can be created ahead of time. |
150127
| enableSearch | bool | `false` | Flip this to flag to include the Search container in each Pod |
151128
| erlangFlags | object | `{"name":"couchdb"}` | erlangFlags is a map that is passed to the Erlang VM as flags using the ERL_FLAGS env. The `name` flag is required to establish connectivity between cluster nodes. ref: http://erlang.org/doc/man/erl.html#init_flags |
152129
| persistentVolume | object | `{"accessModes":["ReadWriteOnce"],"enabled":false,"size":"10Gi"}` | The storage volume used by each Pod in the StatefulSet. If a persistentVolume is not enabled, the Pods will use `emptyDir` ephemeral local storage. Setting the storageClass attribute to "-" disables dynamic provisioning of Persistent Volumes; leaving it unset will invoke the default provisioner. |
@@ -157,7 +134,7 @@ required options to set:
157134

158135
| Parameter | Description | Default |
159136
|---------------------------------|--------------------------------------------------------------------|----------------------------------------|
160-
| `couchdb.uuid` | UUID for this CouchDB server instance ([Required in a cluster][5]) | |
137+
| `couchdb.uuid` | UUID for this CouchDB server instance | auto-generated |
161138
| `chttpd.bind_address` | listens on all interfaces when set to any | any |
162139
| `chttpd.require_valid_user` | disables all the anonymous requests to the port 5984 when true | false |
163140

couchdb/ci/required-values.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
1-
couchdbConfig:
2-
couchdb:
3-
uuid: "decafbaddecafbaddecafbaddecafbad"
41
annotations:
52
foo: bar

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)