From b25be91b3679746e85adad71f944d9cf2e89b697 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?G=C3=B6ran=20P=C3=B6hner?=
 <10630407+groundhog2k@users.noreply.github.com>
Date: Fri, 10 Mar 2023 15:47:58 +0100
Subject: [PATCH] Redis Deployment vs Statefulset (#1210)

---
 charts/redis/Chart.yaml                 | 4 ++--
 charts/redis/README.md                  | 3 ++-
 charts/redis/RELEASENOTES.md            | 2 ++
 charts/redis/templates/statefulset.yaml | 6 ++++++
 charts/redis/values.yaml                | 3 +++
 5 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/charts/redis/Chart.yaml b/charts/redis/Chart.yaml
index fe98b697..9436566c 100644
--- a/charts/redis/Chart.yaml
+++ b/charts/redis/Chart.yaml
@@ -8,7 +8,7 @@ maintainers:
   - name: groundhog2k
 
 # This is the chart version
-version: "0.6.3"
+version: "0.4.15"
 
 # This is the version number of the application being deployed.
-appVersion: "7.0.9"
+appVersion: "6.2.11"
diff --git a/charts/redis/README.md b/charts/redis/README.md
index e2e3cc7a..b1cfa45c 100644
--- a/charts/redis/README.md
+++ b/charts/redis/README.md
@@ -1,6 +1,6 @@
 # Redis
 
-![Version: 0.6.3](https://img.shields.io/badge/Version-0.6.3-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 7.0.9](https://img.shields.io/badge/AppVersion-7.0.9-informational?style=flat-square)
+![Version: 0.6.4](https://img.shields.io/badge/Version-0.6.4-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 7.0.9](https://img.shields.io/badge/AppVersion-7.0.9-informational?style=flat-square)
 
 ## Changelog
 
@@ -159,6 +159,7 @@ helm uninstall my-release
 | extraSentinelSecrets | list | `[]` | A list of additional existing secrets that will be mounted into the sentinel container |
 | extraSentinelSecrets[].name | string | `nil` | Name of the existing K8s secret |
 | extraSentinelSecrets[].mountPath | string | `nil` | Mount path where the secret should be mounted into the container (f.e. /mysecretfolder) |
+| useDeploymentWhenNonHA | bool | `true` | Use Deployment instead of StatefulSet for Non-HA deployments |
 | haMode.enabled | bool | `false` | Enable Redis high availibility mode with master-slave replication and sentinel |
 | haMode.useDnsNames | bool | `false` | Use DNS names instead of Pod IPs to build the cluster |
 | haMode.masterGroupName | string | `"redisha"` | Mandatory redis HA-master group name |
diff --git a/charts/redis/RELEASENOTES.md b/charts/redis/RELEASENOTES.md
index 44f99007..a296c04a 100644
--- a/charts/redis/RELEASENOTES.md
+++ b/charts/redis/RELEASENOTES.md
@@ -7,6 +7,7 @@
 | 0.4.12 | 6.2.7 | Upgraded to Redis 6.2.7 |
 | 0.4.13 | 6.2.10 | Upgraded to Redis 6.2.10 |
 | 0.4.14 | 6.2.11 | Upgraded to Redis 6.2.11 |
+| 0.4.15 | 6.2.11 | Added option to use Deployment instead of StatefulSet for Non-HA deployments - thx @tim-hanssen |
 | 0.5.0 | 7.0.0 | Upgraded to Redis 7.0.0 |
 | 0.5.1 | 7.0.1 | Upgraded to Redis 7.0.1 |
 | 0.5.2 | 7.0.2 | Upgraded to Redis 7.0.2 |
@@ -22,4 +23,5 @@
 | 0.6.1 | 7.0.8 | Upgraded to Redis 7.0.8 |
 | 0.6.2 | 7.0.8 | Updated version detection for pod disruption budget |
 | 0.6.3 | 7.0.9 | Upgraded to Redis 7.0.9 |
+| 0.6.4 | 7.0.9 | Added option to use Deployment instead of StatefulSet for Non-HA deployments - thx @tim-hanssen |
 | | | |
diff --git a/charts/redis/templates/statefulset.yaml b/charts/redis/templates/statefulset.yaml
index 6a965d40..b4cbbf25 100644
--- a/charts/redis/templates/statefulset.yaml
+++ b/charts/redis/templates/statefulset.yaml
@@ -1,5 +1,9 @@
 apiVersion: apps/v1
+{{- if and (not .Values.haMode.enabled) (.Values.useDeploymentWhenNonHA) }}
+kind: Deployment
+{{- else }}
 kind: StatefulSet
+{{- end }}
 metadata:
   name: {{ include "redis.fullname" . }}
   labels:
@@ -13,10 +17,12 @@ spec:
   {{- if .Values.revisionHistoryLimit }}
   revisionHistoryLimit: {{ .Values.revisionHistoryLimit }}
   {{- end }}
+  {{- if or (.Values.haMode.enabled) (not .Values.useDeploymentWhenNonHA) }}
   serviceName: {{ include "redis.fullname" . }}-headless
   podManagementPolicy: {{ .Values.podManagementPolicy }}
   updateStrategy: 
     type: {{ .Values.updateStrategyType }}
+  {{- end }}
   selector:
     matchLabels:
       {{- include "redis.selectorLabels" . | nindent 6 }}
diff --git a/charts/redis/values.yaml b/charts/redis/values.yaml
index cc3839ad..d7803cbb 100644
--- a/charts/redis/values.yaml
+++ b/charts/redis/values.yaml
@@ -194,6 +194,9 @@ extraSentinelSecrets: []
     ## Mount path where the secret should be mounted into the container (f.e. /mysecretfolder)
 #    mountPath:
 
+## Use Kubernetes Deployment instead of StatefulSet when in Non-HA mode
+useDeploymentWhenNonHA: true
+
 ## High availability mode (with master-slave replication and sentinel)
 haMode:
   ## Enable high availibility deployment mode
-- 
GitLab