Skip to content

Commit

Permalink
Fix hard code of 1Mi (#552)
Browse files Browse the repository at this point in the history
Signed-off-by: Shubham Gupta <[email protected]>
  • Loading branch information
shubham-cmyk authored Jul 11, 2023
1 parent 8e854cb commit 4e21093
Show file tree
Hide file tree
Showing 23 changed files with 429 additions and 41 deletions.
7 changes: 7 additions & 0 deletions api/v1beta1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ type Storage struct {
VolumeMount AdditionalVolume `json:"volumeMount,omitempty"`
}

// Node-conf needs to be added only in redis cluster
type ClusterStorage struct {
VolumeClaimTemplate corev1.PersistentVolumeClaim `json:"volumeClaimTemplate,omitempty"`
NodeConfVolumeClaimTemplate corev1.PersistentVolumeClaim `json:"nodeConfVolumeClaimTemplate,omitempty"`
VolumeMount AdditionalVolume `json:"volumeMount,omitempty"`
}

// Additional Volume is provided by user that is mounted on the pods
type AdditionalVolume struct {
Volume []corev1.Volume `json:"volume,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion api/v1beta1/rediscluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type RedisClusterSpec struct {
// +kubebuilder:default:={livenessProbe:{initialDelaySeconds: 1, timeoutSeconds: 1, periodSeconds: 10, successThreshold: 1, failureThreshold:3}, readinessProbe:{initialDelaySeconds: 1, timeoutSeconds: 1, periodSeconds: 10, successThreshold: 1, failureThreshold:3}}
RedisFollower RedisFollower `json:"redisFollower,omitempty"`
RedisExporter *RedisExporter `json:"redisExporter,omitempty"`
Storage *Storage `json:"storage,omitempty"`
Storage *ClusterStorage `json:"storage,omitempty"`
PodSecurityContext *corev1.PodSecurityContext `json:"podSecurityContext,omitempty"`
PriorityClassName string `json:"priorityClassName,omitempty"`
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
Expand Down
30 changes: 29 additions & 1 deletion api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

281 changes: 279 additions & 2 deletions config/crd/bases/redis.redis.opstreelabs.in_redisclusters.yaml

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions example/acl_config/cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,9 @@ spec:
resources:
requests:
storage: 1Gi
nodeConfVolumeClaimTemplate:
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi
6 changes: 6 additions & 0 deletions example/additional_config/clusterd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ spec:
resources:
requests:
storage: 1Gi
nodeConfVolumeClaimTemplate:
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi
6 changes: 6 additions & 0 deletions example/advance_config/clusterd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ spec:
resources:
requests:
storage: 1Gi
nodeConfVolumeClaimTemplate:
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi
# nodeSelector: {}
# podSecurityContext: {}
# priorityClassName: ""
Expand Down
6 changes: 6 additions & 0 deletions example/affinity/clusterd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,9 @@ spec:
resources:
requests:
storage: 1Gi
nodeConfVolumeClaimTemplate:
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi
10 changes: 8 additions & 2 deletions example/disruption_budget/clusterd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,14 @@ spec:
storage:
volumeClaimTemplate:
spec:
accessModes:
- ReadWriteOnce
# storageClassName: standard
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi
nodeConfVolumeClaimTemplate:
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi
6 changes: 6 additions & 0 deletions example/external_service/clusterd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ spec:
resources:
requests:
storage: 1Gi
nodeConfVolumeClaimTemplate:
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi
6 changes: 6 additions & 0 deletions example/node-selector/clusterd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ spec:
resources:
requests:
storage: 1Gi
nodeConfVolumeClaimTemplate:
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi
6 changes: 6 additions & 0 deletions example/password_protected/clusterd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ spec:
resources:
requests:
storage: 1Gi
nodeConfVolumeClaimTemplate:
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi
6 changes: 6 additions & 0 deletions example/private_registry/clusterd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ spec:
resources:
requests:
storage: 1Gi
nodeConfVolumeClaimTemplate:
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi
6 changes: 6 additions & 0 deletions example/probes/clusterd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,9 @@ spec:
resources:
requests:
storage: 1Gi
nodeConfVolumeClaimTemplate:
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi
6 changes: 6 additions & 0 deletions example/recreate-statefulset/clusterd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,10 @@ spec:
resources:
requests:
storage: 1Gi
nodeConfVolumeClaimTemplate:
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi
priorityClassName: priority-100
8 changes: 7 additions & 1 deletion example/redis-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
spec:
clusterSize: 3
clusterVersion: v7
persistenceEnabled: false
persistenceEnabled: true
podSecurityContext:
runAsUser: 1000
fsGroup: 1000
Expand Down Expand Up @@ -64,6 +64,12 @@ spec:
resources:
requests:
storage: 1Gi
nodeConfVolumeClaimTemplate:
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi
# nodeSelector:
# kubernetes.io/hostname: minikube
# priorityClassName:
Expand Down
7 changes: 7 additions & 0 deletions example/redis_monitoring/clusterd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ spec:
imagePullPolicy: Always
storage:
volumeClaimTemplate:
spec:
# storageClassName: standard
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi
nodeConfVolumeClaimTemplate:
spec:
accessModes: ["ReadWriteOnce"]
resources:
Expand Down
7 changes: 7 additions & 0 deletions example/tls_enabled/redis-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@ spec:
storage:
volumeClaimTemplate:
spec:
# storageClassName: standard
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi
nodeConfVolumeClaimTemplate:
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi
6 changes: 6 additions & 0 deletions example/tolerations/clusterd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,9 @@ spec:
resources:
requests:
storage: 1Gi
nodeConfVolumeClaimTemplate:
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi
6 changes: 6 additions & 0 deletions example/upgrade-strategy/clusterd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ spec:
resources:
requests:
storage: 1Gi
nodeConfVolumeClaimTemplate:
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi
6 changes: 6 additions & 0 deletions example/volume_mount/redis-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ spec:
resources:
requests:
storage: 1Gi
nodeConfVolumeClaimTemplate:
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi
volumemount:
volume:
- name: example-config
Expand Down
1 change: 1 addition & 0 deletions k8sutils/redis-cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func generateRedisClusterParams(cr *redisv1beta1.RedisCluster, replicas int32, e
}
if cr.Spec.Storage != nil {
res.PersistentVolumeClaim = cr.Spec.Storage.VolumeClaimTemplate
res.NodeConfPersistentVolumeClaim = cr.Spec.Storage.NodeConfVolumeClaimTemplate
}
if externalConfig != nil {
res.ExternalConfig = externalConfig
Expand Down
39 changes: 5 additions & 34 deletions k8sutils/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
corev1 "k8s.io/api/core/v1"
apiequality "k8s.io/apimachinery/pkg/api/equality"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
)
Expand All @@ -38,6 +37,7 @@ type statefulSetParameters struct {
Tolerations *[]corev1.Toleration
EnableMetrics bool
PersistentVolumeClaim corev1.PersistentVolumeClaim
NodeConfPersistentVolumeClaim corev1.PersistentVolumeClaim
ImagePullSecrets *[]corev1.LocalObjectReference
ExternalConfig *string
ServiceAccountName *string
Expand Down Expand Up @@ -252,10 +252,10 @@ func generateStatefulSetsDef(stsMeta metav1.ObjectMeta, params statefulSetParame
statefulset.Spec.Template.Spec.ImagePullSecrets = *params.ImagePullSecrets
}
if containerParams.PersistenceEnabled != nil && params.ClusterMode {
statefulset.Spec.VolumeClaimTemplates = append(statefulset.Spec.VolumeClaimTemplates, createPVCTemplateNodeConf(stsMeta))
statefulset.Spec.VolumeClaimTemplates = append(statefulset.Spec.VolumeClaimTemplates, createPVCTemplate("node-conf", stsMeta, params.NodeConfPersistentVolumeClaim))
}
if containerParams.PersistenceEnabled != nil && *containerParams.PersistenceEnabled {
statefulset.Spec.VolumeClaimTemplates = append(statefulset.Spec.VolumeClaimTemplates, createPVCTemplate(stsMeta, params.PersistentVolumeClaim))
statefulset.Spec.VolumeClaimTemplates = append(statefulset.Spec.VolumeClaimTemplates, createPVCTemplate(stsMeta.GetName(), stsMeta, params.PersistentVolumeClaim))
}
if params.ExternalConfig != nil {
statefulset.Spec.Template.Spec.Volumes = getExternalConfig(*params.ExternalConfig)
Expand Down Expand Up @@ -308,40 +308,11 @@ func getExternalConfig(configMapName string) []corev1.Volume {
}
}

// createPVCTemplate to store node.conf in durable manner
func createPVCTemplateNodeConf(stsMeta metav1.ObjectMeta) corev1.PersistentVolumeClaim {
// 1Mb Resource requirement for the node.conf
pvcNodeConf := corev1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Name: "node-conf",
},
Spec: corev1.PersistentVolumeClaimSpec{
AccessModes: []corev1.PersistentVolumeAccessMode{
corev1.ReadWriteOnce,
},
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceStorage: resource.MustParse("1Mi"),
},
},
VolumeMode: func() *corev1.PersistentVolumeMode {
volumeMode := corev1.PersistentVolumeFilesystem
return &volumeMode
}(),
},
}
// Load the labels from the statefulset
pvcNodeConf.Labels = stsMeta.GetLabels()
// We want the same annoations as the StatefulSet here
pvcNodeConf.Annotations = generateStatefulSetsAnots(stsMeta)
return pvcNodeConf
}

// createPVCTemplate will create the persistent volume claim template
func createPVCTemplate(stsMeta metav1.ObjectMeta, storageSpec corev1.PersistentVolumeClaim) corev1.PersistentVolumeClaim {
func createPVCTemplate(volumeName string, stsMeta metav1.ObjectMeta, storageSpec corev1.PersistentVolumeClaim) corev1.PersistentVolumeClaim {
pvcTemplate := storageSpec
pvcTemplate.CreationTimestamp = metav1.Time{}
pvcTemplate.Name = stsMeta.GetName()
pvcTemplate.Name = volumeName
pvcTemplate.Labels = stsMeta.GetLabels()
// We want the same annoations as the StatefulSet here
pvcTemplate.Annotations = generateStatefulSetsAnots(stsMeta)
Expand Down

0 comments on commit 4e21093

Please sign in to comment.