diff --git a/api/v1beta1/common_types.go b/api/v1beta1/common_types.go index 499eb4733be5dcbda94f717982c428d5e63d6b37..de110c4cc5d7a644180d1fdb356227c7b268ec64 100644 --- a/api/v1beta1/common_types.go +++ b/api/v1beta1/common_types.go @@ -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"` diff --git a/api/v1beta1/rediscluster_types.go b/api/v1beta1/rediscluster_types.go index 6ef6d6f7a8db03f4eefdae0b7fc257d88f009599..35cda96a6e099dfe2d6929f34882d2c6d8b5d990 100644 --- a/api/v1beta1/rediscluster_types.go +++ b/api/v1beta1/rediscluster_types.go @@ -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"` diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index 1b13370e5c16ca73fea2a78fbe82d88dbd501118..22572ba70cd4297982782b4c0a955cd9ff628842 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -75,6 +75,24 @@ func (in *AdditionalVolume) DeepCopy() *AdditionalVolume { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ClusterStorage) DeepCopyInto(out *ClusterStorage) { + *out = *in + in.VolumeClaimTemplate.DeepCopyInto(&out.VolumeClaimTemplate) + in.NodeConfVolumeClaimTemplate.DeepCopyInto(&out.NodeConfVolumeClaimTemplate) + in.VolumeMount.DeepCopyInto(&out.VolumeMount) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterStorage. +func (in *ClusterStorage) DeepCopy() *ClusterStorage { + if in == nil { + return nil + } + out := new(ClusterStorage) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ExistingPasswordSecret) DeepCopyInto(out *ExistingPasswordSecret) { *out = *in @@ -310,7 +328,7 @@ func (in *RedisClusterSpec) DeepCopyInto(out *RedisClusterSpec) { } if in.Storage != nil { in, out := &in.Storage, &out.Storage - *out = new(Storage) + *out = new(ClusterStorage) (*in).DeepCopyInto(*out) } if in.PodSecurityContext != nil { @@ -450,6 +468,11 @@ func (in *RedisFollower) DeepCopyInto(out *RedisFollower) { *out = new(RedisConfig) (*in).DeepCopyInto(*out) } + if in.SecurityContext != nil { + in, out := &in.SecurityContext, &out.SecurityContext + *out = new(v1.SecurityContext) + (*in).DeepCopyInto(*out) + } if in.Affinity != nil { in, out := &in.Affinity, &out.Affinity *out = new(v1.Affinity) @@ -518,6 +541,11 @@ func (in *RedisLeader) DeepCopyInto(out *RedisLeader) { *out = new(RedisConfig) (*in).DeepCopyInto(*out) } + if in.SecurityContext != nil { + in, out := &in.SecurityContext, &out.SecurityContext + *out = new(v1.SecurityContext) + (*in).DeepCopyInto(*out) + } if in.Affinity != nil { in, out := &in.Affinity, &out.Affinity *out = new(v1.Affinity) diff --git a/config/crd/bases/redis.redis.opstreelabs.in_redisclusters.yaml b/config/crd/bases/redis.redis.opstreelabs.in_redisclusters.yaml index f7d234e7826c92d488499d90e77f1affab6431c2..281d85ba10db5b901ea5f0064c2a44cb0c8bc662 100644 --- a/config/crd/bases/redis.redis.opstreelabs.in_redisclusters.yaml +++ b/config/crd/bases/redis.redis.opstreelabs.in_redisclusters.yaml @@ -3429,9 +3429,286 @@ spec: type: object type: array storage: - description: Storage is the inteface to add pvc and pv support in - redis + description: Node-conf needs to be added only in redis cluster properties: + nodeConfVolumeClaimTemplate: + description: PersistentVolumeClaim is a user's request for and + claim to a persistent volume + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this + representation of an object. Servers should convert recognized + schemas to the latest internal value, and may reject unrecognized + values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST + resource this object represents. Servers may infer this + from the endpoint the client submits requests to. Cannot + be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + description: 'Standard object''s metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata' + type: object + spec: + description: 'Spec defines the desired characteristics of + a volume requested by a pod author. More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#persistentvolumeclaims' + properties: + accessModes: + description: 'AccessModes contains the desired access + modes the volume should have. More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#access-modes-1' + items: + type: string + type: array + dataSource: + description: 'This field can be used to specify either: + * An existing VolumeSnapshot object (snapshot.storage.k8s.io/VolumeSnapshot) + * An existing PVC (PersistentVolumeClaim) If the provisioner + or an external controller can support the specified + data source, it will create a new volume based on the + contents of the specified data source. If the AnyVolumeDataSource + feature gate is enabled, this field will always have + the same contents as the DataSourceRef field.' + properties: + apiGroup: + description: APIGroup is the group for the resource + being referenced. If APIGroup is not specified, + the specified Kind must be in the core API group. + For any other third-party types, APIGroup is required. + type: string + kind: + description: Kind is the type of resource being referenced + type: string + name: + description: Name is the name of resource being referenced + type: string + required: + - kind + - name + type: object + dataSourceRef: + description: 'Specifies the object from which to populate + the volume with data, if a non-empty volume is desired. + This may be any local object from a non-empty API group + (non core object) or a PersistentVolumeClaim object. + When this field is specified, volume binding will only + succeed if the type of the specified object matches + some installed volume populator or dynamic provisioner. + This field will replace the functionality of the DataSource + field and as such if both fields are non-empty, they + must have the same value. For backwards compatibility, + both fields (DataSource and DataSourceRef) will be set + to the same value automatically if one of them is empty + and the other is non-empty. There are two important + differences between DataSource and DataSourceRef: * + While DataSource only allows two specific types of objects, + DataSourceRef allows any non-core object, as well + as PersistentVolumeClaim objects. * While DataSource + ignores disallowed values (dropping them), DataSourceRef preserves + all values, and generates an error if a disallowed value + is specified. (Alpha) Using this field requires the + AnyVolumeDataSource feature gate to be enabled.' + properties: + apiGroup: + description: APIGroup is the group for the resource + being referenced. If APIGroup is not specified, + the specified Kind must be in the core API group. + For any other third-party types, APIGroup is required. + type: string + kind: + description: Kind is the type of resource being referenced + type: string + name: + description: Name is the name of resource being referenced + type: string + required: + - kind + - name + type: object + resources: + description: 'Resources represents the minimum resources + the volume should have. If RecoverVolumeExpansionFailure + feature is enabled users are allowed to specify resource + requirements that are lower than previous value but + must still be higher than capacity recorded in the status + field of the claim. More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#resources' + properties: + limits: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + description: 'Limits describes the maximum amount + of compute resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/' + type: object + requests: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + description: 'Requests describes the minimum amount + of compute resources required. If Requests is omitted + for a container, it defaults to Limits if that is + explicitly specified, otherwise to an implementation-defined + value. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/' + type: object + type: object + selector: + description: A label query over volumes to consider for + binding. + properties: + matchExpressions: + description: matchExpressions is a list of label selector + requirements. The requirements are ANDed. + items: + description: A label selector requirement is a selector + that contains values, a key, and an operator that + relates the key and values. + properties: + key: + description: key is the label key that the selector + applies to. + type: string + operator: + description: operator represents a key's relationship + to a set of values. Valid operators are In, + NotIn, Exists and DoesNotExist. + type: string + values: + description: values is an array of string values. + If the operator is In or NotIn, the values + array must be non-empty. If the operator is + Exists or DoesNotExist, the values array must + be empty. This array is replaced during a + strategic merge patch. + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + matchLabels: + additionalProperties: + type: string + description: matchLabels is a map of {key,value} pairs. + A single {key,value} in the matchLabels map is equivalent + to an element of matchExpressions, whose key field + is "key", the operator is "In", and the values array + contains only "value". The requirements are ANDed. + type: object + type: object + storageClassName: + description: 'Name of the StorageClass required by the + claim. More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#class-1' + type: string + volumeMode: + description: volumeMode defines what type of volume is + required by the claim. Value of Filesystem is implied + when not included in claim spec. + type: string + volumeName: + description: VolumeName is the binding reference to the + PersistentVolume backing this claim. + type: string + type: object + status: + description: 'Status represents the current information/status + of a persistent volume claim. Read-only. More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#persistentvolumeclaims' + properties: + accessModes: + description: 'AccessModes contains the actual access modes + the volume backing the PVC has. More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#access-modes-1' + items: + type: string + type: array + allocatedResources: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + description: The storage resource within AllocatedResources + tracks the capacity allocated to a PVC. It may be larger + than the actual capacity when a volume expansion operation + is requested. For storage quota, the larger value from + allocatedResources and PVC.spec.resources is used. If + allocatedResources is not set, PVC.spec.resources alone + is used for quota calculation. If a volume expansion + capacity request is lowered, allocatedResources is only + lowered if there are no expansion operations in progress + and if the actual volume capacity is equal or lower + than the requested capacity. This is an alpha field + and requires enabling RecoverVolumeExpansionFailure + feature. + type: object + capacity: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + description: Represents the actual resources of the underlying + volume. + type: object + conditions: + description: Current Condition of persistent volume claim. + If underlying persistent volume is being resized then + the Condition will be set to 'ResizeStarted'. + items: + description: PersistentVolumeClaimCondition contails + details about state of pvc + properties: + lastProbeTime: + description: Last time we probed the condition. + format: date-time + type: string + lastTransitionTime: + description: Last time the condition transitioned + from one status to another. + format: date-time + type: string + message: + description: Human-readable message indicating details + about last transition. + type: string + reason: + description: Unique, this should be a short, machine + understandable string that gives the reason for + condition's last transition. If it reports "ResizeStarted" + that means the underlying persistent volume is + being resized. + type: string + status: + type: string + type: + description: PersistentVolumeClaimConditionType + is a valid value of PersistentVolumeClaimCondition.Type + type: string + required: + - status + - type + type: object + type: array + phase: + description: Phase represents the current phase of PersistentVolumeClaim. + type: string + resizeStatus: + description: ResizeStatus stores status of resize operation. + ResizeStatus is not set by default but when expansion + is complete resizeStatus is set to empty string by resize + controller or kubelet. This is an alpha field and requires + enabling RecoverVolumeExpansionFailure feature. + type: string + type: object + type: object volumeClaimTemplate: description: PersistentVolumeClaim is a user's request for and claim to a persistent volume diff --git a/example/acl_config/cluster.yaml b/example/acl_config/cluster.yaml index 2bed225e21b06e308bc5bee825caf685456d2dc6..5f025c9ae1e694ae4f36287a5212a836de0c43de 100644 --- a/example/acl_config/cluster.yaml +++ b/example/acl_config/cluster.yaml @@ -48,3 +48,9 @@ spec: resources: requests: storage: 1Gi + nodeConfVolumeClaimTemplate: + spec: + accessModes: ["ReadWriteOnce"] + resources: + requests: + storage: 1Gi diff --git a/example/additional_config/clusterd.yaml b/example/additional_config/clusterd.yaml index ab236935656f8bde240434ea5ab918bb60067603..a02e2c6a49f7226920025051029988b09e6a0eca 100644 --- a/example/additional_config/clusterd.yaml +++ b/example/additional_config/clusterd.yaml @@ -30,3 +30,9 @@ spec: resources: requests: storage: 1Gi + nodeConfVolumeClaimTemplate: + spec: + accessModes: ["ReadWriteOnce"] + resources: + requests: + storage: 1Gi diff --git a/example/advance_config/clusterd.yaml b/example/advance_config/clusterd.yaml index fba0dcb38ad728cedc0691797afc3263f0ad31b6..0bd59383acf6691db73f34eb2983fef43fd8e196 100644 --- a/example/advance_config/clusterd.yaml +++ b/example/advance_config/clusterd.yaml @@ -32,6 +32,12 @@ spec: resources: requests: storage: 1Gi + nodeConfVolumeClaimTemplate: + spec: + accessModes: ["ReadWriteOnce"] + resources: + requests: + storage: 1Gi # nodeSelector: {} # podSecurityContext: {} # priorityClassName: "" diff --git a/example/affinity/clusterd.yaml b/example/affinity/clusterd.yaml index 734e9a75475c6f732539a33c7e86bc93636476c8..6b9bdd541b6c5aa0008980e7f1592ba85bef8c6c 100644 --- a/example/affinity/clusterd.yaml +++ b/example/affinity/clusterd.yaml @@ -48,3 +48,9 @@ spec: resources: requests: storage: 1Gi + nodeConfVolumeClaimTemplate: + spec: + accessModes: ["ReadWriteOnce"] + resources: + requests: + storage: 1Gi diff --git a/example/disruption_budget/clusterd.yaml b/example/disruption_budget/clusterd.yaml index 53bce8ae3b21f32f3ef4908a49db2ea7e07fc121..f1de2aeab7a5db1cb5bc3dd548fa0392ffbca651 100644 --- a/example/disruption_budget/clusterd.yaml +++ b/example/disruption_budget/clusterd.yaml @@ -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 diff --git a/example/external_service/clusterd.yaml b/example/external_service/clusterd.yaml index 185b880647c23c7ea65455b535b77728df045f7c..4bc986da5553f8f8a084584345a9999812138120 100644 --- a/example/external_service/clusterd.yaml +++ b/example/external_service/clusterd.yaml @@ -24,3 +24,9 @@ spec: resources: requests: storage: 1Gi + nodeConfVolumeClaimTemplate: + spec: + accessModes: ["ReadWriteOnce"] + resources: + requests: + storage: 1Gi diff --git a/example/node-selector/clusterd.yaml b/example/node-selector/clusterd.yaml index 6a6571cc31bfbd933fdc5c3d6d9f158023d9e07a..82b4ccf7b1c0997b475ab3a134650fe7a355b6c7 100644 --- a/example/node-selector/clusterd.yaml +++ b/example/node-selector/clusterd.yaml @@ -30,3 +30,9 @@ spec: resources: requests: storage: 1Gi + nodeConfVolumeClaimTemplate: + spec: + accessModes: ["ReadWriteOnce"] + resources: + requests: + storage: 1Gi diff --git a/example/password_protected/clusterd.yaml b/example/password_protected/clusterd.yaml index 8ba43c4ffeb13d289de714ebf2296b8976ef2789..18cbf49006df8bd6a45c4a0c58845a3737cdce9a 100644 --- a/example/password_protected/clusterd.yaml +++ b/example/password_protected/clusterd.yaml @@ -27,3 +27,9 @@ spec: resources: requests: storage: 1Gi + nodeConfVolumeClaimTemplate: + spec: + accessModes: ["ReadWriteOnce"] + resources: + requests: + storage: 1Gi diff --git a/example/private_registry/clusterd.yaml b/example/private_registry/clusterd.yaml index 63b95e4fd18ff447ac6455e4694bdb96495e8c60..9202d2dd422965f4cc5c0417afe26193d6997f04 100644 --- a/example/private_registry/clusterd.yaml +++ b/example/private_registry/clusterd.yaml @@ -26,3 +26,9 @@ spec: resources: requests: storage: 1Gi + nodeConfVolumeClaimTemplate: + spec: + accessModes: ["ReadWriteOnce"] + resources: + requests: + storage: 1Gi diff --git a/example/probes/clusterd.yaml b/example/probes/clusterd.yaml index d1890549e68218585ec61495ec3d521e498bb3bd..981483c08b9f9e656e395aeab4612c33db31d671 100644 --- a/example/probes/clusterd.yaml +++ b/example/probes/clusterd.yaml @@ -49,3 +49,9 @@ spec: resources: requests: storage: 1Gi + nodeConfVolumeClaimTemplate: + spec: + accessModes: ["ReadWriteOnce"] + resources: + requests: + storage: 1Gi diff --git a/example/recreate-statefulset/clusterd.yaml b/example/recreate-statefulset/clusterd.yaml index 352bc30322c5dc61c70d544d9ff2015e396ef303..cf7098e15e4622343323d16e2e447d51fd57c116 100644 --- a/example/recreate-statefulset/clusterd.yaml +++ b/example/recreate-statefulset/clusterd.yaml @@ -26,4 +26,10 @@ spec: resources: requests: storage: 1Gi + nodeConfVolumeClaimTemplate: + spec: + accessModes: ["ReadWriteOnce"] + resources: + requests: + storage: 1Gi priorityClassName: priority-100 diff --git a/example/redis-cluster.yaml b/example/redis-cluster.yaml index 32da85aca2e79016080226b5847ed50c0de92314..cfde998638369056233d97a776fa711cfb4786a0 100644 --- a/example/redis-cluster.yaml +++ b/example/redis-cluster.yaml @@ -6,7 +6,7 @@ metadata: spec: clusterSize: 3 clusterVersion: v7 - persistenceEnabled: false + persistenceEnabled: true podSecurityContext: runAsUser: 1000 fsGroup: 1000 @@ -64,6 +64,12 @@ spec: resources: requests: storage: 1Gi + nodeConfVolumeClaimTemplate: + spec: + accessModes: ["ReadWriteOnce"] + resources: + requests: + storage: 1Gi # nodeSelector: # kubernetes.io/hostname: minikube # priorityClassName: diff --git a/example/redis_monitoring/clusterd.yaml b/example/redis_monitoring/clusterd.yaml index a87b6b899c62b03da8b54d503cf1c8a1a428cb3e..617f9c3a211b7dcf31e74a4d4a037ab2b45fe5c5 100644 --- a/example/redis_monitoring/clusterd.yaml +++ b/example/redis_monitoring/clusterd.yaml @@ -21,6 +21,13 @@ spec: imagePullPolicy: Always storage: volumeClaimTemplate: + spec: + # storageClassName: standard + accessModes: ["ReadWriteOnce"] + resources: + requests: + storage: 1Gi + nodeConfVolumeClaimTemplate: spec: accessModes: ["ReadWriteOnce"] resources: diff --git a/example/tls_enabled/redis-cluster.yaml b/example/tls_enabled/redis-cluster.yaml index c6a856552025998238a4d6c2c28074e09535cea1..af57922feda2dfea15cc36a9965de547ba1e20e6 100644 --- a/example/tls_enabled/redis-cluster.yaml +++ b/example/tls_enabled/redis-cluster.yaml @@ -45,7 +45,14 @@ spec: storage: volumeClaimTemplate: spec: + # storageClassName: standard accessModes: ["ReadWriteOnce"] resources: requests: storage: 1Gi + nodeConfVolumeClaimTemplate: + spec: + accessModes: ["ReadWriteOnce"] + resources: + requests: + storage: 1Gi \ No newline at end of file diff --git a/example/tolerations/clusterd.yaml b/example/tolerations/clusterd.yaml index 840ded711ae1730e15c386659b1193160afd6fe1..80fecb2373475f93d5cf9352b06fd5c4fd17099c 100644 --- a/example/tolerations/clusterd.yaml +++ b/example/tolerations/clusterd.yaml @@ -36,3 +36,9 @@ spec: resources: requests: storage: 1Gi + nodeConfVolumeClaimTemplate: + spec: + accessModes: ["ReadWriteOnce"] + resources: + requests: + storage: 1Gi diff --git a/example/upgrade-strategy/clusterd.yaml b/example/upgrade-strategy/clusterd.yaml index d58fc9a79229ef1bf7c12d16813774c5bed97200..8fdf0a5450e5a70395512549040e897cae5eb50b 100644 --- a/example/upgrade-strategy/clusterd.yaml +++ b/example/upgrade-strategy/clusterd.yaml @@ -27,3 +27,9 @@ spec: resources: requests: storage: 1Gi + nodeConfVolumeClaimTemplate: + spec: + accessModes: ["ReadWriteOnce"] + resources: + requests: + storage: 1Gi diff --git a/example/volume_mount/redis-cluster.yaml b/example/volume_mount/redis-cluster.yaml index f453c8be23066f161f87ea55cabf4271f3fe2582..c65ddfa6b50abaa605fd360bd62ae23a017973ea 100644 --- a/example/volume_mount/redis-cluster.yaml +++ b/example/volume_mount/redis-cluster.yaml @@ -43,6 +43,12 @@ spec: resources: requests: storage: 1Gi + nodeConfVolumeClaimTemplate: + spec: + accessModes: ["ReadWriteOnce"] + resources: + requests: + storage: 1Gi volumemount: volume: - name: example-config diff --git a/k8sutils/redis-cluster.go b/k8sutils/redis-cluster.go index 2bd6e11eac435b9d7cc4ae7f0183b2731f57bf4a..a99fe8b1993d0a4fda81783ca61caab7a2fad009 100644 --- a/k8sutils/redis-cluster.go +++ b/k8sutils/redis-cluster.go @@ -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 diff --git a/k8sutils/statefulset.go b/k8sutils/statefulset.go index 4e69adb3c0312539c5bea4a0fe729c59c82092ce..a07a83e058a4e59bf22d052b7fd1ee9ae0e77203 100644 --- a/k8sutils/statefulset.go +++ b/k8sutils/statefulset.go @@ -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" ) @@ -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 @@ -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) @@ -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)