From 1dcc171948996c0f85dcbb1e465fd89fd010e13f Mon Sep 17 00:00:00 2001 From: "Chen.Zhidong" Date: Tue, 29 May 2018 14:46:46 +0800 Subject: [PATCH 1/2] add volumes, volumeMounts, volumeClainTemplates remove dataVolume --- api/redisfailover/v1alpha2/types.go | 20 ++++++++++--------- operator/redisfailover/service/generator.go | 22 ++++++++++++--------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/api/redisfailover/v1alpha2/types.go b/api/redisfailover/v1alpha2/types.go index 7b1127397..5421f7472 100644 --- a/api/redisfailover/v1alpha2/types.go +++ b/api/redisfailover/v1alpha2/types.go @@ -35,15 +35,17 @@ type RedisFailoverSpec struct { // RedisSettings defines the specification of the redis cluster type RedisSettings struct { - Replicas int32 `json:"replicas,omitempty"` - Resources RedisFailoverResources `json:"resources,omitempty"` - Exporter bool `json:"exporter,omitempty"` - ExporterImage string `json:"exporterImage,omitempty"` - ExporterVersion string `json:"exporterVersion,omitempty"` - Image string `json:"image,omitempty"` - Version string `json:"version,omitempty"` - ConfigMap string `json:"configMap,omitempty"` - DataVolume corev1.Volume `json:"dataVolume,omitempty"` + Replicas int32 `json:"replicas,omitempty"` + Resources RedisFailoverResources `json:"resources,omitempty"` + Exporter bool `json:"exporter,omitempty"` + ExporterImage string `json:"exporterImage,omitempty"` + ExporterVersion string `json:"exporterVersion,omitempty"` + Image string `json:"image,omitempty"` + Version string `json:"version,omitempty"` + ConfigMap string `json:"configMap,omitempty"` + VolumeMounts []corev1.VolumeMount `json:"volumeMounts,omitempty"` + Volumes []corev1.Volume `json:"volumes,omitempty"` + VolumeClaimTemplates []corev1.PersistentVolumeClaim `json:"volumeClaimTemplates,omitempty"` } // SentinelSettings defines the specification of the sentinel cluster diff --git a/operator/redisfailover/service/generator.go b/operator/redisfailover/service/generator.go index 0035a9757..25f4df93f 100644 --- a/operator/redisfailover/service/generator.go +++ b/operator/redisfailover/service/generator.go @@ -127,6 +127,7 @@ func generateRedisStatefulSet(rf *redisfailoverv1alpha2.RedisFailover, labels ma labels = util.MergeLabels(labels, generateLabels(redisRoleName, rf.Name)) volumeMounts := getRedisVolumeMounts(rf) volumes := getRedisVolumes(rf) + volumeClaimTemplates := getRedisVolumeClaimTemplates(rf) ss := &appsv1beta2.StatefulSet{ ObjectMeta: metav1.ObjectMeta{ @@ -202,6 +203,7 @@ func generateRedisStatefulSet(rf *redisfailoverv1alpha2.RedisFailover, labels ma Volumes: volumes, }, }, + VolumeClaimTemplates: volumeClaimTemplates, }, } @@ -528,12 +530,8 @@ func getRedisVolumeMounts(rf *redisfailoverv1alpha2.RedisFailover) []corev1.Volu }, } - // 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, - MountPath: "/data", - }) + if len(rf.Spec.Redis.VolumeMounts) > 0 { + volumeMounts = append(volumeMounts, rf.Spec.Redis.VolumeMounts...) } return volumeMounts @@ -555,10 +553,16 @@ 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) + if len(rf.Spec.Redis.Volumes) > 0 { + volumes = append(volumes, rf.Spec.Redis.Volumes...) } return volumes } + +func getRedisVolumeClaimTemplates(rf *redisfailoverv1alpha2.RedisFailover) []corev1.PersistentVolumeClaim { + if len(rf.Spec.Redis.VolumeClaimTemplates) > 0 { + return rf.Spec.Redis.VolumeClaimTemplates + } + return []corev1.PersistentVolumeClaim{} +} From de06e4e260f05176e78eab97f9bbe68a0150e5a5 Mon Sep 17 00:00:00 2001 From: "Chen.Zhidong" Date: Tue, 29 May 2018 15:10:24 +0800 Subject: [PATCH 2/2] update example --- ...lover.yaml => redisfailover_emptydir.yaml} | 9 +++-- example/redisfailover_pvc.yaml | 38 +++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) rename example/{redisfailover.yaml => redisfailover_emptydir.yaml} (90%) create mode 100644 example/redisfailover_pvc.yaml diff --git a/example/redisfailover.yaml b/example/redisfailover_emptydir.yaml similarity index 90% rename from example/redisfailover.yaml rename to example/redisfailover_emptydir.yaml index bb21aad70..968eae23a 100644 --- a/example/redisfailover.yaml +++ b/example/redisfailover_emptydir.yaml @@ -25,6 +25,9 @@ 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: {} + volumeMounts: + - name: redis-data + mountPath: "/data" + volumes: + - name: redis-data + emptyDir: {} diff --git a/example/redisfailover_pvc.yaml b/example/redisfailover_pvc.yaml new file mode 100644 index 000000000..dbbf05a2e --- /dev/null +++ b/example/redisfailover_pvc.yaml @@ -0,0 +1,38 @@ +apiVersion: storage.spotahome.com/v1alpha2 +kind: RedisFailover +metadata: + name: redisfailover +spec: + hardAntiAffinity: false # Optional. Value by default. If true, the pods will not be scheduled on the same node. + sentinel: + replicas: 3 # Optional. 3 by default, can be set higher. + resources: # Optional. If not set, it won't be defined on created reosurces. + requests: + cpu: 100m + limits: + memory: 100Mi + redis: + replicas: 3 # Optional. 3 by default, can be set higher. + image: redis # Optional. "redis" by default. + version: 3.2-alpine # Optional. "3.2-alpine" by default. + resources: # Optional. If not set, it won't be defined on created reosurces + requests: + cpu: 100m + memory: 100Mi + limits: + cpu: 400m + memory: 500Mi + 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. + volumeMounts: + - name: redis-data + mountPath: "/data" + volumeClaimTemplates: + - metadata: + name: redis-data + spec: + accessModes: [ "ReadWriteOnce" ] + resources: + requests: + storage: 1Gi