Skip to content

Commit 59e9c68

Browse files
committed
[ISSUE #190] add e2e test workflow on pr request
1 parent 9752d8c commit 59e9c68

File tree

11 files changed

+1076
-9
lines changed

11 files changed

+1076
-9
lines changed

.github/workflows/e2e.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: E2E tests
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
8+
jobs:
9+
test:
10+
name: ${{ matrix.testpath }}
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
testpath:
15+
- ./tests/e2e/v1alpha1/setup/
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v3
20+
21+
- name: Build Dockerfile
22+
run: docker build . --file Dockerfile --tag rocketmq-operator:e2e
23+
24+
- name: Install Chainsaw
25+
run: |
26+
curl -L https://github.com/kyverno/chainsaw/releases/download/v0.1.2/chainsaw_linux_amd64.tar.gz -o chainsaw.tar.gz
27+
tar -xzf chainsaw.tar.gz
28+
sudo mv chainsaw /usr/local/bin/
29+
chainsaw version
30+
31+
- name: Create k8s Kind Cluster
32+
run: |
33+
# install kubectl
34+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
35+
chmod +x kubectl
36+
sudo mv kubectl /usr/local/bin/
37+
38+
# install kind
39+
curl -LO https://github.com/kubernetes-sigs/kind/releases/download/v0.20.0/kind-linux-amd64
40+
sudo chmod +x kind-linux-amd64
41+
sudo mv kind-linux-amd64 /usr/local/bin/kind
42+
kind version
43+
44+
# create kind cluster
45+
kind_node_image="kindest/node:v1.23.17"
46+
echo "Kubernetes version: ${kind_node_image}"
47+
kind create cluster --config tests/_config/kind-config.yaml
48+
kubectl version
49+
kubectl get all --all-namespaces
50+
51+
- name: Load Docker image into Kind
52+
run: |
53+
kubectl cluster-info --context kind-kind
54+
kind load docker-image rocketmq-operator:e2e --name kind
55+
56+
- name: Install RocketMQ Operator
57+
run: |
58+
make deploy
59+
kubectl set image deployment/rocketmq-operator manager=rocketmq-operator:e2e -n default
60+
61+
- name: Wait for RocketMQ Operator to be ready
62+
run: |
63+
kubectl wait --for=condition=available --timeout=300s deployment/rocketmq-operator -n default
64+
65+
- name: Run chainsaw test
66+
run: chainsaw test --test-dir ${{ matrix.testpath }} --config tests/_config/chainsaw-configuration.yaml

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ tags
8787

8888
**/*.zip
8989
**/zz_generated.openapi.go
90-
**/*.sum
91-
*.sum
9290

9391

9492
bin

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ RUN set -eux; \
3131
apk add --virtual .build-deps curl gnupg unzip; \
3232
curl https://archive.apache.org/dist/rocketmq/${ROCKETMQ_VERSION}/rocketmq-all-${ROCKETMQ_VERSION}-bin-release.zip -o rocketmq.zip; \
3333
curl https://archive.apache.org/dist/rocketmq/${ROCKETMQ_VERSION}/rocketmq-all-${ROCKETMQ_VERSION}-bin-release.zip.asc -o rocketmq.zip.asc; \
34-
curl -L https://www.apache.org/dist/rocketmq/KEYS -o KEYS; \
34+
curl -L https://downloads.apache.org/rocketmq//KEYS -o KEYS; \
3535
gpg --import KEYS; \
3636
gpg --batch --verify rocketmq.zip.asc rocketmq.zip; \
3737
unzip rocketmq.zip; \

Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,28 +166,28 @@ undeploy: uninstall ## Undeploy controller from the K8s cluster specified in ~/.
166166
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
167167
.PHONY: controller-gen
168168
controller-gen: ## Download controller-gen locally if necessary.
169-
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])
169+
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])
170170

171171
KUSTOMIZE = $(shell pwd)/bin/kustomize
172172
.PHONY: kustomize
173173
kustomize: ## Download kustomize locally if necessary.
174-
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])
174+
$(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])
175175

176176
ENVTEST = $(shell pwd)/bin/setup-envtest
177177
.PHONY: envtest
178178
envtest: ## Download envtest-setup locally if necessary.
179-
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
179+
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
180180

181-
# go-get-tool will 'go get' any package $2 and install it to $1.
181+
# go-install-tool will 'go install' any package $2 and install it to $1.
182182
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
183-
define go-get-tool
183+
define go-install-tool
184184
@[ -f $(1) ] || { \
185185
set -e ;\
186186
TMP_DIR=$$(mktemp -d) ;\
187187
cd $$TMP_DIR ;\
188188
go mod init tmp ;\
189189
echo "Downloading $(2)" ;\
190-
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
190+
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
191191
rm -rf $$TMP_DIR ;\
192192
}
193193
endef

go.sum

Lines changed: 783 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/configuration-chainsaw-v1alpha1.json
2+
3+
apiVersion: chainsaw.kyverno.io/v1alpha1
4+
kind: Configuration
5+
metadata:
6+
name: chainsaw-configuration
7+
spec:
8+
namespace: default
9+
delayBeforeCleanup: 10s
10+
timeouts:
11+
apply: 5m
12+
delete: 5m
13+
assert: 15m
14+
error: 15m

tests/_config/kind-config.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
kind: Cluster
2+
apiVersion: kind.x-k8s.io/v1alpha4
3+
name: kind
4+
nodes:
5+
- role: control-plane
6+
- role: worker
7+
- role: worker
8+
- role: worker
9+
- role: worker
10+
- role: worker
11+
- role: worker
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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: rocketmq-cluster
7+
spec:
8+
steps:
9+
- name: Create RocketMQ Cluster
10+
try:
11+
- apply:
12+
file: cluster.yaml
13+
- assert:
14+
file: ready-cluster.yaml
15+
- assert:
16+
file: ready-sts.yaml
17+
18+
- name: Sleep for five minutes
19+
try:
20+
- sleep:
21+
duration: 5m
22+
23+
- name: Check Cluster by Name Server
24+
try:
25+
- script:
26+
content: |
27+
kubectl exec --namespace ${NAMESPACE} --container name-service name-service-0 -- ./mqadmin clusterList -n 127.0.0.1:9876 2>/dev/null | grep 'broker' | wc -l
28+
check:
29+
($stdout=='2'): true
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: broker-config
5+
namespace: default
6+
data:
7+
# BROKER_MEM sets the broker JVM, if set to "" then Xms = Xmx = max(min(1/2 ram, 1024MB), min(1/4 ram, 8GB))
8+
BROKER_MEM: " -Xms2g -Xmx2g -Xmn1g "
9+
broker-common.conf: |
10+
# brokerClusterName, brokerName, brokerId are automatically generated by the operator and do not set it manually!!!
11+
deleteWhen=04
12+
fileReservedTime=48
13+
flushDiskType=ASYNC_FLUSH
14+
# set brokerRole to ASYNC_MASTER or SYNC_MASTER. DO NOT set to SLAVE because the replica instance will automatically be set!!!
15+
brokerRole=ASYNC_MASTER
16+
---
17+
apiVersion: rocketmq.apache.org/v1alpha1
18+
kind: Broker
19+
metadata:
20+
name: broker
21+
namespace: default
22+
spec:
23+
size: 1
24+
nameServers: ""
25+
replicaPerGroup: 1
26+
brokerImage: apacherocketmq/rocketmq-broker:4.5.0-alpine-operator-0.3.0
27+
imagePullPolicy: Always
28+
resources:
29+
requests:
30+
memory: "2048Mi"
31+
cpu: "250m"
32+
limits:
33+
memory: "12288Mi"
34+
cpu: "500m"
35+
allowRestart: true
36+
storageMode: StorageClass
37+
hostPath: /data/rocketmq/broker
38+
scalePodName: broker-0-master-0
39+
env:
40+
- name: BROKER_MEM
41+
valueFrom:
42+
configMapKeyRef:
43+
name: broker-config
44+
key: BROKER_MEM
45+
volumes:
46+
- name: broker-config
47+
configMap:
48+
name: broker-config
49+
items:
50+
- key: broker-common.conf
51+
path: broker-common.conf
52+
volumeClaimTemplates:
53+
- metadata:
54+
name: broker-storage
55+
spec:
56+
accessModes:
57+
- ReadWriteOnce
58+
resources:
59+
requests:
60+
storage: 8Gi
61+
---
62+
apiVersion: rocketmq.apache.org/v1alpha1
63+
kind: NameService
64+
metadata:
65+
name: name-service
66+
namespace: default
67+
spec:
68+
size: 1
69+
nameServiceImage: apacherocketmq/rocketmq-nameserver:4.5.0-alpine-operator-0.3.0
70+
imagePullPolicy: Always
71+
hostNetwork: false
72+
dnsPolicy: ClusterFirstWithHostNet
73+
resources:
74+
requests:
75+
memory: "512Mi"
76+
cpu: "250m"
77+
limits:
78+
memory: "1024Mi"
79+
cpu: "500m"
80+
storageMode: StorageClass
81+
hostPath: /data/rocketmq/broker
82+
volumeClaimTemplates:
83+
- metadata:
84+
name: namesrv-storage
85+
spec:
86+
accessModes:
87+
- ReadWriteOnce
88+
resources:
89+
requests:
90+
storage: 1Gi
91+
---
92+
apiVersion: rocketmq.apache.org/v1alpha1
93+
kind: Console
94+
metadata:
95+
name: console
96+
namespace: default
97+
spec:
98+
nameServers: ""
99+
consoleDeployment:
100+
apiVersion: apps/v1
101+
kind: Deployment
102+
metadata:
103+
labels:
104+
app: rocketmq-console
105+
spec:
106+
replicas: 1
107+
selector:
108+
matchLabels:
109+
app: rocketmq-console
110+
template:
111+
metadata:
112+
labels:
113+
app: rocketmq-console
114+
spec:
115+
containers:
116+
- name: console
117+
image: apacherocketmq/rocketmq-console:2.0.0
118+
ports:
119+
- containerPort: 8080
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: rocketmq.apache.org/v1alpha1
2+
kind: Broker
3+
metadata:
4+
name: broker
5+
namespace: default
6+
status:
7+
nodes:
8+
- broker-0-master-0
9+
- broker-0-replica-1-0
10+
size: 1

0 commit comments

Comments
 (0)