Skip to content

Commit

Permalink
feat: allow configure persistentVolumeClaimRetentionPolicy (#136)
Browse files Browse the repository at this point in the history
Allow to specify a persistentVolumeClaimRetentionPolicy in both the primary and secondary StatefulSet.

This allows for automatic cleanup of PVCs after deletion, etc. An example use case of this is for highly dynamic test environments, where cleaning up the PVCs after deletion of the helm chart is preferred.
  • Loading branch information
ByJacob authored May 7, 2024
1 parent 8ce7048 commit c83baf8
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion couchdb/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v1
name: couchdb
version: 4.5.1
version: 4.5.2
appVersion: 3.3.3
description: A database featuring seamless multi-master sync, that scales from
big data to mobile, with an intuitive HTTP/JSON API and designed for
Expand Down
13 changes: 8 additions & 5 deletions couchdb/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CouchDB

![Version: 4.5.1](https://img.shields.io/badge/Version-4.5.1-informational?style=flat-square) ![AppVersion: 3.3.3](https://img.shields.io/badge/AppVersion-3.3.3-informational?style=flat-square)
![Version: 4.5.2](https://img.shields.io/badge/Version-4.5.2-informational?style=flat-square) ![AppVersion: 3.3.3](https://img.shields.io/badge/AppVersion-3.3.3-informational?style=flat-square)

Apache CouchDB is a database featuring seamless multi-master sync, that scales
from big data to mobile, with an intuitive HTTP/JSON API and designed for
Expand All @@ -18,7 +18,7 @@ storage volumes to each Pod in the Deployment.
```bash
$ helm repo add couchdb https://apache.github.io/couchdb-helm
$ helm install couchdb/couchdb \
--version=4.5.1 \
--version=4.5.2 \
--set allowAdminParty=true \
--set couchdbConfig.couchdb.uuid=$(curl https://www.uuidgenerator.net/api/version4 2>/dev/null | tr -d -)
```
Expand All @@ -44,7 +44,7 @@ Afterwards install the chart replacing the UUID
```bash
$ helm install \
--name my-release \
--version=4.5.1 \
--version=4.5.2 \
--set couchdbConfig.couchdb.uuid=decafbaddecafbaddecafbaddecafbad \
couchdb/couchdb
```
Expand Down Expand Up @@ -78,7 +78,7 @@ and then install the chart while overriding the `createAdminSecret` setting:
```bash
$ helm install \
--name my-release \
--version=4.5.1 \
--version=4.5.2 \
--set createAdminSecret=false \
--set couchdbConfig.couchdb.uuid=decafbaddecafbaddecafbaddecafbad \
couchdb/couchdb
Expand Down Expand Up @@ -133,7 +133,7 @@ version semantics. You can upgrade directly from `stable/couchdb` to this chart

```bash
$ helm repo add couchdb https://apache.github.io/couchdb-helm
$ helm upgrade my-release --version=4.5.1 couchdb/couchdb
$ helm upgrade my-release --version=4.5.2 couchdb/couchdb
```

## Configuration
Expand Down Expand Up @@ -194,6 +194,9 @@ A variety of other parameters are also configurable. See the comments in the
| `persistentVolume.claimName` | |
| `persistentVolume.volumeSource` | |
| `persistentVolume.annotations` | {} |
| `persistentVolumeClaimRetentionPolicy.enabled` | Field controls if and how PVCs are deleted during the lifecycle |
| `persistentVolumeClaimRetentionPolicy.whenScaled` | Configures the volume retention behavior that applies when the replica count of the StatefulSet is reduced |
| `persistentVolumeClaimRetentionPolicy.whenDeleted` | Configures the volume retention behavior that applies when the StatefulSet is deleted |
| `podDisruptionBudget.enabled` | false |
| `podDisruptionBudget.minAvailable` | nil |
| `podDisruptionBudget.maxUnavailable` | 1 |
Expand Down
5 changes: 5 additions & 0 deletions couchdb/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ spec:
claimName: {{ $claim.claimName }}
{{- end }}
{{- else }}
{{- if .Values.persistentVolumeClaimRetentionPolicy.enabled }}
persistentVolumeClaimRetentionPolicy:
whenDeleted: {{ .Values.persistentVolumeClaimRetentionPolicy.whenDeleted }}
whenScaled: {{ .Values.persistentVolumeClaimRetentionPolicy.whenScaled }}
{{- end }}
volumeClaimTemplates:
- metadata:
{{- include "persistentVolume.metadata" (dict "context" .) | nindent 8 }}
Expand Down
9 changes: 9 additions & 0 deletions couchdb/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ persistentVolume:
size: 10Gi
# storageClass: "-"

# Experimental - FEATURE STATE: Kubernetes v1.27 [beta]
# Field controls if and how PVCs are deleted during the lifecycle
# of a StatefulSet
# ref: https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#persistentvolumeclaim-retention
persistentVolumeClaimRetentionPolicy:
enabled: false
whenScaled: Retain
whenDeleted: Retain

## The CouchDB image
image:
repository: couchdb
Expand Down
2 changes: 1 addition & 1 deletion test/e2e-kind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ readonly K8S_VERSION=v1.25.3

run_ct_container() {
echo 'Running ct container...'
docker run --rm --interactive --detach --network host --name ct \
docker run --rm --interactive --detach --network host --name ct --userns=host \
--volume "$(pwd)/test/ct.yaml:/etc/ct/ct.yaml" \
--volume "$(pwd):/workdir" \
--workdir /workdir \
Expand Down

0 comments on commit c83baf8

Please sign in to comment.