Skip to content

Commit d17ea8b

Browse files
authored
feat: Add PersistentVolumeClaimRetentionPolicy support (#1448)
Signed-off-by: Dee Kryvenko <[email protected]>
1 parent 4a41f55 commit d17ea8b

File tree

16 files changed

+361
-91
lines changed

16 files changed

+361
-91
lines changed

api/common/v1beta2/common_types.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ import (
88
// KubernetesConfig will be the JSON struct for Basic Redis Config
99
// +k8s:deepcopy-gen=true
1010
type KubernetesConfig struct {
11-
Image string `json:"image"`
12-
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
13-
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
14-
ExistingPasswordSecret *ExistingPasswordSecret `json:"redisSecret,omitempty"`
15-
ImagePullSecrets *[]corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
16-
UpdateStrategy appsv1.StatefulSetUpdateStrategy `json:"updateStrategy,omitempty"`
17-
Service *ServiceConfig `json:"service,omitempty"`
18-
IgnoreAnnotations []string `json:"ignoreAnnotations,omitempty"`
19-
MinReadySeconds *int32 `json:"minReadySeconds,omitempty"`
11+
Image string `json:"image"`
12+
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
13+
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
14+
ExistingPasswordSecret *ExistingPasswordSecret `json:"redisSecret,omitempty"`
15+
ImagePullSecrets *[]corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
16+
UpdateStrategy appsv1.StatefulSetUpdateStrategy `json:"updateStrategy,omitempty"`
17+
PersistentVolumeClaimRetentionPolicy *appsv1.StatefulSetPersistentVolumeClaimRetentionPolicy `json:"persistentVolumeClaimRetentionPolicy,omitempty"`
18+
Service *ServiceConfig `json:"service,omitempty"`
19+
IgnoreAnnotations []string `json:"ignoreAnnotations,omitempty"`
20+
MinReadySeconds *int32 `json:"minReadySeconds,omitempty"`
2021
}
2122

2223
func (in *KubernetesConfig) GetServiceType() string {

api/common/v1beta2/zz_generated.deepcopy.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/redis-operator/crds/crds.yaml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,6 +1564,27 @@ spec:
15641564
minReadySeconds:
15651565
format: int32
15661566
type: integer
1567+
persistentVolumeClaimRetentionPolicy:
1568+
description: |-
1569+
StatefulSetPersistentVolumeClaimRetentionPolicy describes the policy used for PVCs
1570+
created from the StatefulSet VolumeClaimTemplates.
1571+
properties:
1572+
whenDeleted:
1573+
description: |-
1574+
WhenDeleted specifies what happens to PVCs created from StatefulSet
1575+
VolumeClaimTemplates when the StatefulSet is deleted. The default policy
1576+
of `Retain` causes PVCs to not be affected by StatefulSet deletion. The
1577+
`Delete` policy causes those PVCs to be deleted.
1578+
type: string
1579+
whenScaled:
1580+
description: |-
1581+
WhenScaled specifies what happens to PVCs created from StatefulSet
1582+
VolumeClaimTemplates when the StatefulSet is scaled down. The default
1583+
policy of `Retain` causes PVCs to not be affected by a scaledown. The
1584+
`Delete` policy causes the associated PVCs for any excess pods above
1585+
the replica count to be deleted.
1586+
type: string
1587+
type: object
15671588
redisSecret:
15681589
description: ExistingPasswordSecret is the struct to access the
15691590
existing secret
@@ -6085,6 +6106,27 @@ spec:
60856106
minReadySeconds:
60866107
format: int32
60876108
type: integer
6109+
persistentVolumeClaimRetentionPolicy:
6110+
description: |-
6111+
StatefulSetPersistentVolumeClaimRetentionPolicy describes the policy used for PVCs
6112+
created from the StatefulSet VolumeClaimTemplates.
6113+
properties:
6114+
whenDeleted:
6115+
description: |-
6116+
WhenDeleted specifies what happens to PVCs created from StatefulSet
6117+
VolumeClaimTemplates when the StatefulSet is deleted. The default policy
6118+
of `Retain` causes PVCs to not be affected by StatefulSet deletion. The
6119+
`Delete` policy causes those PVCs to be deleted.
6120+
type: string
6121+
whenScaled:
6122+
description: |-
6123+
WhenScaled specifies what happens to PVCs created from StatefulSet
6124+
VolumeClaimTemplates when the StatefulSet is scaled down. The default
6125+
policy of `Retain` causes PVCs to not be affected by a scaledown. The
6126+
`Delete` policy causes the associated PVCs for any excess pods above
6127+
the replica count to be deleted.
6128+
type: string
6129+
type: object
60886130
redisSecret:
60896131
description: ExistingPasswordSecret is the struct to access the
60906132
existing secret
@@ -14779,6 +14821,27 @@ spec:
1477914821
minReadySeconds:
1478014822
format: int32
1478114823
type: integer
14824+
persistentVolumeClaimRetentionPolicy:
14825+
description: |-
14826+
StatefulSetPersistentVolumeClaimRetentionPolicy describes the policy used for PVCs
14827+
created from the StatefulSet VolumeClaimTemplates.
14828+
properties:
14829+
whenDeleted:
14830+
description: |-
14831+
WhenDeleted specifies what happens to PVCs created from StatefulSet
14832+
VolumeClaimTemplates when the StatefulSet is deleted. The default policy
14833+
of `Retain` causes PVCs to not be affected by StatefulSet deletion. The
14834+
`Delete` policy causes those PVCs to be deleted.
14835+
type: string
14836+
whenScaled:
14837+
description: |-
14838+
WhenScaled specifies what happens to PVCs created from StatefulSet
14839+
VolumeClaimTemplates when the StatefulSet is scaled down. The default
14840+
policy of `Retain` causes PVCs to not be affected by a scaledown. The
14841+
`Delete` policy causes the associated PVCs for any excess pods above
14842+
the replica count to be deleted.
14843+
type: string
14844+
type: object
1478214845
redisSecret:
1478314846
description: ExistingPasswordSecret is the struct to access the
1478414847
existing secret
@@ -20277,6 +20340,27 @@ spec:
2027720340
minReadySeconds:
2027820341
format: int32
2027920342
type: integer
20343+
persistentVolumeClaimRetentionPolicy:
20344+
description: |-
20345+
StatefulSetPersistentVolumeClaimRetentionPolicy describes the policy used for PVCs
20346+
created from the StatefulSet VolumeClaimTemplates.
20347+
properties:
20348+
whenDeleted:
20349+
description: |-
20350+
WhenDeleted specifies what happens to PVCs created from StatefulSet
20351+
VolumeClaimTemplates when the StatefulSet is deleted. The default policy
20352+
of `Retain` causes PVCs to not be affected by StatefulSet deletion. The
20353+
`Delete` policy causes those PVCs to be deleted.
20354+
type: string
20355+
whenScaled:
20356+
description: |-
20357+
WhenScaled specifies what happens to PVCs created from StatefulSet
20358+
VolumeClaimTemplates when the StatefulSet is scaled down. The default
20359+
policy of `Retain` causes PVCs to not be affected by a scaledown. The
20360+
`Delete` policy causes the associated PVCs for any excess pods above
20361+
the replica count to be deleted.
20362+
type: string
20363+
type: object
2028020364
redisSecret:
2028120365
description: ExistingPasswordSecret is the struct to access the
2028220366
existing secret

config/crd/bases/redis.redis.opstreelabs.in_redis.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,6 +1565,27 @@ spec:
15651565
minReadySeconds:
15661566
format: int32
15671567
type: integer
1568+
persistentVolumeClaimRetentionPolicy:
1569+
description: |-
1570+
StatefulSetPersistentVolumeClaimRetentionPolicy describes the policy used for PVCs
1571+
created from the StatefulSet VolumeClaimTemplates.
1572+
properties:
1573+
whenDeleted:
1574+
description: |-
1575+
WhenDeleted specifies what happens to PVCs created from StatefulSet
1576+
VolumeClaimTemplates when the StatefulSet is deleted. The default policy
1577+
of `Retain` causes PVCs to not be affected by StatefulSet deletion. The
1578+
`Delete` policy causes those PVCs to be deleted.
1579+
type: string
1580+
whenScaled:
1581+
description: |-
1582+
WhenScaled specifies what happens to PVCs created from StatefulSet
1583+
VolumeClaimTemplates when the StatefulSet is scaled down. The default
1584+
policy of `Retain` causes PVCs to not be affected by a scaledown. The
1585+
`Delete` policy causes the associated PVCs for any excess pods above
1586+
the replica count to be deleted.
1587+
type: string
1588+
type: object
15681589
redisSecret:
15691590
description: ExistingPasswordSecret is the struct to access the
15701591
existing secret

config/crd/bases/redis.redis.opstreelabs.in_redisclusters.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,27 @@ spec:
715715
minReadySeconds:
716716
format: int32
717717
type: integer
718+
persistentVolumeClaimRetentionPolicy:
719+
description: |-
720+
StatefulSetPersistentVolumeClaimRetentionPolicy describes the policy used for PVCs
721+
created from the StatefulSet VolumeClaimTemplates.
722+
properties:
723+
whenDeleted:
724+
description: |-
725+
WhenDeleted specifies what happens to PVCs created from StatefulSet
726+
VolumeClaimTemplates when the StatefulSet is deleted. The default policy
727+
of `Retain` causes PVCs to not be affected by StatefulSet deletion. The
728+
`Delete` policy causes those PVCs to be deleted.
729+
type: string
730+
whenScaled:
731+
description: |-
732+
WhenScaled specifies what happens to PVCs created from StatefulSet
733+
VolumeClaimTemplates when the StatefulSet is scaled down. The default
734+
policy of `Retain` causes PVCs to not be affected by a scaledown. The
735+
`Delete` policy causes the associated PVCs for any excess pods above
736+
the replica count to be deleted.
737+
type: string
738+
type: object
718739
redisSecret:
719740
description: ExistingPasswordSecret is the struct to access the
720741
existing secret

config/crd/bases/redis.redis.opstreelabs.in_redisreplications.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,6 +1574,27 @@ spec:
15741574
minReadySeconds:
15751575
format: int32
15761576
type: integer
1577+
persistentVolumeClaimRetentionPolicy:
1578+
description: |-
1579+
StatefulSetPersistentVolumeClaimRetentionPolicy describes the policy used for PVCs
1580+
created from the StatefulSet VolumeClaimTemplates.
1581+
properties:
1582+
whenDeleted:
1583+
description: |-
1584+
WhenDeleted specifies what happens to PVCs created from StatefulSet
1585+
VolumeClaimTemplates when the StatefulSet is deleted. The default policy
1586+
of `Retain` causes PVCs to not be affected by StatefulSet deletion. The
1587+
`Delete` policy causes those PVCs to be deleted.
1588+
type: string
1589+
whenScaled:
1590+
description: |-
1591+
WhenScaled specifies what happens to PVCs created from StatefulSet
1592+
VolumeClaimTemplates when the StatefulSet is scaled down. The default
1593+
policy of `Retain` causes PVCs to not be affected by a scaledown. The
1594+
`Delete` policy causes the associated PVCs for any excess pods above
1595+
the replica count to be deleted.
1596+
type: string
1597+
type: object
15771598
redisSecret:
15781599
description: ExistingPasswordSecret is the struct to access the
15791600
existing secret

config/crd/bases/redis.redis.opstreelabs.in_redissentinels.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,6 +1500,27 @@ spec:
15001500
minReadySeconds:
15011501
format: int32
15021502
type: integer
1503+
persistentVolumeClaimRetentionPolicy:
1504+
description: |-
1505+
StatefulSetPersistentVolumeClaimRetentionPolicy describes the policy used for PVCs
1506+
created from the StatefulSet VolumeClaimTemplates.
1507+
properties:
1508+
whenDeleted:
1509+
description: |-
1510+
WhenDeleted specifies what happens to PVCs created from StatefulSet
1511+
VolumeClaimTemplates when the StatefulSet is deleted. The default policy
1512+
of `Retain` causes PVCs to not be affected by StatefulSet deletion. The
1513+
`Delete` policy causes those PVCs to be deleted.
1514+
type: string
1515+
whenScaled:
1516+
description: |-
1517+
WhenScaled specifies what happens to PVCs created from StatefulSet
1518+
VolumeClaimTemplates when the StatefulSet is scaled down. The default
1519+
policy of `Retain` causes PVCs to not be affected by a scaledown. The
1520+
`Delete` policy causes the associated PVCs for any excess pods above
1521+
the replica count to be deleted.
1522+
type: string
1523+
type: object
15031524
redisSecret:
15041525
description: ExistingPasswordSecret is the struct to access the
15051526
existing secret

docs/content/en/docs/CRD Reference/Redis API/_index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ _Appears in:_
7575
| `redisSecret` _[ExistingPasswordSecret](#existingpasswordsecret)_ | |
7676
| `imagePullSecrets` _[LocalObjectReference](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#localobjectreference-v1-core)_ | |
7777
| `updateStrategy` _[StatefulSetUpdateStrategy](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#statefulsetupdatestrategy-v1-apps)_ | |
78+
| `persistentVolumeClaimRetentionPolicy` _[StatefulSetPersistentVolumeClaimRetentionPolicy](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#statefulsetpersistentvolumeclaimretentionpolicy-v1-apps)_ | |
7879

7980
#### VolumeMount
8081

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
apiVersion: redis.redis.opstreelabs.in/v1beta2
3+
kind: RedisCluster
4+
metadata:
5+
name: redis-cluster
6+
spec:
7+
clusterSize: 3
8+
clusterVersion: v7
9+
podSecurityContext:
10+
runAsUser: 1000
11+
fsGroup: 1000
12+
persistenceEnabled: true
13+
kubernetesConfig:
14+
image: quay.io/opstree/redis:v7.0.12
15+
imagePullPolicy: IfNotPresent
16+
persistentVolumeClaimRetentionPolicy:
17+
whenScaled: Delete
18+
whenDeleted: Delete
19+
redisExporter:
20+
enabled: false
21+
image: quay.io/opstree/redis-exporter:v1.44.0
22+
storage:
23+
volumeClaimTemplate:
24+
spec:
25+
# storageClassName: standard
26+
accessModes: ["ReadWriteOnce"]
27+
resources:
28+
requests:
29+
storage: 1Gi
30+
nodeConfVolumeClaimTemplate:
31+
spec:
32+
accessModes: ["ReadWriteOnce"]
33+
resources:
34+
requests:
35+
storage: 1Gi
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
apiVersion: redis.redis.opstreelabs.in/v1beta2
3+
kind: RedisReplication
4+
metadata:
5+
name: redis-replication
6+
spec:
7+
clusterSize: 3
8+
kubernetesConfig:
9+
image: quay.io/opstree/redis:v7.0.12
10+
imagePullPolicy: IfNotPresent
11+
persistentVolumeClaimRetentionPolicy:
12+
whenScaled: Delete
13+
whenDeleted: Delete
14+
podSecurityContext:
15+
runAsUser: 1000
16+
fsGroup: 1000
17+
storage:
18+
volumeClaimTemplate:
19+
spec:
20+
# storageClassName: standard
21+
accessModes: ["ReadWriteOnce"]
22+
resources:
23+
requests:
24+
storage: 1Gi
25+
redisExporter:
26+
enabled: false
27+
image: quay.io/opstree/redis-exporter:v1.44.0

0 commit comments

Comments
 (0)