From 432f1748584d75aeed2bf27e413203521a059067 Mon Sep 17 00:00:00 2001 From: Samuel Vijaykumar M Date: Fri, 2 Sep 2022 12:42:08 +0530 Subject: [PATCH] Add extravolumes and extravolumemounts --- README.md | 31 +++++++++++++++++++ api/redisfailover/v1/types.go | 2 ++ .../redisfailover/extravolumes-mounts.yaml | 18 +++++++++++ operator/redisfailover/service/generator.go | 8 +++++ 4 files changed, 59 insertions(+) create mode 100644 example/redisfailover/extravolumes-mounts.yaml diff --git a/README.md b/README.md index 2a979d951..c31eb8b9e 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,37 @@ app.kubernetes.io/part-of redisfailovers.databases.spotahome.com/name ``` + +### ExtraVolumes and ExtraVolumeMounts + +If the user choose to have extra volumes creates and mounted, he could use the `extraVolumes` and `extraVolumeMounts`, in `spec.redis` of the CRD. This allows users to mount the extra configurations, or secrets to be used. A typical use case for this might be +- Secrets that sidecars might use to backup of RDBs +- Extra users and their secrets and acls that could used the initContainers to create multiple users +- Extra Configurations that could merge on top the existing configurations + +``` +apiVersion: databases.spotahome.com/v1 +kind: RedisFailover +metadata: + name: redisfailover +spec: + sentinel: + replicas: 3 + redis: + replicas: 3 + extraVolumes: + - name: foo_user + secret: + secretName: mysecret + optional: false + exraVolumeMounts: + - name: foo + mountPath: "/etc/foo" + readOnly: true +``` + + + ## Connection to the created Redis Failovers In order to connect to the redis-failover and use it, a [Sentinel-ready](https://redis.io/topics/sentinel-clients) library has to be used. This will connect through the Sentinel service to the Redis node working as a master. diff --git a/api/redisfailover/v1/types.go b/api/redisfailover/v1/types.go index b10de26eb..12c7b8674 100644 --- a/api/redisfailover/v1/types.go +++ b/api/redisfailover/v1/types.go @@ -64,6 +64,8 @@ type RedisSettings struct { PriorityClassName string `json:"priorityClassName,omitempty"` ServiceAccountName string `json:"serviceAccountName,omitempty"` TerminationGracePeriodSeconds int64 `json:"terminationGracePeriod,omitempty"` + ExtraVolumes []corev1.Volume `json:"extraVolumes,omitempty"` + ExtraVolumeMounts []corev1.VolumeMount `json:"extraVolumeMounts,omitempty"` } // SentinelSettings defines the specification of the sentinel cluster diff --git a/example/redisfailover/extravolumes-mounts.yaml b/example/redisfailover/extravolumes-mounts.yaml new file mode 100644 index 000000000..e3c7bc6f1 --- /dev/null +++ b/example/redisfailover/extravolumes-mounts.yaml @@ -0,0 +1,18 @@ +apiVersion: databases.spotahome.com/v1 +kind: RedisFailover +metadata: + name: redisfailover +spec: + sentinel: + replicas: 3 + redis: + replicas: 3 + extraVolumes: + - name: foo_user + secret: + secretName: mysecret + optional: false + exraVolumeMounts: + - name: foo + mountPath: "/etc/foo" + readOnly: true \ No newline at end of file diff --git a/operator/redisfailover/service/generator.go b/operator/redisfailover/service/generator.go index 4ad5fab6d..ce6081d8e 100644 --- a/operator/redisfailover/service/generator.go +++ b/operator/redisfailover/service/generator.go @@ -781,6 +781,10 @@ func getRedisVolumeMounts(rf *redisfailoverv1.RedisFailover) []corev1.VolumeMoun }, } + if rf.Spec.Redis.ExtraVolumeMounts != nil { + volumeMounts = append(volumeMounts, rf.Spec.Redis.ExtraVolumeMounts...) + } + return volumeMounts } @@ -830,6 +834,10 @@ func getRedisVolumes(rf *redisfailoverv1.RedisFailover) []corev1.Volume { volumes = append(volumes, *dataVolume) } + if rf.Spec.Redis.ExtraVolumes != nil { + volumes = append(volumes, rf.Spec.Redis.ExtraVolumes...) + } + return volumes }