From 3d2733d2c164cd5ec47f8bd17036dbac03528090 Mon Sep 17 00:00:00 2001 From: Philip Champon Date: Wed, 15 Mar 2017 07:06:46 -0400 Subject: [PATCH] [stable/postgresql] add persistence.existingClaim (#616) * add persistence.existingClaim to postgresql * update docs * make template inline * nope, that was not right * up version * clean up templating * bump minor version --- stable/postgresql/Chart.yaml | 2 +- stable/postgresql/README.md | 12 +++++++++++- stable/postgresql/templates/_helpers.tpl | 1 + stable/postgresql/templates/deployment.yaml | 4 ++-- stable/postgresql/templates/pvc.yaml | 4 ++-- stable/postgresql/values.yaml | 6 ++++++ 6 files changed, 23 insertions(+), 6 deletions(-) diff --git a/stable/postgresql/Chart.yaml b/stable/postgresql/Chart.yaml index edf5eb0575..afb25ba37b 100644 --- a/stable/postgresql/Chart.yaml +++ b/stable/postgresql/Chart.yaml @@ -1,5 +1,5 @@ name: postgresql -version: 0.4.0 +version: 0.5.0 description: Object-relational database management system (ORDBMS) with an emphasis on extensibility and on standards-compliance. keywords: - postgresql diff --git a/stable/postgresql/README.md b/stable/postgresql/README.md index 60f781a848..b0946909dd 100644 --- a/stable/postgresql/README.md +++ b/stable/postgresql/README.md @@ -52,6 +52,7 @@ The following tables lists the configurable parameters of the PostgresSQL chart | `postgresPassword` | Password for the new user. | random 10 characters | | `postgresDatabase` | Name for new database to create. | `postgres` | | `persistence.enabled` | Use a PVC to persist data | `true` | +| `persistence.existingClaim`| Provide an existing PersistentVolumeClaim | `nil` | | `persistence.storageClass` | Storage class of backing PVC | `nil` (uses alpha storage class annotation) | | `persistence.accessMode` | Use volume as ReadOnly or ReadWrite | `ReadWriteOnce` | | `persistence.size` | Size of data volume | `8Gi` | @@ -87,7 +88,16 @@ $ helm install --name my-release -f values.yaml stable/postgresql The [postgres](https://github.com/docker-library/postgres) image stores the PostgreSQL data and configurations at the `/var/lib/postgresql/data/pgdata` path of the container. -The chart mounts a [Persistent Volume](http://kubernetes.io/docs/user-guide/persistent-volumes/) volume at this location. The volume is created using dynamic volume provisioning. +The chart mounts a [Persistent Volume](http://kubernetes.io/docs/user-guide/persistent-volumes/) volume at this location. The volume is created using dynamic volume provisioning. If the PersistentVolumeClaim should not be managed by the chart, define `persistence.existingClaim`. + +### Existing PersistentVolumeClaims + +1. Create the PersistentVolume +1. Create the PersistentVolumeClaim +1. Install the chart +```bash +$ helm install --set persistence.existingClaim=PVC_NAME postgresql +``` The volume defaults to mount at a subdirectory of the volume instead of the volume root to avoid the volume's hidden directories from interfering with `initdb`. If you are upgrading this chart from before version `0.4.0`, set `persistence.subPath` to `""`. diff --git a/stable/postgresql/templates/_helpers.tpl b/stable/postgresql/templates/_helpers.tpl index f0d83d2edb..2bf4e517f5 100644 --- a/stable/postgresql/templates/_helpers.tpl +++ b/stable/postgresql/templates/_helpers.tpl @@ -14,3 +14,4 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this {{- $name := default .Chart.Name .Values.nameOverride -}} {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} {{- end -}} + diff --git a/stable/postgresql/templates/deployment.yaml b/stable/postgresql/templates/deployment.yaml index c2d0eef461..a14bb6342b 100644 --- a/stable/postgresql/templates/deployment.yaml +++ b/stable/postgresql/templates/deployment.yaml @@ -54,7 +54,7 @@ spec: mountPath: /var/lib/postgresql/data/pgdata subPath: {{ .Values.persistence.subPath }} {{- if .Values.metrics.enabled }} - - name: metrics + - name: metrics image: "{{ .Values.metrics.image }}:{{ .Values.metrics.imageTag }}" imagePullPolicy: {{ default "" .Values.metrics.imagePullPolicy | quote }} env: @@ -70,7 +70,7 @@ spec: - name: data {{- if .Values.persistence.enabled }} persistentVolumeClaim: - claimName: {{ template "fullname" . }} + claimName: {{ .Values.persistence.existingClaim | default (include "fullname" .) }} {{- else }} emptyDir: {} {{- end -}} diff --git a/stable/postgresql/templates/pvc.yaml b/stable/postgresql/templates/pvc.yaml index 6a21fe551b..2424b389ce 100644 --- a/stable/postgresql/templates/pvc.yaml +++ b/stable/postgresql/templates/pvc.yaml @@ -1,4 +1,4 @@ -{{- if .Values.persistence.enabled }} +{{- if and .Values.persistence.enabled (not .Values.persistence.existingClaim) -}} kind: PersistentVolumeClaim apiVersion: v1 metadata: @@ -20,4 +20,4 @@ spec: resources: requests: storage: {{ .Values.persistence.size | quote }} -{{- end }} +{{- end -}} diff --git a/stable/postgresql/values.yaml b/stable/postgresql/values.yaml index 696f50ff71..8431b49780 100644 --- a/stable/postgresql/values.yaml +++ b/stable/postgresql/values.yaml @@ -24,6 +24,12 @@ imageTag: "9.5.4" ## Persist data to a persitent volume persistence: enabled: true + + ## A manually managed Persistent Volume and Claim + ## Requires persistence.enabled: true + ## If defined, PVC must be created manually before volume will be bound + # existingClaim: + ## If defined, volume.beta.kubernetes.io/storage-class: ## Default: volume.alpha.kubernetes.io/storage-class: default ##