Skip to content

Commit a76cef6

Browse files
author
Paulo Gomes
committed
Extract e2e tests from github actions
Enable users to run the exact same tests locally as they would be executed as part of their PRs. Signed-off-by: Paulo Gomes <[email protected]>
1 parent 97d7a6a commit a76cef6

File tree

4 files changed

+129
-72
lines changed

4 files changed

+129
-72
lines changed

.github/workflows/e2e.yaml

Lines changed: 3 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -43,76 +43,8 @@ jobs:
4343
echo 'run make test and commit changes'
4444
exit 1
4545
fi
46-
- name: Build container image
47-
run: make docker-build IMG=test/source-controller TAG=latest BUILD_PLATFORMS=linux/amd64 BUILD_ARGS=--load
48-
- name: Load test image
49-
run: kind load docker-image test/source-controller:latest
50-
- name: Deploy controller
51-
run: make dev-deploy IMG=test/source-controller TAG=latest
52-
- name: Run smoke tests
53-
run: |
54-
kubectl -n source-system apply -f ./config/samples
55-
kubectl -n source-system rollout status deploy/source-controller --timeout=1m
56-
kubectl -n source-system wait gitrepository/gitrepository-sample --for=condition=ready --timeout=1m
57-
kubectl -n source-system wait helmrepository/helmrepository-sample --for=condition=ready --timeout=1m
58-
kubectl -n source-system wait helmchart/helmchart-sample --for=condition=ready --timeout=1m
59-
kubectl -n source-system delete -f ./config/samples
60-
- name: Run HelmChart values file tests
61-
run: |
62-
kubectl -n source-system apply -f ./config/testdata/helmchart-valuesfile
63-
kubectl -n source-system wait helmchart/podinfo --for=condition=ready --timeout=5m
64-
kubectl -n source-system wait helmchart/podinfo-git --for=condition=ready --timeout=5m
65-
kubectl -n source-system delete -f ./config/testdata/helmchart-valuesfile
66-
- name: Setup Minio
46+
- name: Run E2E tests
6747
env:
6848
MINIO_VER: ${{ 'v6.3.1' }}
69-
run: |
70-
kubectl create ns minio
71-
helm repo add minio https://helm.min.io/
72-
helm upgrade --wait -i minio minio/minio \
73-
--version $MINIO_VER \
74-
--namespace minio \
75-
--set accessKey=myaccesskey \
76-
--set secretKey=mysecretkey \
77-
--set resources.requests.memory=128Mi \
78-
--set persistence.enable=false
79-
kubectl -n minio port-forward svc/minio 9000:9000 &>/dev/null &
80-
sleep 2
81-
wget -q https://dl.min.io/client/mc/release/linux-amd64/mc
82-
chmod +x mc
83-
./mc alias set minio http://localhost:9000 myaccesskey mysecretkey --api S3v4
84-
kubectl -n source-system apply -f ./config/testdata/minio/secret.yaml
85-
- name: Run Bucket tests
86-
run: |
87-
./mc mb minio/podinfo
88-
./mc mirror ./config/testdata/minio/manifests/ minio/podinfo
89-
90-
kubectl -n source-system apply -f ./config/testdata/bucket/source.yaml
91-
kubectl -n source-system wait bucket/podinfo --for=condition=ready --timeout=1m
92-
- name: Run HelmChart from Bucket tests
93-
run: |
94-
./mc mb minio/charts
95-
./mc mirror ./controllers/testdata/charts/helmchart/ minio/charts/helmchart
96-
97-
kubectl -n source-system apply -f ./config/testdata/helmchart-from-bucket/source.yaml
98-
kubectl -n source-system wait bucket/charts --for=condition=ready --timeout=1m
99-
kubectl -n source-system wait helmchart/helmchart-bucket --for=condition=ready --timeout=1m
100-
- name: Run large Git repo tests
101-
run: |
102-
kubectl -n source-system apply -f ./config/testdata/git/large-repo.yaml
103-
kubectl -n source-system wait gitrepository/large-repo-go-git --for=condition=ready --timeout=2m
104-
kubectl -n source-system wait gitrepository/large-repo-libgit2 --for=condition=ready --timeout=2m
105-
- name: Logs
106-
run: |
107-
kubectl -n source-system logs deploy/source-controller
108-
- name: Debug failure
109-
if: failure()
110-
run: |
111-
kubectl -n kube-system describe pods
112-
kubectl -n source-system describe pods
113-
kubectl -n source-system get gitrepositories -oyaml
114-
kubectl -n source-system get helmrepositories -oyaml
115-
kubectl -n source-system get helmcharts -oyaml
116-
kubectl -n source-system get all
117-
kubectl -n source-system logs deploy/source-controller
118-
kubectl -n minio get all
49+
CREATE_CLUSTER: false
50+
run: make e2e

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@ config/release/
1818

1919
# Exclude all libgit2 related files
2020
hack/libgit2/
21+
22+
# Exclude temporary build files
23+
build/

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,7 @@ help: ## Display this help menu
224224
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-20s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
225225

226226
update-attributions:
227-
./hack/update-attributions.sh
227+
./hack/update-attributions.sh
228+
229+
e2e:
230+
./hack/ci/e2e.sh

hack/ci/e2e.sh

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#!/usr/bin/env bash
2+
3+
set -eoux pipefail
4+
5+
MINIO_VER="${MINIO_VER:-v6.3.1}"
6+
CREATE_CLUSTER="${CREATE_CLUSTER:-true}"
7+
KIND_CLUSTER_NAME="${KIND_CLUSTER_NAME:-kind}"
8+
9+
IMG=test/source-controller
10+
TAG=latest
11+
MC_RELEASE=mc.RELEASE.2021-12-10T00-14-28Z
12+
MC_SHA256=01ec33b51ad208634deb8d701d52ac8f6be088e72563a92475ba6e6470653b73
13+
14+
ROOT_DIR="$(git rev-parse --show-toplevel)"
15+
BUILD_DIR="${ROOT_DIR}/build"
16+
17+
if "${CREATE_CLUSTER}"; then
18+
KIND_CLUSTER_NAME="flux-${RANDOM}"
19+
export KUBECONFIG="${ROOT_DIR}/build/kindconfig"
20+
21+
echo "Spinning up flux kind cluster"
22+
kind create cluster --name "${KIND_CLUSTER_NAME}" --kubeconfig "${KUBECONFIG}"
23+
fi
24+
25+
function cleanup(){
26+
EXIT_CODE="$?"
27+
28+
# only dump all logs if an error has occurred
29+
if [ ${EXIT_CODE} -ne 0 ]; then
30+
kubectl -n kube-system describe pods
31+
kubectl -n source-system describe pods
32+
kubectl -n source-system get gitrepositories -oyaml
33+
kubectl -n source-system get helmrepositories -oyaml
34+
kubectl -n source-system get helmcharts -oyaml
35+
kubectl -n source-system get all
36+
kubectl -n source-system logs deploy/source-controller
37+
kubectl -n minio get all
38+
else
39+
echo "All E2E tests passed!"
40+
fi
41+
42+
if "${CREATE_CLUSTER}"; then
43+
echo "Delete cluster"
44+
kind delete cluster --name "${KIND_CLUSTER_NAME}"
45+
fi
46+
exit ${EXIT_CODE}
47+
}
48+
trap cleanup EXIT
49+
50+
kubectl wait node "${KIND_CLUSTER_NAME}-control-plane" --for=condition=ready --timeout=2m
51+
52+
echo "Build, load image into kind and deploy controller"
53+
make docker-build IMG="${IMG}" TAG="${TAG}" BUILD_PLATFORMS=linux/amd64 BUILD_ARGS=--load
54+
kind load docker-image --name "${KIND_CLUSTER_NAME}" "${IMG}":"${TAG}"
55+
make dev-deploy IMG="${IMG}" TAG="${TAG}"
56+
57+
echo "Run smoke tests"
58+
kubectl -n source-system apply -f "${ROOT_DIR}/config/samples"
59+
kubectl -n source-system rollout status deploy/source-controller --timeout=1m
60+
kubectl -n source-system wait gitrepository/gitrepository-sample --for=condition=ready --timeout=1m
61+
kubectl -n source-system wait helmrepository/helmrepository-sample --for=condition=ready --timeout=1m
62+
kubectl -n source-system wait helmchart/helmchart-sample --for=condition=ready --timeout=1m
63+
kubectl -n source-system delete -f "${ROOT_DIR}/config/samples"
64+
65+
echo "Run HelmChart values file tests"
66+
kubectl -n source-system apply -f "${ROOT_DIR}/config/testdata/helmchart-valuesfile"
67+
kubectl -n source-system wait helmchart/podinfo --for=condition=ready --timeout=5m
68+
kubectl -n source-system wait helmchart/podinfo-git --for=condition=ready --timeout=5m
69+
kubectl -n source-system delete -f "${ROOT_DIR}/config/testdata/helmchart-valuesfile"
70+
71+
echo "Setup Minio"
72+
kubectl create ns minio
73+
helm repo add minio https://helm.min.io/
74+
helm upgrade --wait -i minio minio/minio \
75+
--version "${MINIO_VER}" \
76+
--namespace minio \
77+
--set accessKey=myaccesskey \
78+
--set secretKey=mysecretkey \
79+
--set resources.requests.memory=128Mi \
80+
--set persistence.enable=false
81+
kubectl -n minio port-forward svc/minio 9000:9000 &>/dev/null &
82+
83+
sleep 2
84+
85+
if [ ! -f "${BUILD_DIR}/mc" ]; then
86+
mkdir -p "${BUILD_DIR}"
87+
curl -o "${BUILD_DIR}/mc" -LO "https://dl.min.io/client/mc/release/linux-amd64/archive/${MC_RELEASE}"
88+
if ! echo "${MC_SHA256} ${BUILD_DIR}/mc" | sha256sum --check; then
89+
echo "Checksum failed for mc."
90+
rm "${BUILD_DIR}/mc"
91+
exit 1
92+
fi
93+
94+
chmod +x "${BUILD_DIR}/mc"
95+
fi
96+
97+
"${BUILD_DIR}/mc" alias set minio http://localhost:9000 myaccesskey mysecretkey --api S3v4
98+
kubectl -n source-system apply -f "${ROOT_DIR}/config/testdata/minio/secret.yaml"
99+
100+
echo "Run Bucket tests"
101+
"${BUILD_DIR}/mc" mb minio/podinfo
102+
"${BUILD_DIR}/mc" mirror "${ROOT_DIR}/config/testdata/minio/manifests/" minio/podinfo
103+
104+
kubectl -n source-system apply -f "${ROOT_DIR}/config/testdata/bucket/source.yaml"
105+
kubectl -n source-system wait bucket/podinfo --for=condition=ready --timeout=1m
106+
107+
108+
echo "Run HelmChart from Bucket tests"
109+
"${BUILD_DIR}/mc" mb minio/charts
110+
"${BUILD_DIR}/mc" mirror "${ROOT_DIR}/controllers/testdata/charts/helmchart/" minio/charts/helmchart
111+
112+
kubectl -n source-system apply -f "${ROOT_DIR}/config/testdata/helmchart-from-bucket/source.yaml"
113+
kubectl -n source-system wait bucket/charts --for=condition=ready --timeout=1m
114+
kubectl -n source-system wait helmchart/helmchart-bucket --for=condition=ready --timeout=1m
115+
116+
echo "Run large Git repo tests"
117+
kubectl -n source-system apply -f "${ROOT_DIR}/config/testdata/git/large-repo.yaml"
118+
kubectl -n source-system wait gitrepository/large-repo-go-git --for=condition=ready --timeout=2m
119+
kubectl -n source-system wait gitrepository/large-repo-libgit2 --for=condition=ready --timeout=2m

0 commit comments

Comments
 (0)