Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support volumeCliamTemplates #61

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions api/redisfailover/v1alpha2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}
38 changes: 38 additions & 0 deletions example/redisfailover_pvc.yaml
Original file line number Diff line number Diff line change
@@ -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
22 changes: 13 additions & 9 deletions operator/redisfailover/service/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -202,6 +203,7 @@ func generateRedisStatefulSet(rf *redisfailoverv1alpha2.RedisFailover, labels ma
Volumes: volumes,
},
},
VolumeClaimTemplates: volumeClaimTemplates,
},
}

Expand Down Expand Up @@ -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
Expand All @@ -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{}
}