Skip to content

Commit

Permalink
Merge pull request #703 from drivebyer/fix-pvc
Browse files Browse the repository at this point in the history
[Fix] : redis data pvc not deleted
  • Loading branch information
drivebyer authored Nov 14, 2023
2 parents 697538e + bdbe6f0 commit 6502c91
Show file tree
Hide file tree
Showing 28 changed files with 1,025 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
matrix:
testpath:
- ./tests/e2e/v1beta2/setup
- ./tests/e2e/v1beta2/teardown
- ./tests/e2e/v1beta2/ignore-annots

steps:
Expand Down
2 changes: 1 addition & 1 deletion k8sutils/finalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func finalizeRedisPVC(client kubernetes.Interface, logger logr.Logger, cr *redis
func finalizeRedisClusterPVC(client kubernetes.Interface, logger logr.Logger, cr *redisv1beta2.RedisCluster) error {
for _, role := range []string{"leader", "follower"} {
for i := 0; i < int(cr.Spec.GetReplicaCounts(role)); i++ {
PVCName := fmt.Sprintf("%s-%s-%s-%d", cr.Name, cr.Name, role, i)
PVCName := fmt.Sprintf("%s-%s-%s-%s-%d", cr.Name, role, cr.Name, role, i)
err := client.CoreV1().PersistentVolumeClaims(cr.Namespace).Delete(context.TODO(), PVCName, metav1.DeleteOptions{})
if err != nil && !errors.IsNotFound(err) {
logger.Error(err, "Could not delete Persistent Volume Claim "+PVCName)
Expand Down
2 changes: 1 addition & 1 deletion k8sutils/finalizers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func helperRedisClusterPVCs(clusterName string, namespace string) []*corev1.Pers
roles := []string{"leader", "follower"}
for _, role := range roles {
for i := 0; i < 3; i++ {
clusterPVCName := fmt.Sprintf("%s-%s-%s-%d", clusterName, clusterName, role, i)
clusterPVCName := fmt.Sprintf("%s-%s-%s-%s-%d", clusterName, role, clusterName, role, i)
clusterPVC := &corev1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Name: clusterPVCName,
Expand Down
1 change: 1 addition & 0 deletions tests/_config/kuttl-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ parallel: 1
timeout: 300
testDirs:
- tests/e2e/v1beta2/setup
- tests/e2e/v1beta2/teardown
- tests/e2e/v1beta2/ignore-annots
suppress :
- events
9 changes: 9 additions & 0 deletions tests/e2e/v1beta2/teardown/redis-cluster/00-install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
apply :
- cluster.yaml
assert :
- ready-cluster.yaml
- ready-sts.yaml
- ready-pvc.yaml
- ready-svc.yaml
10 changes: 10 additions & 0 deletions tests/e2e/v1beta2/teardown/redis-cluster/01-uninstall.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- command: kubectl delete -f cluster.yaml
namespaced: true
error:
- ready-cluster.yaml
- ready-sts.yaml
- ready-pvc.yaml
- ready-svc.yaml
47 changes: 47 additions & 0 deletions tests/e2e/v1beta2/teardown/redis-cluster/cluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
apiVersion: redis.redis.opstreelabs.in/v1beta2
kind: RedisCluster
metadata:
name: redis-cluster-v1beta2
spec:
clusterSize: 3
clusterVersion: v7
persistenceEnabled: true
podSecurityContext:
runAsUser: 1000
fsGroup: 1000
kubernetesConfig:
image: quay.io/opstree/redis:latest
imagePullPolicy: Always
resources:
requests:
cpu: 101m
memory: 128Mi
limits:
cpu: 101m
memory: 128Mi
redisExporter:
enabled: true
image: quay.io/opstree/redis-exporter:v1.44.0
imagePullPolicy: Always
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 100m
memory: 128Mi
storage:
volumeClaimTemplate:
spec:
# storageClassName: standard
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi
nodeConfVolume: true
nodeConfVolumeClaimTemplate:
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi
7 changes: 7 additions & 0 deletions tests/e2e/v1beta2/teardown/redis-cluster/ready-cluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: redis.redis.opstreelabs.in/v1beta2
kind: RedisCluster
metadata:
name: redis-cluster-v1beta2
status:
readyFollowerReplicas: 3
readyLeaderReplicas: 3
181 changes: 181 additions & 0 deletions tests/e2e/v1beta2/teardown/redis-cluster/ready-pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: node-conf-redis-cluster-v1beta2-leader-0
labels:
app: redis-cluster-v1beta2-leader
redis_setup_type: cluster
role: leader
status:
accessModes:
- ReadWriteOnce
capacity:
storage: 1Gi
phase: Bound
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: node-conf-redis-cluster-v1beta2-leader-1
labels:
app: redis-cluster-v1beta2-leader
redis_setup_type: cluster
role: leader
status:
accessModes:
- ReadWriteOnce
capacity:
storage: 1Gi
phase: Bound
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: node-conf-redis-cluster-v1beta2-leader-2
labels:
app: redis-cluster-v1beta2-leader
redis_setup_type: cluster
role: leader
status:
accessModes:
- ReadWriteOnce
capacity:
storage: 1Gi
phase: Bound
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: node-conf-redis-cluster-v1beta2-follower-0
labels:
app: redis-cluster-v1beta2-follower
redis_setup_type: cluster
role: follower
status:
accessModes:
- ReadWriteOnce
capacity:
storage: 1Gi
phase: Bound
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: node-conf-redis-cluster-v1beta2-follower-1
labels:
app: redis-cluster-v1beta2-follower
redis_setup_type: cluster
role: follower
status:
accessModes:
- ReadWriteOnce
capacity:
storage: 1Gi
phase: Bound
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: node-conf-redis-cluster-v1beta2-follower-2
labels:
app: redis-cluster-v1beta2-follower
redis_setup_type: cluster
role: follower
status:
accessModes:
- ReadWriteOnce
capacity:
storage: 1Gi
phase: Bound

---

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: redis-cluster-v1beta2-leader-redis-cluster-v1beta2-leader-0
labels:
app: redis-cluster-v1beta2-leader
redis_setup_type: cluster
role: leader
status:
accessModes:
- ReadWriteOnce
capacity:
storage: 1Gi
phase: Bound
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: redis-cluster-v1beta2-leader-redis-cluster-v1beta2-leader-1
labels:
app: redis-cluster-v1beta2-leader
redis_setup_type: cluster
role: leader
status:
accessModes:
- ReadWriteOnce
capacity:
storage: 1Gi
phase: Bound
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: redis-cluster-v1beta2-leader-redis-cluster-v1beta2-leader-2
labels:
app: redis-cluster-v1beta2-leader
redis_setup_type: cluster
role: leader
status:
accessModes:
- ReadWriteOnce
capacity:
storage: 1Gi
phase: Bound
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: redis-cluster-v1beta2-follower-redis-cluster-v1beta2-follower-0
labels:
app: redis-cluster-v1beta2-follower
redis_setup_type: cluster
role: follower
status:
accessModes:
- ReadWriteOnce
capacity:
storage: 1Gi
phase: Bound
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: redis-cluster-v1beta2-follower-redis-cluster-v1beta2-follower-1
labels:
app: redis-cluster-v1beta2-follower
redis_setup_type: cluster
role: follower
status:
accessModes:
- ReadWriteOnce
capacity:
storage: 1Gi
phase: Bound
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: redis-cluster-v1beta2-follower-redis-cluster-v1beta2-follower-2
labels:
app: redis-cluster-v1beta2-follower
redis_setup_type: cluster
role: follower
status:
accessModes:
- ReadWriteOnce
capacity:
storage: 1Gi
phase: Bound
25 changes: 25 additions & 0 deletions tests/e2e/v1beta2/teardown/redis-cluster/ready-sts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: redis-cluster-v1beta2-leader
labels:
app: redis-cluster-v1beta2-leader
redis_setup_type: cluster
role: leader
status:
replicas: 3
readyReplicas: 3

---

apiVersion: apps/v1
kind: StatefulSet
metadata:
name: redis-cluster-v1beta2-follower
labels:
app: redis-cluster-v1beta2-follower
redis_setup_type: cluster
role: follower
status:
replicas: 3
readyReplicas: 3
Loading

0 comments on commit 6502c91

Please sign in to comment.