From e2d9b916e2fe1b6880ec6d8ea2e07abb2a6ae0e9 Mon Sep 17 00:00:00 2001 From: micw Date: Thu, 28 Feb 2019 19:07:33 +0000 Subject: [PATCH] #11812 allow hostPath as datadir (#11815) * allow hostPath as datadir Signed-off-by: Michael Wyraz * Better documentation for hostPath as datadir, make the chown init-container optional Signed-off-by: Michael Wyraz --- stable/redis-ha/Chart.yaml | 2 +- stable/redis-ha/README.md | 2 ++ .../templates/redis-ha-statefulset.yaml | 18 ++++++++++++++++++ stable/redis-ha/values.yaml | 12 ++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/stable/redis-ha/Chart.yaml b/stable/redis-ha/Chart.yaml index 660e9bf337..530289b35e 100644 --- a/stable/redis-ha/Chart.yaml +++ b/stable/redis-ha/Chart.yaml @@ -5,7 +5,7 @@ keywords: - redis - keyvalue - database -version: 3.2.0 +version: 3.2.1 appVersion: 5.0.3 description: Highly available Kubernetes implementation of Redis icon: https://upload.wikimedia.org/wikipedia/en/thumb/6/6b/Redis_Logo.svg/1200px-Redis_Logo.svg.png diff --git a/stable/redis-ha/README.md b/stable/redis-ha/README.md index cf5325d27e..f495ba9ce9 100644 --- a/stable/redis-ha/README.md +++ b/stable/redis-ha/README.md @@ -78,6 +78,8 @@ The following table lists the configurable parameters of the Redis chart and the | `exporter.tag` | Exporter tag | `v0.28.0` | | `exporter.annotations` | Prometheus scrape annotations | `{prometheus.io/path: /metrics, prometheus.io/port: "9121", prometheus.io/scrape: "true"}` | | `exporter.extraArgs` | Additional args for the exporter | `{}` | +| `hostPath.path` | Use this path on the host for data storage | not set | +| `hostPath.chown` | Run an init-container as root to set ownership on the hostPath | true | Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example, diff --git a/stable/redis-ha/templates/redis-ha-statefulset.yaml b/stable/redis-ha/templates/redis-ha-statefulset.yaml index 3fde614608..48502632c9 100644 --- a/stable/redis-ha/templates/redis-ha-statefulset.yaml +++ b/stable/redis-ha/templates/redis-ha-statefulset.yaml @@ -49,6 +49,20 @@ spec: securityContext: {{ toYaml .Values.securityContext | indent 8 }} initContainers: +{{- if and .Values.hostPath.path .Values.hostPath.chown }} + - name: hostpath-chown + image: {{ .Values.image.repository }}:{{ .Values.image.tag }} + securityContext: + runAsNonRoot: false + runAsUser: 0 + command: + - chown + - "{{ .Values.securityContext.runAsUser }}" + - /data + volumeMounts: + - name: data + mountPath: /data +{{- end }} - name: config-init image: {{ .Values.image.repository }}:{{ .Values.image.tag }} imagePullPolicy: {{ .Values.image.pullPolicy }} @@ -225,6 +239,10 @@ spec: storageClassName: "{{ .Values.persistentVolume.storageClass }}" {{- end }} {{- end }} +{{- else if .Values.hostPath.path }} + - name: data + hostPath: + path: {{ tpl .Values.hostPath.path .}} {{- else }} - name: data emptyDir: {} diff --git a/stable/redis-ha/values.yaml b/stable/redis-ha/values.yaml index 6e118f064b..c5b96d8393 100644 --- a/stable/redis-ha/values.yaml +++ b/stable/redis-ha/values.yaml @@ -138,3 +138,15 @@ persistentVolume: annotations: {} init: resources: {} + +# To use a hostPath for data, set persistentVolume.enabled to false +# and define hostPath.path. +# Warning: this might overwrite existing folders on the host system! +hostPath: + ## path is evaluated as template so placeholders are replaced + # path: "/data/{{ .Release.Name }}" + + # if chown is true, an init-container with root permissions is launched to + # change the owner of the hostPath folder to the user defined in the + # security context + chown: true