Skip to content

Commit 1fbe07e

Browse files
author
Nont
committed
Add the client part for k8s antithesis
Signed-off-by: Nont <[email protected]>
1 parent 2ea4aef commit 1fbe07e

File tree

8 files changed

+163
-17
lines changed

8 files changed

+163
-17
lines changed

tests/antithesis/README.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ docker images | grep etcd-client
2929

3030
It should show something like:
3131

32-
```
32+
```bash
3333
etcd-client latest <IMAGE_ID> <DATE>
3434
```
3535

@@ -45,7 +45,7 @@ The command uses the etcd client and server images built from step 1.
4545

4646
The client will continuously check the health of the etcd nodes and print logs similar to:
4747

48-
```
48+
```bash
4949
[+] Running 4/4
5050
✔ Container etcd0 Created 0.0s
5151
✔ Container etcd2 Created 0.0s
@@ -151,6 +151,33 @@ If you use something other than `kind`, please make sure the images are accessib
151151
kubectl apply -f ./config/manifests
152152
```
153153

154+
#### 4. Run the driver(s)
155+
156+
First, locate your client pod, which should be named with prefix client when you execute `kubectl get pods`.
157+
158+
```bash
159+
> kubectl get pods
160+
NAME READY STATUS RESTARTS AGE
161+
client-6b9885f69b-dcndw 1/1 Running 0 10m
162+
etcd-0 1/1 Running 0 10m
163+
etcd-1 1/1 Running 0 10m
164+
etcd-2 1/1 Running 0 10m
165+
```
166+
167+
With the pod name, you can execute the traffic and validation commands:
168+
169+
```bash
170+
# Traffic generation
171+
kubectl exec -it client-6b9885f69b-dcndw -- /opt/antithesis/test/v1/robustness/single_driver_traffic
172+
173+
# Collecting results and compiling the reports
174+
kubectl exec -it client-6b9885f69b-dcndw -- /opt/antithesis/test/v1/robustness/finally_validation
175+
```
176+
177+
##### Making changes and retests
178+
179+
If you make changes to the client or server, you will have to rebuild the images and load them into the cluster again. You can use the same commands as in step 2. Once that the images are loaded, you can delete the existing pods to force kubernetes to create new ones with the updated images:
180+
154181
### Tearing down the cluster
155182

156183
```bash

tests/antithesis/config/docker-compose-1-node.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ services:
99
group_add:
1010
- '${GROUP_ID:-root}'
1111
volumes:
12-
- ${ETCD_ROBUSTNESS_DATA_PATH:-/tmp/etcddata}0:/var/etcddata0
12+
- ${ETCD_ROBUSTNESS_LOCAL_DATA_PATH:-/tmp/etcddata}0:/var/etcddata0
1313
- ${ETCD_ROBUSTNESS_REPORT_PATH:-/tmp/etcdreport}:/var/report
1414
command:
1515
- /bin/sh
@@ -43,7 +43,7 @@ services:
4343
ports:
4444
- 12379:2379
4545
volumes:
46-
- ${ETCD_ROBUSTNESS_DATA_PATH:-/tmp/etcddata}0:/var/etcd/data
46+
- ${ETCD_ROBUSTNESS_LOCAL_DATA_PATH:-/tmp/etcddata}0:/var/etcd/data
4747

4848
client:
4949
image: 'etcd-client:${IMAGE_TAG:-latest}'
@@ -54,5 +54,5 @@ services:
5454
etcd0:
5555
condition: service_started
5656
volumes:
57-
- ${ETCD_ROBUSTNESS_DATA_PATH:-/tmp/etcddata}0:/var/etcddata0
57+
- ${ETCD_ROBUSTNESS_LOCAL_DATA_PATH:-/tmp/etcddata}0:/var/etcddata0
5858
- ${ETCD_ROBUSTNESS_REPORT_PATH:-/tmp/etcdreport}:/var/report

tests/antithesis/config/docker-compose-3-node.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ services:
99
group_add:
1010
- '${GROUP_ID:-root}'
1111
volumes:
12-
- ${ETCD_ROBUSTNESS_DATA_PATH:-/tmp/etcddata}0:/var/etcddata0
13-
- ${ETCD_ROBUSTNESS_DATA_PATH:-/tmp/etcddata}1:/var/etcddata1
14-
- ${ETCD_ROBUSTNESS_DATA_PATH:-/tmp/etcddata}2:/var/etcddata2
12+
- ${ETCD_ROBUSTNESS_LOCAL_DATA_PATH:-/tmp/etcddata}0:/var/etcddata0
13+
- ${ETCD_ROBUSTNESS_LOCAL_DATA_PATH:-/tmp/etcddata}1:/var/etcddata1
14+
- ${ETCD_ROBUSTNESS_LOCAL_DATA_PATH:-/tmp/etcddata}2:/var/etcddata2
1515
- ${ETCD_ROBUSTNESS_REPORT_PATH:-/tmp/etcdreport}:/var/report
1616
command:
1717
- /bin/sh
@@ -45,7 +45,7 @@ services:
4545
ports:
4646
- 12379:2379
4747
volumes:
48-
- ${ETCD_ROBUSTNESS_DATA_PATH:-/tmp/etcddata}0:/var/etcd/data
48+
- ${ETCD_ROBUSTNESS_LOCAL_DATA_PATH:-/tmp/etcddata}0:/var/etcd/data
4949

5050
etcd1:
5151
image: 'etcd-server:${IMAGE_TAG:-latest}'
@@ -72,7 +72,7 @@ services:
7272
ports:
7373
- 22379:2379
7474
volumes:
75-
- ${ETCD_ROBUSTNESS_DATA_PATH:-/tmp/etcddata}1:/var/etcd/data
75+
- ${ETCD_ROBUSTNESS_LOCAL_DATA_PATH:-/tmp/etcddata}1:/var/etcd/data
7676

7777
etcd2:
7878
image: 'etcd-server:${IMAGE_TAG:-latest}'
@@ -99,7 +99,7 @@ services:
9999
ports:
100100
- 32379:2379
101101
volumes:
102-
- ${ETCD_ROBUSTNESS_DATA_PATH:-/tmp/etcddata}2:/var/etcd/data
102+
- ${ETCD_ROBUSTNESS_LOCAL_DATA_PATH:-/tmp/etcddata}2:/var/etcd/data
103103

104104
client:
105105
image: 'etcd-client:${IMAGE_TAG:-latest}'
@@ -114,7 +114,7 @@ services:
114114
etcd2:
115115
condition: service_started
116116
volumes:
117-
- ${ETCD_ROBUSTNESS_DATA_PATH:-/tmp/etcddata}0:/var/etcddata0
118-
- ${ETCD_ROBUSTNESS_DATA_PATH:-/tmp/etcddata}1:/var/etcddata1
119-
- ${ETCD_ROBUSTNESS_DATA_PATH:-/tmp/etcddata}2:/var/etcddata2
117+
- ${ETCD_ROBUSTNESS_LOCAL_DATA_PATH:-/tmp/etcddata}0:/var/etcddata0
118+
- ${ETCD_ROBUSTNESS_LOCAL_DATA_PATH:-/tmp/etcddata}1:/var/etcddata1
119+
- ${ETCD_ROBUSTNESS_LOCAL_DATA_PATH:-/tmp/etcddata}2:/var/etcddata2
120120
- ${ETCD_ROBUSTNESS_REPORT_PATH:-/tmp/etcdreport}:/var/report

tests/antithesis/config/manifests/default-etcd-3-replicas.yaml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,66 @@ spec:
101101
resources:
102102
requests:
103103
storage: 200Mi
104+
---
105+
apiVersion: v1
106+
kind: PersistentVolumeClaim
107+
metadata:
108+
name: report
109+
spec:
110+
accessModes:
111+
- ReadWriteOnce
112+
resources:
113+
requests:
114+
storage: 500Mi
115+
storageClassName: standard
116+
---
117+
apiVersion: apps/v1
118+
kind: Deployment
119+
metadata:
120+
name: client
121+
labels:
122+
app: client
123+
spec:
124+
replicas: 1
125+
selector:
126+
matchLabels:
127+
app: client
128+
template:
129+
metadata:
130+
labels:
131+
app: client
132+
spec:
133+
containers:
134+
- name: etcd-client
135+
image: etcd-client:latest
136+
command: ["/opt/antithesis/entrypoint/entrypoint"]
137+
imagePullPolicy: Never
138+
env:
139+
- name: ETCD_ROBUSTNESS_SERVER_ENDPOINTS
140+
value: "etcd-0.etcd.default.svc.cluster.local:2379,etcd-1.etcd.default.svc.cluster.local:2379,etcd-2.etcd.default.svc.cluster.local:2379"
141+
- name: ETCD_ROBUSTNESS_DATA_PATHS
142+
value: "/var/etcddata-0,/var/etcddata-1,/var/etcddata-2"
143+
- name: ETCD_ROBUSTNESS_REPORT_PATH
144+
value: "/var/report/"
145+
volumeMounts:
146+
- name: etcd-0
147+
mountPath: /var/etcddata-0
148+
- name: etcd-1
149+
mountPath: /var/etcddata-1
150+
- name: etcd-2
151+
mountPath: /var/etcddata-2
152+
- name: report
153+
mountPath: /var/report/
154+
volumes:
155+
- name: etcd-0
156+
persistentVolumeClaim:
157+
claimName: data-etcd-0
158+
- name: etcd-1
159+
persistentVolumeClaim:
160+
claimName: data-etcd-1
161+
- name: etcd-2
162+
persistentVolumeClaim:
163+
claimName: data-etcd-2
164+
- name: report
165+
persistentVolumeClaim:
166+
claimName: report

tests/antithesis/test-template/entrypoint/main.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,23 @@ var NodeCount = "3"
3636
func CheckHealth() bool {
3737
cfg := common.MakeConfig(NodeCount)
3838

39+
var hosts []string
3940
nodeOptions := []string{"etcd0", "etcd1", "etcd2"}[:cfg.NodeCount]
41+
for _, n := range nodeOptions {
42+
hosts = append(hosts, fmt.Sprintf("%s:2379", n))
43+
}
44+
45+
// override hosts if environment variable is set
46+
h, _, _ := common.PathsFromEnv()
47+
if len(h) > 0 {
48+
hosts = h
49+
}
4050

4151
// iterate over each node and check health
42-
for _, node := range nodeOptions {
52+
for _, node := range hosts {
53+
fmt.Printf("Client [entrypoint]: checking connection with %s\n", node)
4354
cli, err := clientv3.New(clientv3.Config{
44-
Endpoints: []string{fmt.Sprintf("http://%s:2379", node)},
55+
Endpoints: []string{node},
4556
DialTimeout: 5 * time.Second,
4657
})
4758
if err != nil {

tests/antithesis/test-template/robustness/common/path.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package common
1919
import (
2020
"fmt"
2121
"os"
22+
"strings"
2223
)
2324

2425
const (
@@ -34,8 +35,12 @@ const (
3435
localetcd2 = "127.0.0.1:32379"
3536
// used by default when running the client locally
3637
defaultetcdLocalDataPath = "/tmp/etcddata%d"
37-
localetcdDataPathEnv = "ETCD_ROBUSTNESS_DATA_PATH"
38+
localetcdDataPathEnv = "ETCD_ROBUSTNESS_LOCAL_DATA_PATH"
3839
localReportPath = "report"
40+
41+
serverEndpointEnv = "ETCD_ROBUSTNESS_SERVER_ENDPOINTS"
42+
dataPathEnv = "ETCD_ROBUSTNESS_DATA_PATHS"
43+
reportPathEnv = "ETCD_ROBUSTNESS_REPORT_PATH"
3944
)
4045

4146
func DefaultPaths(cfg *Config) (hosts []string, reportPath string, dataPaths map[string]string) {
@@ -64,3 +69,20 @@ func etcdDataPaths(dir string, amount int) map[string]string {
6469
}
6570
return dataPaths
6671
}
72+
73+
func PathsFromEnv() (hosts []string, reportPath string, dataPaths map[string]string) {
74+
hosts = strings.Split(os.Getenv(serverEndpointEnv), ",")
75+
d := strings.Split(os.Getenv(dataPathEnv), ",")
76+
77+
if len(hosts) != len(d) {
78+
panic("The number of endpoints and data paths must be equal")
79+
}
80+
81+
dataPaths = make(map[string]string)
82+
for i := range hosts {
83+
dataPaths[hosts[i]] = d[i]
84+
}
85+
reportPath = os.Getenv(reportPathEnv)
86+
87+
return hosts, reportPath, dataPaths
88+
}

tests/antithesis/test-template/robustness/finally/main.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ func main() {
4545
cfg := common.MakeConfig(NodeCount)
4646

4747
_, reportPath, dirs := common.DefaultPaths(cfg)
48+
49+
// override paths if environment variables are set
50+
_, rp, d := common.PathsFromEnv()
51+
if rp != "" {
52+
reportPath = rp
53+
}
54+
if len(d) > 0 {
55+
dirs = d
56+
}
57+
4858
if *local {
4959
_, reportPath, dirs = common.LocalPaths(cfg)
5060
}

tests/antithesis/test-template/robustness/traffic/main.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,19 @@ func main() {
6565
cfg := common.MakeConfig(NodeCount)
6666

6767
hosts, reportPath, etcdetcdDataPaths := common.DefaultPaths(cfg)
68+
69+
// override paths if environment variables are set
70+
h, rp, d := common.PathsFromEnv()
71+
if len(h) > 0 {
72+
hosts = h
73+
}
74+
if rp != "" {
75+
reportPath = rp
76+
}
77+
if len(d) > 0 {
78+
etcdetcdDataPaths = d
79+
}
80+
6881
if *local {
6982
hosts, reportPath, etcdetcdDataPaths = common.LocalPaths(cfg)
7083
}

0 commit comments

Comments
 (0)