Skip to content

Commit d8ad9f9

Browse files
authored
test: Try ping and save key on redis replication (#731)
* test: Try ping and save key on redis replication Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * saving without password Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * fix test Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * try fix Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> * try Comment Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com> --------- Signed-off-by: Shubham Gupta <iamshubhamgupta2001@gmail.com>
1 parent 25d807a commit d8ad9f9

File tree

7 files changed

+342
-0
lines changed

7 files changed

+342
-0
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json
2+
3+
apiVersion: chainsaw.kyverno.io/v1alpha1
4+
kind: Test
5+
metadata:
6+
name: redis-replication-password
7+
spec:
8+
steps:
9+
- try:
10+
- apply:
11+
file: replication.yaml
12+
- apply:
13+
file: secret.yaml
14+
- assert:
15+
file: ready-sts.yaml
16+
- assert:
17+
file: ready-svc.yaml
18+
- assert:
19+
file: ready-pvc.yaml
20+
- assert:
21+
file: secret.yaml
22+
23+
- name: Sleep for five minutes
24+
try:
25+
- sleep:
26+
duration: 5m
27+
28+
- name: Ping Replicated Cluster With Password
29+
try:
30+
- script:
31+
timeout: 10s
32+
content: |
33+
kubectl exec --namespace ${NAMESPACE} redis-replication-0 -- redis-cli -p 6379 -a Opstree@1234 ping
34+
check:
35+
($stdout=='PONG'): true
36+
- script:
37+
timeout: 10s
38+
content: |
39+
kubectl exec --namespace ${NAMESPACE} redis-replication-1 -- redis-cli -p 6379 -a Opstree@1234 ping
40+
check:
41+
($stdout=='PONG'): true
42+
- script:
43+
timeout: 10s
44+
content: |
45+
kubectl exec --namespace ${NAMESPACE} redis-replication-2 -- redis-cli -p 6379 -a Opstree@1234 ping
46+
check:
47+
($stdout=='PONG'): true
48+
49+
- name: Try saving a key With Password
50+
try:
51+
- script:
52+
timeout: 10s
53+
content: |
54+
kubectl exec --namespace ${NAMESPACE} redis-replication-0 -- redis-cli -p 6379 -a Opstree@1234 set foo-0 bar-0
55+
check:
56+
($stdout=='OK'): true
57+
# - script:
58+
# timeout: 10s
59+
# content: |
60+
# kubectl exec --namespace ${NAMESPACE} redis-replication-1 -- redis-cli -p 6379 -a Opstree@1234 set foo-1 bar-1
61+
# check:
62+
# ($stdout=='READONLY You can't write against a read only replica.'): true
63+
# - script:
64+
# timeout: 10s
65+
# content: |
66+
# kubectl exec --namespace ${NAMESPACE} redis-replication-2 -- redis-cli -p 6379 -a Opstree@1234 set foo-2 bar-2
67+
# check:
68+
# ($stdout=='READONLY You can't write against a read only replica.'): true
69+
70+
- name: Ping Replicated Cluster Without Password
71+
try:
72+
- script:
73+
timeout: 10s
74+
content: |
75+
kubectl exec --namespace ${NAMESPACE} redis-replication-0 -- redis-cli -p 6379 ping
76+
check:
77+
($stdout=='NOAUTH Authentication required.'): true
78+
- script:
79+
timeout: 10s
80+
content: |
81+
kubectl exec --namespace ${NAMESPACE} redis-replication-1 -- redis-cli -p 6379 ping
82+
check:
83+
($stdout=='NOAUTH Authentication required.'): true
84+
- script:
85+
timeout: 10s
86+
content: |
87+
kubectl exec --namespace ${NAMESPACE} redis-replication-2 -- redis-cli -p 6379 ping
88+
check:
89+
($stdout=='NOAUTH Authentication required.'): true
90+
91+
- name: Try saving a key Without Password
92+
try:
93+
- script:
94+
timeout: 10s
95+
content: |
96+
kubectl exec --namespace ${NAMESPACE} redis-replication-0 -- redis-cli -p 6379 set foo-0 bar-0
97+
check:
98+
($stdout=='NOAUTH Authentication required.'): true
99+
- script:
100+
timeout: 10s
101+
content: |
102+
kubectl exec --namespace ${NAMESPACE} redis-replication-1 -- redis-cli -p 6379 set foo-1 bar-1
103+
check:
104+
($stdout=='NOAUTH Authentication required.'): true
105+
- script:
106+
timeout: 10s
107+
content: |
108+
kubectl exec --namespace ${NAMESPACE} redis-replication-2 -- redis-cli -p 6379 set foo-2 bar-2
109+
check:
110+
($stdout=='NOAUTH Authentication required.'): true
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
apiVersion: v1
2+
kind: PersistentVolumeClaim
3+
metadata:
4+
name: redis-replication-redis-replication-0
5+
labels:
6+
app: redis-replication
7+
redis_setup_type: replication
8+
role: replication
9+
status:
10+
accessModes:
11+
- ReadWriteOnce
12+
capacity:
13+
storage: 1Gi
14+
phase: Bound
15+
---
16+
apiVersion: v1
17+
kind: PersistentVolumeClaim
18+
metadata:
19+
name: redis-replication-redis-replication-1
20+
labels:
21+
app: redis-replication
22+
redis_setup_type: replication
23+
role: replication
24+
status:
25+
accessModes:
26+
- ReadWriteOnce
27+
capacity:
28+
storage: 1Gi
29+
phase: Bound
30+
---
31+
apiVersion: v1
32+
kind: PersistentVolumeClaim
33+
metadata:
34+
name: redis-replication-redis-replication-2
35+
labels:
36+
app: redis-replication
37+
redis_setup_type: replication
38+
role: replication
39+
status:
40+
accessModes:
41+
- ReadWriteOnce
42+
capacity:
43+
storage: 1Gi
44+
phase: Bound
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: apps/v1
2+
kind: StatefulSet
3+
metadata:
4+
annotations:
5+
redis.opstreelabs.in: "true"
6+
redis.opstreelabs.instance: redis-replication
7+
labels:
8+
app: redis-replication
9+
redis_setup_type: replication
10+
role: replication
11+
name: redis-replication
12+
ownerReferences:
13+
- apiVersion: redis.redis.opstreelabs.in/v1beta2
14+
controller: true
15+
kind: RedisReplication
16+
name: redis-replication
17+
status:
18+
readyReplicas: 3
19+
replicas: 3
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
annotations:
5+
prometheus.io/port: "9121"
6+
prometheus.io/scrape: "true"
7+
redis.opstreelabs.in: "true"
8+
redis.opstreelabs.instance: redis-replication
9+
labels:
10+
app: redis-replication
11+
redis_setup_type: replication
12+
role: replication
13+
name: redis-replication
14+
ownerReferences:
15+
- apiVersion: redis.redis.opstreelabs.in/v1beta2
16+
controller: true
17+
kind: RedisReplication
18+
name: redis-replication
19+
spec:
20+
ports:
21+
- name: redis-client
22+
port: 6379
23+
protocol: TCP
24+
targetPort: 6379
25+
selector:
26+
app: redis-replication
27+
redis_setup_type: replication
28+
role: replication
29+
type: ClusterIP
30+
---
31+
apiVersion: v1
32+
kind: Service
33+
metadata:
34+
annotations:
35+
prometheus.io/port: "9121"
36+
prometheus.io/scrape: "true"
37+
redis.opstreelabs.in: "true"
38+
redis.opstreelabs.instance: redis-replication
39+
labels:
40+
app: redis-replication
41+
redis_setup_type: replication
42+
role: replication
43+
name: redis-replication-additional
44+
ownerReferences:
45+
- apiVersion: redis.redis.opstreelabs.in/v1beta2
46+
controller: true
47+
kind: RedisReplication
48+
name: redis-replication
49+
spec:
50+
ports:
51+
- name: redis-client
52+
port: 6379
53+
protocol: TCP
54+
targetPort: 6379
55+
selector:
56+
app: redis-replication
57+
redis_setup_type: replication
58+
role: replication
59+
type: ClusterIP
60+
---
61+
apiVersion: v1
62+
kind: Service
63+
metadata:
64+
annotations:
65+
prometheus.io/port: "9121"
66+
prometheus.io/scrape: "true"
67+
redis.opstreelabs.in: "true"
68+
redis.opstreelabs.instance: redis-replication
69+
labels:
70+
app: redis-replication
71+
redis_setup_type: replication
72+
role: replication
73+
name: redis-replication-headless
74+
ownerReferences:
75+
- apiVersion: redis.redis.opstreelabs.in/v1beta2
76+
controller: true
77+
kind: RedisReplication
78+
name: redis-replication
79+
spec:
80+
clusterIP: None
81+
ports:
82+
- name: redis-client
83+
port: 6379
84+
protocol: TCP
85+
targetPort: 6379
86+
selector:
87+
app: redis-replication
88+
redis_setup_type: replication
89+
role: replication
90+
type: ClusterIP
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
apiVersion: redis.redis.opstreelabs.in/v1beta2
3+
kind: RedisReplication
4+
metadata:
5+
name: redis-replication
6+
spec:
7+
clusterSize: 3
8+
podSecurityContext:
9+
runAsUser: 1000
10+
fsGroup: 1000
11+
kubernetesConfig:
12+
image: quay.io/opstree/redis:latest
13+
imagePullPolicy: Always
14+
resources:
15+
requests:
16+
cpu: 101m
17+
memory: 128Mi
18+
limits:
19+
cpu: 101m
20+
memory: 128Mi
21+
redisSecret:
22+
name: redis-secret
23+
key: password
24+
storage:
25+
volumeClaimTemplate:
26+
spec:
27+
accessModes: ["ReadWriteOnce"]
28+
resources:
29+
requests:
30+
storage: 1Gi
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
apiVersion: v1
3+
kind: Secret
4+
metadata:
5+
name: redis-secret
6+
data:
7+
password: T3BzdHJlZUAxMjM0Cg==
8+
type: Opaque

tests/e2e-chainsaw/v1beta2/setup/redis-replication/chainsaw-test.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,44 @@ spec:
1616
- assert:
1717
file: ready-pvc.yaml
1818

19+
- name: Ping Replicated Cluster
20+
try:
21+
- script:
22+
timeout: 10s
23+
content: |
24+
kubectl exec --namespace ${NAMESPACE} redis-replication-0 -- redis-cli -p 6379 ping
25+
check:
26+
($stdout=='PONG'): true
27+
- script:
28+
timeout: 10s
29+
content: |
30+
kubectl exec --namespace ${NAMESPACE} redis-replication-1 -- redis-cli -p 6379 ping
31+
check:
32+
($stdout=='PONG'): true
33+
- script:
34+
timeout: 10s
35+
content: |
36+
kubectl exec --namespace ${NAMESPACE} redis-replication-2 -- redis-cli -p 6379 ping
37+
check:
38+
($stdout=='PONG'): true
39+
40+
- name: Try saving a key
41+
try:
42+
- script:
43+
timeout: 10s
44+
content: |
45+
kubectl exec --namespace ${NAMESPACE} redis-replication-0 -- redis-cli -p 6379 set foo-0 bar-0
46+
check:
47+
($stdout=='OK'): true
48+
# - script:
49+
# timeout: 10s
50+
# content: |
51+
# kubectl exec --namespace ${NAMESPACE} redis-replication-1 -- redis-cli -p 6379 set foo-1 bar-1
52+
# check:
53+
# ($stdout==`READONLY You can't write against a read only replica.`): true
54+
# - script:
55+
# timeout: 10s
56+
# content: |
57+
# kubectl exec --namespace ${NAMESPACE} redis-replication-2 -- redis-cli -p 6379 set foo-2 bar-2
58+
# check:
59+
# ($stdout==`READONLY You can't write against a read only replica.`): true

0 commit comments

Comments
 (0)