@@ -17,6 +17,7 @@ import (
1717 corev1 "k8s.io/api/core/v1"
1818 apiequality "k8s.io/apimachinery/pkg/api/equality"
1919 apierrors "k8s.io/apimachinery/pkg/api/errors"
20+ "k8s.io/apimachinery/pkg/api/resource"
2021 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2122 "k8s.io/apimachinery/pkg/labels"
2223)
@@ -28,6 +29,7 @@ const (
2829// statefulSetParameters will define statefulsets input params
2930type statefulSetParameters struct {
3031 Replicas * int32
32+ ClusterMode bool
3133 Metadata metav1.ObjectMeta
3234 NodeSelector map [string ]string
3335 PodSecurityContext * corev1.PodSecurityContext
@@ -241,6 +243,9 @@ func generateStatefulSetsDef(stsMeta metav1.ObjectMeta, params statefulSetParame
241243 if params .ImagePullSecrets != nil {
242244 statefulset .Spec .Template .Spec .ImagePullSecrets = * params .ImagePullSecrets
243245 }
246+ if containerParams .PersistenceEnabled != nil && params .ClusterMode {
247+ statefulset .Spec .VolumeClaimTemplates = append (statefulset .Spec .VolumeClaimTemplates , createPVCTemplateNodeConf (stsMeta ))
248+ }
244249 if containerParams .PersistenceEnabled != nil && * containerParams .PersistenceEnabled {
245250 statefulset .Spec .VolumeClaimTemplates = append (statefulset .Spec .VolumeClaimTemplates , createPVCTemplate (stsMeta , params .PersistentVolumeClaim ))
246251 }
@@ -295,6 +300,35 @@ func getExternalConfig(configMapName string) []corev1.Volume {
295300 }
296301}
297302
303+ // createPVCTemplate to store node.conf in durable manner
304+ func createPVCTemplateNodeConf (stsMeta metav1.ObjectMeta ) corev1.PersistentVolumeClaim {
305+ // 1Mb Resource requirement for the node.conf
306+ pvcNodeConf := corev1.PersistentVolumeClaim {
307+ ObjectMeta : metav1.ObjectMeta {
308+ Name : "node-conf" ,
309+ },
310+ Spec : corev1.PersistentVolumeClaimSpec {
311+ AccessModes : []corev1.PersistentVolumeAccessMode {
312+ corev1 .ReadWriteOnce ,
313+ },
314+ Resources : corev1.ResourceRequirements {
315+ Requests : corev1.ResourceList {
316+ corev1 .ResourceStorage : resource .MustParse ("1Mi" ),
317+ },
318+ },
319+ VolumeMode : func () * corev1.PersistentVolumeMode {
320+ volumeMode := corev1 .PersistentVolumeFilesystem
321+ return & volumeMode
322+ }(),
323+ },
324+ }
325+ // Load the labels from the statefulset
326+ pvcNodeConf .Labels = stsMeta .GetLabels ()
327+ // We want the same annoations as the StatefulSet here
328+ pvcNodeConf .Annotations = generateStatefulSetsAnots (stsMeta )
329+ return pvcNodeConf
330+ }
331+
298332// createPVCTemplate will create the persistent volume claim template
299333func createPVCTemplate (stsMeta metav1.ObjectMeta , storageSpec corev1.PersistentVolumeClaim ) corev1.PersistentVolumeClaim {
300334 pvcTemplate := storageSpec
@@ -339,7 +373,7 @@ func generateContainerDef(name string, containerParams containerParameters, enab
339373 ),
340374 ReadinessProbe : getProbeInfo (containerParams .ReadinessProbe ),
341375 LivenessProbe : getProbeInfo (containerParams .LivenessProbe ),
342- VolumeMounts : getVolumeMount (name , containerParams .PersistenceEnabled , externalConfig , mountpath , containerParams .TLSConfig , containerParams .ACLConfig ),
376+ VolumeMounts : getVolumeMount (name , containerParams .PersistenceEnabled , true , externalConfig , mountpath , containerParams .TLSConfig , containerParams .ACLConfig ),
343377 },
344378 }
345379
@@ -388,7 +422,7 @@ func generateInitContainerDef(name string, initcontainerParams initContainerPara
388422 ImagePullPolicy : initcontainerParams .ImagePullPolicy ,
389423 Command : initcontainerParams .Command ,
390424 Args : initcontainerParams .Arguments ,
391- VolumeMounts : getVolumeMount (name , initcontainerParams .PersistenceEnabled , nil , mountpath , nil , nil ),
425+ VolumeMounts : getVolumeMount (name , initcontainerParams .PersistenceEnabled , false , nil , mountpath , nil , nil ),
392426 },
393427 }
394428
@@ -458,7 +492,7 @@ func enableRedisMonitoring(params containerParameters) corev1.Container {
458492 params .TLSConfig ,
459493 params .ACLConfig ,
460494 ),
461- VolumeMounts : getVolumeMount ("" , nil , nil , params .AdditionalMountPath , params .TLSConfig , params .ACLConfig ), // We need/want the tls-certs but we DON'T need the PVC (if one is available)
495+ VolumeMounts : getVolumeMount ("" , nil , false , nil , params .AdditionalMountPath , params .TLSConfig , params .ACLConfig ), // We need/want the tls-certs but we DON'T need the PVC (if one is available)
462496 Ports : []corev1.ContainerPort {
463497 {
464498 Name : redisExporterPortName ,
@@ -474,9 +508,16 @@ func enableRedisMonitoring(params containerParameters) corev1.Container {
474508}
475509
476510// getVolumeMount gives information about persistence mount
477- func getVolumeMount (name string , persistenceEnabled * bool , externalConfig * string , mountpath []corev1.VolumeMount , tlsConfig * redisv1beta1.TLSConfig , aclConfig * redisv1beta1.ACLConfig ) []corev1.VolumeMount {
511+ func getVolumeMount (name string , persistenceEnabled * bool , cluster bool , externalConfig * string , mountpath []corev1.VolumeMount , tlsConfig * redisv1beta1.TLSConfig , aclConfig * redisv1beta1.ACLConfig ) []corev1.VolumeMount {
478512 var VolumeMounts []corev1.VolumeMount
479513
514+ if persistenceEnabled != nil && cluster {
515+ VolumeMounts = append (VolumeMounts , corev1.VolumeMount {
516+ Name : "node-conf" ,
517+ MountPath : "/node-conf" ,
518+ })
519+ }
520+
480521 if persistenceEnabled != nil && * persistenceEnabled {
481522 VolumeMounts = append (VolumeMounts , corev1.VolumeMount {
482523 Name : name ,
0 commit comments