From d0feb86f77516c5896e22469155103659cced292 Mon Sep 17 00:00:00 2001 From: Julio Chana Date: Tue, 17 Jul 2018 16:55:52 +0200 Subject: [PATCH 1/8] [DEVOPS-785] Fix make update-codegen --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 627737950..34647c0a9 100644 --- a/Makefile +++ b/Makefile @@ -144,6 +144,6 @@ endif # Generate kubernetes code for types.. .PHONY: update-codegen -update-codegen: build +update-codegen: docker-build @echo ">> Generating code for Kubernetes CRD types..." docker run --rm -v $(PWD):/go/src/github.com/spotahome/redis-operator/ $(REPOSITORY)-dev /bin/bash -c '$(UPDATE_CODEGEN_CMD)' From f468f33828c4f37c7dbd17bf3ec96d2522b4bdbf Mon Sep 17 00:00:00 2001 From: Julio Chana Date: Tue, 17 Jul 2018 17:43:43 +0200 Subject: [PATCH 2/8] [DEVOPS-785] Improve Redis spec for storage --- api/redisfailover/v1alpha2/types.go | 8 ++++- .../v1alpha2/zz_generated.deepcopy.go | 36 ++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/api/redisfailover/v1alpha2/types.go b/api/redisfailover/v1alpha2/types.go index 7b1127397..efc8334db 100644 --- a/api/redisfailover/v1alpha2/types.go +++ b/api/redisfailover/v1alpha2/types.go @@ -43,7 +43,7 @@ type RedisSettings struct { Image string `json:"image,omitempty"` Version string `json:"version,omitempty"` ConfigMap string `json:"configMap,omitempty"` - DataVolume corev1.Volume `json:"dataVolume,omitempty"` + Storage RedisStorage `json:"storage,omitempty"` } // SentinelSettings defines the specification of the sentinel cluster @@ -65,6 +65,12 @@ type CPUAndMem struct { Memory string `json:"memory"` } +// RedisStorage defines the structure used to store the Redis Data +type RedisStorage struct { + EmptyDir *corev1.EmptyDirVolumeSource `json:"emptyDir,omitempty"` + PersistentVolumeClaim *corev1.PersistentVolumeClaim `json:"persistentVolumeClaim,omitempty"` +} + // RedisFailoverStatus has the status of the cluster type RedisFailoverStatus struct { Phase Phase `json:"phase"` diff --git a/api/redisfailover/v1alpha2/zz_generated.deepcopy.go b/api/redisfailover/v1alpha2/zz_generated.deepcopy.go index 6794f35b5..765094c86 100644 --- a/api/redisfailover/v1alpha2/zz_generated.deepcopy.go +++ b/api/redisfailover/v1alpha2/zz_generated.deepcopy.go @@ -188,7 +188,7 @@ func (in *RedisFailoverStatus) DeepCopy() *RedisFailoverStatus { func (in *RedisSettings) DeepCopyInto(out *RedisSettings) { *out = *in out.Resources = in.Resources - in.DataVolume.DeepCopyInto(&out.DataVolume) + in.Storage.DeepCopyInto(&out.Storage) return } @@ -202,6 +202,40 @@ func (in *RedisSettings) DeepCopy() *RedisSettings { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RedisStorage) DeepCopyInto(out *RedisStorage) { + *out = *in + if in.EmptyDir != nil { + in, out := &in.EmptyDir, &out.EmptyDir + if *in == nil { + *out = nil + } else { + *out = new(v1.EmptyDirVolumeSource) + (*in).DeepCopyInto(*out) + } + } + if in.PersistentVolumeClaim != nil { + in, out := &in.PersistentVolumeClaim, &out.PersistentVolumeClaim + if *in == nil { + *out = nil + } else { + *out = new(v1.PersistentVolumeClaim) + (*in).DeepCopyInto(*out) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RedisStorage. +func (in *RedisStorage) DeepCopy() *RedisStorage { + if in == nil { + return nil + } + out := new(RedisStorage) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *SentinelSettings) DeepCopyInto(out *SentinelSettings) { *out = *in From 3c5fb90e1dc8fb4fd8f187c71550cb78ca135d65 Mon Sep 17 00:00:00 2001 From: Julio Chana Date: Wed, 18 Jul 2018 12:38:34 +0200 Subject: [PATCH 3/8] [DEVOPS-785] Only add volume when needed --- operator/redisfailover/service/generator.go | 65 +++++++++++++++++---- 1 file changed, 53 insertions(+), 12 deletions(-) diff --git a/operator/redisfailover/service/generator.go b/operator/redisfailover/service/generator.go index 0035a9757..8dd30035d 100644 --- a/operator/redisfailover/service/generator.go +++ b/operator/redisfailover/service/generator.go @@ -14,6 +14,11 @@ import ( "github.com/spotahome/redis-operator/operator/redisfailover/util" ) +const ( + redisConfigurationVolumeName = "redis-config" + redisStorageVolumeName = "redis-data" +) + func generateSentinelService(rf *redisfailoverv1alpha2.RedisFailover, labels map[string]string, ownerRefs []metav1.OwnerReference) *corev1.Service { name := GetSentinelName(rf) namespace := rf.Namespace @@ -205,6 +210,12 @@ func generateRedisStatefulSet(rf *redisfailoverv1alpha2.RedisFailover, labels ma }, } + if rf.Spec.Redis.Storage.PersistentVolumeClaim != nil { + ss.Spec.VolumeClaimTemplates = []corev1.PersistentVolumeClaim{ + *rf.Spec.Redis.Storage.PersistentVolumeClaim, + } + } + if rf.Spec.Redis.Exporter { exporter := createRedisExporterContainer(rf) ss.Spec.Template.Spec.Containers = append(ss.Spec.Template.Spec.Containers, exporter) @@ -523,17 +534,13 @@ func getRedisExporterImage(rf *redisfailoverv1alpha2.RedisFailover) string { func getRedisVolumeMounts(rf *redisfailoverv1alpha2.RedisFailover) []corev1.VolumeMount { volumeMounts := []corev1.VolumeMount{ { - Name: "redis-config", + Name: redisConfigurationVolumeName, MountPath: "/redis", }, - } - - // check if data volume is set, if set, mount to /data - if rf.Spec.Redis.DataVolume.Name != "" { - volumeMounts = append(volumeMounts, corev1.VolumeMount{ - Name: rf.Spec.Redis.DataVolume.Name, + { + Name: getRedisDataVolumeName(rf), MountPath: "/data", - }) + }, } return volumeMounts @@ -544,7 +551,7 @@ func getRedisVolumes(rf *redisfailoverv1alpha2.RedisFailover) []corev1.Volume { volumes := []corev1.Volume{ { - Name: "redis-config", + Name: redisConfigurationVolumeName, VolumeSource: corev1.VolumeSource{ ConfigMap: &corev1.ConfigMapVolumeSource{ LocalObjectReference: corev1.LocalObjectReference{ @@ -555,10 +562,44 @@ func getRedisVolumes(rf *redisfailoverv1alpha2.RedisFailover) []corev1.Volume { }, } - // check if data volume is set, if not set skip it - if rf.Spec.Redis.DataVolume.Name != "" { - volumes = append(volumes, rf.Spec.Redis.DataVolume) + dataVolume := getRedisDataVolume(rf) + if dataVolume != nil { + volumes = append(volumes, *dataVolume) } return volumes } + +func getRedisDataVolume(rf *redisfailoverv1alpha2.RedisFailover) *corev1.Volume { + // This will find the volumed desired by the user. If no volume defined + // an EmptyDir will be used by default + switch { + case rf.Spec.Redis.Storage.PersistentVolumeClaim != nil: + return nil + case rf.Spec.Redis.Storage.EmptyDir != nil: + return &corev1.Volume{ + Name: redisStorageVolumeName, + VolumeSource: corev1.VolumeSource{ + EmptyDir: rf.Spec.Redis.Storage.EmptyDir, + }, + } + default: + return &corev1.Volume{ + Name: redisStorageVolumeName, + VolumeSource: corev1.VolumeSource{ + EmptyDir: &corev1.EmptyDirVolumeSource{}, + }, + } + } +} + +func getRedisDataVolumeName(rf *redisfailoverv1alpha2.RedisFailover) string { + switch { + case rf.Spec.Redis.Storage.PersistentVolumeClaim != nil: + return rf.Spec.Redis.Storage.PersistentVolumeClaim.Name + case rf.Spec.Redis.Storage.EmptyDir != nil: + return redisStorageVolumeName + default: + return redisStorageVolumeName + } +} From 21fff9b56f81deddf5884334e86b76d096a6a6a6 Mon Sep 17 00:00:00 2001 From: Julio Chana Date: Wed, 18 Jul 2018 12:38:53 +0200 Subject: [PATCH 4/8] [DEVOPS-785] Add tests on Redis StatefulSet generation --- .../redisfailover/service/generator_test.go | 218 ++++++++++++++++++ 1 file changed, 218 insertions(+) create mode 100644 operator/redisfailover/service/generator_test.go diff --git a/operator/redisfailover/service/generator_test.go b/operator/redisfailover/service/generator_test.go new file mode 100644 index 000000000..22ca3c72d --- /dev/null +++ b/operator/redisfailover/service/generator_test.go @@ -0,0 +1,218 @@ +package service_test + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" + appsv1beta2 "k8s.io/api/apps/v1beta2" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + redisfailoverv1alpha2 "github.com/spotahome/redis-operator/api/redisfailover/v1alpha2" + "github.com/spotahome/redis-operator/log" + mK8SService "github.com/spotahome/redis-operator/mocks/service/k8s" + rfservice "github.com/spotahome/redis-operator/operator/redisfailover/service" +) + +func TestRedisStatefulSetStorageGeneration(t *testing.T) { + configMapName := rfservice.GetRedisConfigMapName(generateRF()) + tests := []struct { + name string + expectedSS appsv1beta2.StatefulSet + rfRedisStorage redisfailoverv1alpha2.RedisStorage + }{ + { + name: "Default values", + expectedSS: appsv1beta2.StatefulSet{ + Spec: appsv1beta2.StatefulSetSpec{ + Template: corev1.PodTemplateSpec{ + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + VolumeMounts: []corev1.VolumeMount{ + { + Name: "redis-config", + MountPath: "/redis", + }, + { + Name: "redis-data", + MountPath: "/data", + }, + }, + }, + }, + Volumes: []corev1.Volume{ + { + Name: "redis-config", + VolumeSource: corev1.VolumeSource{ + ConfigMap: &corev1.ConfigMapVolumeSource{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: configMapName, + }, + }, + }, + }, + { + Name: "redis-data", + VolumeSource: corev1.VolumeSource{ + EmptyDir: &corev1.EmptyDirVolumeSource{}, + }, + }, + }, + }, + }, + }, + }, + rfRedisStorage: redisfailoverv1alpha2.RedisStorage{}, + }, + { + name: "Defined an emptydir with storage on memory", + expectedSS: appsv1beta2.StatefulSet{ + Spec: appsv1beta2.StatefulSetSpec{ + Template: corev1.PodTemplateSpec{ + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + VolumeMounts: []corev1.VolumeMount{ + { + Name: "redis-config", + MountPath: "/redis", + }, + { + Name: "redis-data", + MountPath: "/data", + }, + }, + }, + }, + Volumes: []corev1.Volume{ + { + Name: "redis-config", + VolumeSource: corev1.VolumeSource{ + ConfigMap: &corev1.ConfigMapVolumeSource{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: configMapName, + }, + }, + }, + }, + { + Name: "redis-data", + VolumeSource: corev1.VolumeSource{ + EmptyDir: &corev1.EmptyDirVolumeSource{ + Medium: corev1.StorageMediumMemory, + }, + }, + }, + }, + }, + }, + }, + }, + rfRedisStorage: redisfailoverv1alpha2.RedisStorage{ + EmptyDir: &corev1.EmptyDirVolumeSource{ + Medium: corev1.StorageMediumMemory, + }, + }, + }, + { + name: "Defined an persistentvolumeclaim", + expectedSS: appsv1beta2.StatefulSet{ + Spec: appsv1beta2.StatefulSetSpec{ + Template: corev1.PodTemplateSpec{ + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + VolumeMounts: []corev1.VolumeMount{ + { + Name: "redis-config", + MountPath: "/redis", + }, + { + Name: "pvc-data", + MountPath: "/data", + }, + }, + }, + }, + Volumes: []corev1.Volume{ + { + Name: "redis-config", + VolumeSource: corev1.VolumeSource{ + ConfigMap: &corev1.ConfigMapVolumeSource{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: configMapName, + }, + }, + }, + }, + }, + }, + }, + VolumeClaimTemplates: []corev1.PersistentVolumeClaim{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pvc-data", + }, + Spec: corev1.PersistentVolumeClaimSpec{ + AccessModes: []corev1.PersistentVolumeAccessMode{ + "ReadWriteOnce", + }, + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceStorage: resource.MustParse("1Gi"), + }, + }, + }, + }, + }, + }, + }, + rfRedisStorage: redisfailoverv1alpha2.RedisStorage{ + PersistentVolumeClaim: &corev1.PersistentVolumeClaim{ + ObjectMeta: metav1.ObjectMeta{ + Name: "pvc-data", + }, + Spec: corev1.PersistentVolumeClaimSpec{ + AccessModes: []corev1.PersistentVolumeAccessMode{ + "ReadWriteOnce", + }, + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceStorage: resource.MustParse("1Gi"), + }, + }, + }, + }, + }, + }, + } + + for _, test := range tests { + assert := assert.New(t) + + // Generate a default RedisFailover and attaching the required storage + rf := generateRF() + rf.Spec.Redis.Storage = test.rfRedisStorage + + generatedStatefulSet := appsv1beta2.StatefulSet{} + + ms := &mK8SService.Services{} + ms.On("CreateOrUpdatePodDisruptionBudget", namespace, mock.Anything).Once().Return(nil, nil) + ms.On("CreateOrUpdateStatefulSet", namespace, mock.Anything).Once().Run(func(args mock.Arguments) { + ss := args.Get(1).(*appsv1beta2.StatefulSet) + generatedStatefulSet = *ss + }).Return(nil) + + client := rfservice.NewRedisFailoverKubeClient(ms, log.Dummy) + err := client.EnsureRedisStatefulset(rf, map[string]string{}, []metav1.OwnerReference{}) + + // Check that the storage-related fields are as spected + assert.Equal(test.expectedSS.Spec.Template.Spec.Volumes, generatedStatefulSet.Spec.Template.Spec.Volumes) + assert.Equal(test.expectedSS.Spec.Template.Spec.Containers[0].VolumeMounts, generatedStatefulSet.Spec.Template.Spec.Containers[0].VolumeMounts) + assert.Equal(test.expectedSS.Spec.VolumeClaimTemplates, generatedStatefulSet.Spec.VolumeClaimTemplates) + assert.NoError(err) + } +} From 4bf125ebd31b9ee5860a779670fea399cc386496 Mon Sep 17 00:00:00 2001 From: Julio Chana Date: Wed, 18 Jul 2018 13:28:56 +0200 Subject: [PATCH 5/8] [DEVOPS-785] Add autodeletion of PVC. Allow keeping them --- api/redisfailover/v1alpha2/types.go | 1 + operator/redisfailover/service/generator.go | 4 + .../redisfailover/service/generator_test.go | 161 +++++++++++++++++- 3 files changed, 165 insertions(+), 1 deletion(-) diff --git a/api/redisfailover/v1alpha2/types.go b/api/redisfailover/v1alpha2/types.go index efc8334db..4d2aff8a9 100644 --- a/api/redisfailover/v1alpha2/types.go +++ b/api/redisfailover/v1alpha2/types.go @@ -67,6 +67,7 @@ type CPUAndMem struct { // RedisStorage defines the structure used to store the Redis Data type RedisStorage struct { + KeepAfterDeletion bool `json:"keepAfterDeletion,omitempty"` EmptyDir *corev1.EmptyDirVolumeSource `json:"emptyDir,omitempty"` PersistentVolumeClaim *corev1.PersistentVolumeClaim `json:"persistentVolumeClaim,omitempty"` } diff --git a/operator/redisfailover/service/generator.go b/operator/redisfailover/service/generator.go index 8dd30035d..2a7febc21 100644 --- a/operator/redisfailover/service/generator.go +++ b/operator/redisfailover/service/generator.go @@ -211,6 +211,10 @@ func generateRedisStatefulSet(rf *redisfailoverv1alpha2.RedisFailover, labels ma } if rf.Spec.Redis.Storage.PersistentVolumeClaim != nil { + if !rf.Spec.Redis.Storage.KeepAfterDeletion { + // Set an owner reference so the persistent volumes are deleted when the RF is + rf.Spec.Redis.Storage.PersistentVolumeClaim.OwnerReferences = ownerRefs + } ss.Spec.VolumeClaimTemplates = []corev1.PersistentVolumeClaim{ *rf.Spec.Redis.Storage.PersistentVolumeClaim, } diff --git a/operator/redisfailover/service/generator_test.go b/operator/redisfailover/service/generator_test.go index 22ca3c72d..826587606 100644 --- a/operator/redisfailover/service/generator_test.go +++ b/operator/redisfailover/service/generator_test.go @@ -20,6 +20,7 @@ func TestRedisStatefulSetStorageGeneration(t *testing.T) { configMapName := rfservice.GetRedisConfigMapName(generateRF()) tests := []struct { name string + ownerRefs []metav1.OwnerReference expectedSS appsv1beta2.StatefulSet rfRedisStorage redisfailoverv1alpha2.RedisStorage }{ @@ -188,6 +189,164 @@ func TestRedisStatefulSetStorageGeneration(t *testing.T) { }, }, }, + { + name: "Defined an persistentvolumeclaim with ownerRefs", + ownerRefs: []metav1.OwnerReference{ + { + Name: "testing", + }, + }, + expectedSS: appsv1beta2.StatefulSet{ + Spec: appsv1beta2.StatefulSetSpec{ + Template: corev1.PodTemplateSpec{ + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + VolumeMounts: []corev1.VolumeMount{ + { + Name: "redis-config", + MountPath: "/redis", + }, + { + Name: "pvc-data", + MountPath: "/data", + }, + }, + }, + }, + Volumes: []corev1.Volume{ + { + Name: "redis-config", + VolumeSource: corev1.VolumeSource{ + ConfigMap: &corev1.ConfigMapVolumeSource{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: configMapName, + }, + }, + }, + }, + }, + }, + }, + VolumeClaimTemplates: []corev1.PersistentVolumeClaim{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pvc-data", + OwnerReferences: []metav1.OwnerReference{ + { + Name: "testing", + }, + }, + }, + Spec: corev1.PersistentVolumeClaimSpec{ + AccessModes: []corev1.PersistentVolumeAccessMode{ + "ReadWriteOnce", + }, + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceStorage: resource.MustParse("1Gi"), + }, + }, + }, + }, + }, + }, + }, + rfRedisStorage: redisfailoverv1alpha2.RedisStorage{ + PersistentVolumeClaim: &corev1.PersistentVolumeClaim{ + ObjectMeta: metav1.ObjectMeta{ + Name: "pvc-data", + }, + Spec: corev1.PersistentVolumeClaimSpec{ + AccessModes: []corev1.PersistentVolumeAccessMode{ + "ReadWriteOnce", + }, + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceStorage: resource.MustParse("1Gi"), + }, + }, + }, + }, + }, + }, + { + name: "Defined an persistentvolumeclaim with ownerRefs keeping the pvc", + ownerRefs: []metav1.OwnerReference{ + { + Name: "testing", + }, + }, + expectedSS: appsv1beta2.StatefulSet{ + Spec: appsv1beta2.StatefulSetSpec{ + Template: corev1.PodTemplateSpec{ + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + VolumeMounts: []corev1.VolumeMount{ + { + Name: "redis-config", + MountPath: "/redis", + }, + { + Name: "pvc-data", + MountPath: "/data", + }, + }, + }, + }, + Volumes: []corev1.Volume{ + { + Name: "redis-config", + VolumeSource: corev1.VolumeSource{ + ConfigMap: &corev1.ConfigMapVolumeSource{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: configMapName, + }, + }, + }, + }, + }, + }, + }, + VolumeClaimTemplates: []corev1.PersistentVolumeClaim{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pvc-data", + }, + Spec: corev1.PersistentVolumeClaimSpec{ + AccessModes: []corev1.PersistentVolumeAccessMode{ + "ReadWriteOnce", + }, + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceStorage: resource.MustParse("1Gi"), + }, + }, + }, + }, + }, + }, + }, + rfRedisStorage: redisfailoverv1alpha2.RedisStorage{ + KeepAfterDeletion: true, + PersistentVolumeClaim: &corev1.PersistentVolumeClaim{ + ObjectMeta: metav1.ObjectMeta{ + Name: "pvc-data", + }, + Spec: corev1.PersistentVolumeClaimSpec{ + AccessModes: []corev1.PersistentVolumeAccessMode{ + "ReadWriteOnce", + }, + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceStorage: resource.MustParse("1Gi"), + }, + }, + }, + }, + }, + }, } for _, test := range tests { @@ -207,7 +366,7 @@ func TestRedisStatefulSetStorageGeneration(t *testing.T) { }).Return(nil) client := rfservice.NewRedisFailoverKubeClient(ms, log.Dummy) - err := client.EnsureRedisStatefulset(rf, map[string]string{}, []metav1.OwnerReference{}) + err := client.EnsureRedisStatefulset(rf, nil, test.ownerRefs) // Check that the storage-related fields are as spected assert.Equal(test.expectedSS.Spec.Template.Spec.Volumes, generatedStatefulSet.Spec.Template.Spec.Volumes) From f6810ee5c7e7ed5a083ab5f3b7403c01090abfc2 Mon Sep 17 00:00:00 2001 From: Julio Chana Date: Wed, 18 Jul 2018 13:29:13 +0200 Subject: [PATCH 6/8] [DEVOPS-785] Reorganize example yamls --- example/{ => operator}/operator.yaml | 0 example/{ => operator}/rolebinding.yaml | 0 example/{ => operator}/roles.yaml | 0 example/{ => operator}/serviceaccount.yaml | 0 .../all-options.yaml} | 6 +++--- example/{ => redisfailover}/minimum.yaml | 0 .../persistant-storage-no-pvc-deletion.yaml | 21 +++++++++++++++++++ example/redisfailover/persistant-storage.yaml | 20 ++++++++++++++++++ 8 files changed, 44 insertions(+), 3 deletions(-) rename example/{ => operator}/operator.yaml (100%) rename example/{ => operator}/rolebinding.yaml (100%) rename example/{ => operator}/roles.yaml (100%) rename example/{ => operator}/serviceaccount.yaml (100%) rename example/{redisfailover.yaml => redisfailover/all-options.yaml} (93%) rename example/{ => redisfailover}/minimum.yaml (100%) create mode 100644 example/redisfailover/persistant-storage-no-pvc-deletion.yaml create mode 100644 example/redisfailover/persistant-storage.yaml diff --git a/example/operator.yaml b/example/operator/operator.yaml similarity index 100% rename from example/operator.yaml rename to example/operator/operator.yaml diff --git a/example/rolebinding.yaml b/example/operator/rolebinding.yaml similarity index 100% rename from example/rolebinding.yaml rename to example/operator/rolebinding.yaml diff --git a/example/roles.yaml b/example/operator/roles.yaml similarity index 100% rename from example/roles.yaml rename to example/operator/roles.yaml diff --git a/example/serviceaccount.yaml b/example/operator/serviceaccount.yaml similarity index 100% rename from example/serviceaccount.yaml rename to example/operator/serviceaccount.yaml diff --git a/example/redisfailover.yaml b/example/redisfailover/all-options.yaml similarity index 93% rename from example/redisfailover.yaml rename to example/redisfailover/all-options.yaml index bb21aad70..2c4785340 100644 --- a/example/redisfailover.yaml +++ b/example/redisfailover/all-options.yaml @@ -25,6 +25,6 @@ spec: exporter: false # Optional. False by default. Adds a redis-exporter container to export metrics. exporterImage: oliver006/redis_exporter # Optional. oliver006/redis_exporter by default. exporterVersion: v0.11.3 # Optional. v0.11.3 by default. - dataVolume: - name: redis-data - emptyDir: {} + storage: + emptyDir: {} # Optional. emptyDir by default. + diff --git a/example/minimum.yaml b/example/redisfailover/minimum.yaml similarity index 100% rename from example/minimum.yaml rename to example/redisfailover/minimum.yaml diff --git a/example/redisfailover/persistant-storage-no-pvc-deletion.yaml b/example/redisfailover/persistant-storage-no-pvc-deletion.yaml new file mode 100644 index 000000000..98aca799c --- /dev/null +++ b/example/redisfailover/persistant-storage-no-pvc-deletion.yaml @@ -0,0 +1,21 @@ +apiVersion: storage.spotahome.com/v1alpha2 +kind: RedisFailover +metadata: + name: redisfailover-persistant-keep +spec: + sentinel: + replicas: 3 + redis: + replicas: 3 + storage: + keepAfterDeletion: true + persistentVolumeClaim: + metadata: + name: redisfailover-persistant-keep-data + spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi + diff --git a/example/redisfailover/persistant-storage.yaml b/example/redisfailover/persistant-storage.yaml new file mode 100644 index 000000000..e327a60b7 --- /dev/null +++ b/example/redisfailover/persistant-storage.yaml @@ -0,0 +1,20 @@ +apiVersion: storage.spotahome.com/v1alpha2 +kind: RedisFailover +metadata: + name: redisfailover-persistant +spec: + sentinel: + replicas: 3 + redis: + replicas: 3 + storage: + persistentVolumeClaim: + metadata: + name: redisfailover-persistant-data + spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi + From e4a39d83c081566accee300775f6fd3ca54b5448 Mon Sep 17 00:00:00 2001 From: Julio Chana Date: Wed, 18 Jul 2018 13:37:46 +0200 Subject: [PATCH 7/8] [DEVOPS-785] Add persistance section to README.md --- README.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a801023dd..0e4acbde6 100644 --- a/README.md +++ b/README.md @@ -36,9 +36,9 @@ helm install --name redisfailover charts/redisoperator ## Usage Once the operator is deployed inside a Kubernetes cluster, a new API will be accesible, so you'll be able to create, update and delete redisfailovers. -In order to deploy a new redis-failover a [specification](example/redisfailover.yaml) has to be created: +In order to deploy a new redis-failover a [specification](example/redisfailover/all-options.yaml) has to be created: ``` -kubectl create -f https://raw.githubusercontent.com/spotahome/redis-operator/master/example/redisfailover.yaml +kubectl create -f https://raw.githubusercontent.com/spotahome/redis-operator/master/redisfailover/all-options.yaml ``` This redis-failover will be managed by the operator, resulting in the following elements created inside Kubernetes: @@ -51,6 +51,13 @@ This redis-failover will be managed by the operator, resulting in the following **NOTE**: `NAME` is the named provided when creating the RedisFailover. +### Persistance +The operator has the ability of add persistance to Redis data. By default an `emptyDir` will be used, so the data is not saved. + +In order to have persistance, a PersistentVolumeClaim usage is allowed. The full [PVC definition has to be added](example/redisfailover/persistant-storage.yaml) to the Redis Failover Spec under the `Storage` section. + +**IMPORTANT**: By default, the persistent volume claims will be deleted when the Redis Failover is. If this is not the expected usage, a `keepAfterDeletion` flag can be added under the `storage` section of Redis. [An example is given](example/redisfailover/persistant-storage-no-pvc-deletion.yaml). + ### Connection 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. The connection parameters are the following: From 5f32d56fa8885003e023ca23a4c5ec19eab0a340 Mon Sep 17 00:00:00 2001 From: Julio Chana Date: Wed, 18 Jul 2018 13:38:13 +0200 Subject: [PATCH 8/8] [DEVOPS-785] Bump version to 0.4.0 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 34647c0a9..b058162b2 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION := 0.3.0 +VERSION := 0.4.0 # Name of this service/application SERVICE_NAME := redis-operator