Skip to content

Commit d4a1798

Browse files
committed
antithesis: Configuration for 1 node cluster
Signed-off-by: joshjms <joshjms1607@gmail.com>
1 parent d37ff81 commit d4a1798

File tree

10 files changed

+144
-33
lines changed

10 files changed

+144
-33
lines changed

tests/antithesis/Dockerfile.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ FROM golang:$GO_VERSION AS build
44
RUN go install github.com/a8m/envsubst/cmd/envsubst@v1.4.3
55

66
ARG IMAGE_TAG
7-
COPY docker-compose.yml /docker-compose.yml.template
7+
ARG NODE_COUNT
8+
COPY docker-compose-${NODE_COUNT}-node.yml /docker-compose.yml.template
89
RUN IMAGE_TAG=${IMAGE_TAG} cat /docker-compose.yml.template | envsubst > /docker-compose.yml
910

1011
FROM scratch

tests/antithesis/Makefile

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@ ARCH ?= $(shell go env GOARCH)
55
REF = main
66
IMAGE_TAG = latest
77

8+
CFG_NODE_COUNT ?= 3
9+
810
.PHONY: antithesis-build-client-docker-image
9-
antithesis-build-client-docker-image:
10-
docker build --build-arg GO_VERSION=$(shell cat $(REPOSITORY_ROOT)/.go-version) -f $(REPOSITORY_ROOT)/tests/antithesis/test-template/Dockerfile $(REPOSITORY_ROOT) -t etcd-client:latest
11+
antithesis-build-client-docker-image: validate-node-count
12+
docker build \
13+
--build-arg GO_VERSION=$(shell cat $(REPOSITORY_ROOT)/.go-version) \
14+
--build-arg CFG_NODE_COUNT=$(CFG_NODE_COUNT) \
15+
-f $(REPOSITORY_ROOT)/tests/antithesis/test-template/Dockerfile $(REPOSITORY_ROOT) -t etcd-client:latest
1116

1217
.PHONY: antithesis-build-etcd-image
1318
antithesis-build-etcd-image:
@@ -30,30 +35,39 @@ antithesis-build-etcd-image-main: REF=main
3035
antithesis-build-etcd-image-main: antithesis-build-etcd-image
3136

3237
.PHONY: antithesis-build-config-image
33-
antithesis-build-config-image:
34-
docker build -f ./Dockerfile.config . -t etcd-config:latest --build-arg IMAGE_TAG=$(IMAGE_TAG)
38+
antithesis-build-config-image: validate-node-count
39+
docker build -f ./Dockerfile.config . -t etcd-config:latest \
40+
--build-arg IMAGE_TAG=$(IMAGE_TAG) \
41+
--build-arg NODE_COUNT=$(CFG_NODE_COUNT)
3542

3643
.PHONY: antithesis-docker-compose-up
37-
antithesis-docker-compose-up:
38-
export USER_ID=$(USER_ID) && export GROUP_ID=$(GROUP_ID) && docker-compose up
44+
antithesis-docker-compose-up: validate-node-count
45+
export USER_ID=$(USER_ID) && export GROUP_ID=$(GROUP_ID) && docker compose -f docker-compose-$(CFG_NODE_COUNT)-node.yml up
3946

4047
.PHONY: antithesis-run-container-traffic
41-
antithesis-run-container-traffic:
42-
export USER_ID=$(USER_ID) && export GROUP_ID=$(GROUP_ID) && docker-compose exec client /opt/antithesis/test/v1/robustness/singleton_driver_traffic
48+
antithesis-run-container-traffic: validate-node-count
49+
export USER_ID=$(USER_ID) && export GROUP_ID=$(GROUP_ID) && docker compose -f docker-compose-$(CFG_NODE_COUNT)-node.yml exec client /opt/antithesis/test/v1/robustness/singleton_driver_traffic
4350

4451
.PHONY: antithesis-run-container-validation
45-
antithesis-run-container-validation:
46-
export USER_ID=$(USER_ID) && export GROUP_ID=$(GROUP_ID) && docker-compose exec client /opt/antithesis/test/v1/robustness/finally_validation
52+
antithesis-run-container-validation: validate-node-count
53+
export USER_ID=$(USER_ID) && export GROUP_ID=$(GROUP_ID) && docker compose -f docker-compose-$(CFG_NODE_COUNT)-node.yml exec client /opt/antithesis/test/v1/robustness/finally_validation
4754

4855
.PHONY: antithesis-run-local-traffic
4956
antithesis-run-local-traffic:
50-
go run --race ./test-template/robustness/traffic/main.go --local
57+
go run -ldflags "-X main.NodeCount=$(CFG_NODE_COUNT)" --race ./test-template/robustness/traffic/main.go --local
5158

5259
.PHONY: antithesis-run-local-validation
5360
antithesis-run-local-validation:
54-
go run --race ./test-template/robustness/finally/main.go --local
61+
go run -ldflags "-X main.NodeCount=$(CFG_NODE_COUNT)" --race ./test-template/robustness/finally/main.go --local
5562

5663
.PHONY: antithesis-clean
57-
antithesis-clean:
58-
export USER_ID=$(USER_ID) && export GROUP_ID=$(GROUP_ID) && docker-compose down
64+
antithesis-clean: validate-node-count
65+
export USER_ID=$(USER_ID) && export GROUP_ID=$(GROUP_ID) && docker compose -f docker-compose-$(CFG_NODE_COUNT)-node.yml down --remove-orphans
5966
rm -rf /tmp/etcddata0 /tmp/etcddata1 /tmp/etcddata2 /tmp/etcdreport
67+
68+
.PHONY: validate-node-count
69+
validate-node-count:
70+
@if [ "$(CFG_NODE_COUNT)" != "1" ] && [ "$(CFG_NODE_COUNT)" != "3" ]; then \
71+
echo "CFG_NODE_COUNT must be either 1 or 3 (got $(CFG_NODE_COUNT))"; \
72+
exit 1; \
73+
fi
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
services:
3+
# This is needed for creating non-root data folders on host.
4+
# By default, if the folders don't exist when mounting, compose creates them with root as owner.
5+
# With root owner, accessing the WAL files from local tests will fail due to an unauthorized access error.
6+
init:
7+
image: 'docker.io/library/ubuntu:latest'
8+
user: root
9+
group_add:
10+
- '${GROUP_ID:-root}'
11+
volumes:
12+
- ${ETCD_ROBUSTNESS_DATA_PATH:-/tmp/etcddata}0:/var/etcddata0
13+
- ${ETCD_ROBUSTNESS_REPORT_PATH:-/tmp/etcdreport}:/var/report
14+
command:
15+
- /bin/sh
16+
- -c
17+
- |
18+
rm -rf /var/etcddata0/* /var/report/*
19+
chown -R ${USER_ID:-root}:${GROUP_ID:-root} /var/etcddata0 /var/report
20+
21+
etcd0:
22+
image: 'etcd-server:${IMAGE_TAG:-latest}'
23+
container_name: etcd0
24+
hostname: etcd0
25+
environment:
26+
ETCD_NAME: "etcd0"
27+
ETCD_INITIAL_ADVERTISE_PEER_URLS: "http://etcd0:2380"
28+
ETCD_LISTEN_PEER_URLS: "http://0.0.0.0:2380"
29+
ETCD_LISTEN_CLIENT_URLS: "http://0.0.0.0:2379"
30+
ETCD_ADVERTISE_CLIENT_URLS: "http://etcd0.etcd:2379"
31+
ETCD_INITIAL_CLUSTER_TOKEN: "etcd-cluster-1"
32+
ETCD_INITIAL_CLUSTER: "etcd0=http://etcd0:2380"
33+
ETCD_INITIAL_CLUSTER_STATE: "new"
34+
ETCD_DATA_DIR: "/var/etcd/data"
35+
user: "${USER_ID:-root}:${GROUP_ID:-root}"
36+
depends_on:
37+
init:
38+
condition: service_completed_successfully
39+
ports:
40+
- 12379:2379
41+
volumes:
42+
- ${ETCD_ROBUSTNESS_DATA_PATH:-/tmp/etcddata}0:/var/etcd/data
43+
44+
client:
45+
image: 'etcd-client:${IMAGE_TAG:-latest}'
46+
container_name: client
47+
entrypoint: ["/opt/antithesis/entrypoint/entrypoint"]
48+
user: "${USER_ID:-root}:${GROUP_ID:-root}"
49+
depends_on:
50+
etcd0:
51+
condition: service_started
52+
volumes:
53+
- ${ETCD_ROBUSTNESS_DATA_PATH:-/tmp/etcddata}0:/var/etcddata0
54+
- ${ETCD_ROBUSTNESS_REPORT_PATH:-/tmp/etcdreport}:/var/report

tests/antithesis/test-template/Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ ARG GO_VERSION=1.24.4
22
ARG ARCH=amd64
33

44
FROM golang:$GO_VERSION
5+
ARG CFG_NODE_COUNT=3
56
WORKDIR /build
67
COPY . .
78

89
WORKDIR /build/tests
9-
RUN go build -o /opt/antithesis/entrypoint/entrypoint -race ./antithesis/test-template/entrypoint/main.go
10-
RUN go build -o /opt/antithesis/test/v1/robustness/singleton_driver_traffic -race ./antithesis/test-template/robustness/traffic/main.go
11-
RUN go build -o /opt/antithesis/test/v1/robustness/finally_validation -race ./antithesis/test-template/robustness/finally/main.go
10+
RUN go build -ldflags "-X main.NodeCount=$CFG_NODE_COUNT" -o /opt/antithesis/entrypoint/entrypoint -race ./antithesis/test-template/entrypoint/main.go
11+
RUN go build -ldflags "-X main.NodeCount=$CFG_NODE_COUNT" -o /opt/antithesis/test/v1/robustness/singleton_driver_traffic -race ./antithesis/test-template/robustness/traffic/main.go
12+
RUN go build -ldflags "-X main.NodeCount=$CFG_NODE_COUNT" -o /opt/antithesis/test/v1/robustness/finally_validation -race ./antithesis/test-template/robustness/finally/main.go

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,19 @@ import (
2424
"github.com/antithesishq/antithesis-sdk-go/lifecycle"
2525

2626
clientv3 "go.etcd.io/etcd/client/v3"
27+
"go.etcd.io/etcd/tests/v3/antithesis/test-template/robustness/common"
2728
)
2829

2930
// Sleep duration
3031
const SLEEP = 10
3132

33+
var NodeCount = "3"
34+
3235
// CheckHealth checks health of all etcd nodes
3336
func CheckHealth() bool {
34-
nodeOptions := []string{"etcd0", "etcd1", "etcd2"}
37+
cfg := common.MakeConfig(NodeCount)
38+
39+
nodeOptions := []string{"etcd0", "etcd1", "etcd2"}[:cfg.NodeCount]
3540

3641
// iterate over each node and check health
3742
for _, node := range nodeOptions {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2025 The etcd Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package common
16+
17+
import "strconv"
18+
19+
type Config struct {
20+
NodeCount int
21+
}
22+
23+
func MakeConfig(nodeCount string) *Config {
24+
cfg := &Config{}
25+
26+
cfg.NodeCount, _ = strconv.Atoi(nodeCount)
27+
28+
return cfg
29+
}

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,23 @@ const (
3838
localReportPath = "report"
3939
)
4040

41-
func DefaultPaths() (string, []string, map[string]string) {
42-
hosts := []string{defaultetcd0, defaultetcd1, defaultetcd2}
43-
reportPath := defaultReportPath
44-
dataPaths := etcdDataPaths(defaultetcdDataPath, len(hosts))
45-
return reportPath, hosts, dataPaths
41+
func DefaultPaths(cfg *Config) (hosts []string, reportPath string, dataPaths map[string]string) {
42+
hosts = []string{defaultetcd0, defaultetcd1, defaultetcd2}[:cfg.NodeCount]
43+
reportPath = defaultReportPath
44+
dataPaths = etcdDataPaths(defaultetcdDataPath, cfg.NodeCount)
45+
return hosts, reportPath, dataPaths
4646
}
4747

48-
func LocalPaths() (string, []string, map[string]string) {
49-
hosts := []string{localetcd0, localetcd1, localetcd2}
50-
reportPath := localReportPath
48+
func LocalPaths(cfg *Config) (hosts []string, reportPath string, dataPaths map[string]string) {
49+
hosts = []string{localetcd0, localetcd1, localetcd2}[:cfg.NodeCount]
50+
reportPath = localReportPath
5151
etcdDataPath := defaultetcdLocalDataPath
5252
envPath := os.Getenv(localetcdDataPathEnv)
5353
if envPath != "" {
5454
etcdDataPath = envPath + "%d"
5555
}
56-
dataPaths := etcdDataPaths(etcdDataPath, len(hosts))
57-
return reportPath, hosts, dataPaths
56+
dataPaths = etcdDataPaths(etcdDataPath, cfg.NodeCount)
57+
return hosts, reportPath, dataPaths
5858
}
5959

6060
func etcdDataPaths(dir string, amount int) map[string]string {

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,17 @@ const (
3535
reportFileName = "history.html"
3636
)
3737

38+
var NodeCount = "3"
39+
3840
func main() {
3941
local := flag.Bool("local", false, "run finally locally and connect to etcd instances via localhost")
4042
flag.Parse()
4143

42-
reportPath, _, dirs := common.DefaultPaths()
44+
cfg := common.MakeConfig(NodeCount)
45+
46+
_, reportPath, dirs := common.DefaultPaths(cfg)
4347
if *local {
44-
reportPath, _, dirs = common.LocalPaths()
48+
_, reportPath, dirs = common.LocalPaths(cfg)
4549
}
4650

4751
lg, err := zap.NewProduction()

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,18 @@ var (
5454
traffic.EtcdPutDeleteLease,
5555
traffic.Kubernetes,
5656
}
57+
NodeCount = "3"
5758
)
5859

5960
func main() {
6061
local := flag.Bool("local", false, "run tests locally and connect to etcd instances via localhost")
6162
flag.Parse()
6263

63-
reportPath, hosts, etcdetcdDataPaths := common.DefaultPaths()
64+
cfg := common.MakeConfig(NodeCount)
65+
66+
hosts, reportPath, etcdetcdDataPaths := common.DefaultPaths(cfg)
6467
if *local {
65-
reportPath, hosts, etcdetcdDataPaths = common.LocalPaths()
68+
hosts, reportPath, etcdetcdDataPaths = common.LocalPaths(cfg)
6669
}
6770

6871
ctx := context.Background()

0 commit comments

Comments
 (0)