Skip to content

Commit 8fe8bc5

Browse files
Sowmya viswamSowmya viswam
authored andcommitted
Adding in deploy changes tests for vcluster
1 parent a871894 commit 8fe8bc5

File tree

63 files changed

+667
-92
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+667
-92
lines changed
Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
name: E2E Deploy Changes CI
2+
3+
on:
4+
release:
5+
types: [created]
6+
pull_request:
7+
branches:
8+
- main
9+
- v*
10+
paths:
11+
- "test/deploy_changes/**"
12+
workflow_dispatch:
13+
14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
16+
cancel-in-progress: true
17+
18+
env:
19+
REPOSITORY_NAME: ghcr.io/${{ github.repository }}-ci
20+
TAG_NAME: PR${{ github.event.number }}
21+
VCLUSTER_SUFFIX: vcluster
22+
VCLUSTER_NAME: vcluster
23+
VCLUSTER_NAMESPACE: vcluster
24+
25+
jobs:
26+
build-and-push-syncer-image:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- name: Checkout repository
30+
uses: actions/checkout@v4
31+
with:
32+
fetch-depth: 0
33+
- run: git fetch --force --tags
34+
- name: Set up Go
35+
uses: actions/setup-go@v5
36+
with:
37+
go-version: "1.22"
38+
- name: Setup Just
39+
uses: extractions/setup-just@v2
40+
- name: Setup Syft
41+
uses: anchore/sbom-action/[email protected]
42+
- name: Setup GoReleaser
43+
uses: goreleaser/goreleaser-action@v6
44+
with:
45+
install-only: true
46+
version: latest
47+
- name: Build and save syncer image
48+
run: |
49+
set -x
50+
TELEMETRY_PRIVATE_KEY="" goreleaser build --single-target --snapshot --id vcluster --clean --output ./vcluster
51+
docker build -t "${{ env.REPOSITORY_NAME }}:${{ env.TAG_NAME }}" -f Dockerfile.release --build-arg TARGETARCH=amd64 --build-arg TARGETOS=linux .
52+
docker save -o vcluster_syncer "${{ env.REPOSITORY_NAME }}:${{ env.TAG_NAME }}"
53+
- name: Upload syncer image to artifact
54+
uses: actions/upload-artifact@v4
55+
with:
56+
name: vcluster_syncer
57+
path: ./vcluster_syncer
58+
retention-days: 7
59+
60+
build-vcluster-cli:
61+
runs-on: ubuntu-latest
62+
steps:
63+
- name: Checkout repository
64+
uses: actions/checkout@v4
65+
with:
66+
fetch-depth: 0
67+
- run: git fetch --force --tags
68+
- name: Set up Go
69+
uses: actions/setup-go@v5
70+
with:
71+
go-version: "1.22"
72+
- name: Setup Just
73+
uses: extractions/setup-just@v2
74+
- name: Setup Syft
75+
uses: anchore/sbom-action/[email protected]
76+
- name: Setup GoReleaser
77+
uses: goreleaser/goreleaser-action@v6
78+
with:
79+
install-only: true
80+
- name: Build vcluster cli
81+
run: |
82+
set -x
83+
TELEMETRY_PRIVATE_KEY="" goreleaser build --single-target --snapshot --id vcluster-cli --clean --output ./vcluster
84+
- name: Upload vcluster cli to artifact
85+
uses: actions/upload-artifact@v4
86+
with:
87+
name: vcluster
88+
path: ./vcluster
89+
retention-days: 7
90+
91+
build-tests:
92+
name: Build tests binaries
93+
runs-on: ubuntu-latest
94+
steps:
95+
- name: Checkout
96+
uses: actions/checkout@v4
97+
98+
- name: Configure git
99+
run: git config --global url.https://[email protected]/.insteadOf https://github.com/
100+
env:
101+
GH_ACCESS_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
102+
103+
- name: Set up Go
104+
uses: actions/setup-go@v4
105+
with:
106+
go-version-file: go.mod
107+
108+
- name: Build e2e binary
109+
run: |
110+
cd ./test
111+
go run -mod=vendor github.com/onsi/ginkgo/v2/ginkgo build --require-suite -r --mod vendor $(ls -d ./deploy_changes/deploy_* | jq -R . | jq -rcs '. | join(" \\\n")')
112+
env:
113+
GOWORK: off
114+
115+
- name: Upload test binaries to artifacts
116+
uses: actions/upload-artifact@v4
117+
with:
118+
name: test-binaries
119+
path: test/deploy_changes/**/*.test
120+
retention-days: 7
121+
122+
generate-matrix:
123+
runs-on: ubuntu-latest
124+
steps:
125+
- name: Checkout code
126+
uses: actions/checkout@v4
127+
128+
- name: List test directories
129+
id: set-paths-matrix
130+
run: |
131+
cd ./test
132+
directories=$(ls -d ./deploy_changes/*/ | xargs -n 1 basename)
133+
# Append .test to each directory name
134+
matrix=$(echo "$directories" | sed -e 's/$/.test/' | jq -R -s 'split("\n") | .[:-1]')
135+
echo "Generated matrix: $matrix"
136+
echo "::set-output name=matrix::$matrix"
137+
outputs:
138+
matrix: ${{ steps.set-paths-matrix.outputs.matrix }}
139+
140+
deploy-tests:
141+
name: Execute test suites
142+
needs:
143+
- build-and-push-syncer-image
144+
- build-vcluster-cli
145+
- build-tests
146+
- generate-matrix
147+
148+
runs-on: ubuntu-latest
149+
strategy:
150+
fail-fast: false
151+
matrix: ${{ fromJson(steps.set-paths-matrix.outputs.matrix) }}
152+
steps:
153+
- name: Checkout repository
154+
uses: actions/checkout@v4
155+
156+
- uses: azure/setup-helm@v4
157+
name: Setup Helm
158+
with:
159+
version: "v3.11.0"
160+
161+
- name: Set up kind k8s cluster
162+
uses: engineerd/[email protected]
163+
with:
164+
version: "v0.20.0"
165+
image: kindest/node:v1.30.0@sha256:047357ac0cfea04663786a612ba1eaba9702bef25227a794b52890dd8bcd692e
166+
167+
- name: Testing kind cluster set-up
168+
run: |
169+
set -x
170+
kubectl cluster-info
171+
kubectl get pods -n kube-system
172+
echo "kubectl config current-context:" $(kubectl config current-context)
173+
echo "KUBECONFIG env var:" ${KUBECONFIG}
174+
175+
- name: Download vcluster cli
176+
uses: actions/download-artifact@v4
177+
with:
178+
name: vcluster
179+
180+
- name: Download syncer image
181+
uses: actions/download-artifact@v4
182+
with:
183+
name: vcluster_syncer
184+
185+
- name: Download test binaries
186+
uses: actions/download-artifact@v4
187+
with:
188+
name: test-binaries
189+
path: ./test/deploy_changes
190+
191+
- name: Create vcluster
192+
id: create-vcluster
193+
run: |
194+
set -x
195+
196+
sudo apt-get install -y sed
197+
198+
sed -i "s|REPLACE_REPOSITORY_NAME|${{ env.REPOSITORY_NAME }}|g" ./test/deploy_changes/commonValues.yaml
199+
sed -i "s|REPLACE_TAG_NAME|${{ env.TAG_NAME }}|g" ./test/deploy_changes/commonValues.yaml
200+
201+
kind load image-archive vcluster_syncer
202+
203+
chmod +x vcluster && sudo mv vcluster /usr/bin
204+
205+
vcluster create ${{ env.VCLUSTER_SUFFIX }} -n ${{ env.VCLUSTER_NAMESPACE }} \
206+
--create-namespace \
207+
--debug \
208+
--connect=false \
209+
--local-chart-dir ./chart \
210+
-f ./test/deploy_changes/commonValues.yaml
211+
continue-on-error: true
212+
213+
- name: Wait until vcluster is ready
214+
id: wait-until-vcluster-is-ready
215+
if: steps.create-vcluster.outcome == 'success'
216+
run: |
217+
set -x
218+
219+
./hack/wait-for-pod.sh -l app=${{ env.VCLUSTER_SUFFIX }} -n ${{ env.VCLUSTER_NAMESPACE }}
220+
221+
continue-on-error: true
222+
223+
- name: Collect deployment information in case vcluster fails to start
224+
if: steps.wait-until-vcluster-is-ready.outcome != 'success'
225+
run: |
226+
set -x
227+
kubectl get pods -o yaml -n ${{ env.VCLUSTER_NAMESPACE }}
228+
echo "======================================================================================================================"
229+
kubectl get events -n ${{ env.VCLUSTER_NAMESPACE }} --sort-by='.lastTimestamp'
230+
echo "======================================================================================================================"
231+
kubectl logs -l app=${{ env.VCLUSTER_SUFFIX }} -n ${{ env.VCLUSTER_NAMESPACE }} -c syncer --tail=-1 -p || kubectl logs -l app=${{ env.VCLUSTER_SUFFIX }} -n ${{ env.VCLUSTER_NAMESPACE }} -c syncer --tail=-1
232+
echo "======================================================================================================================"
233+
kubectl describe pods -n ${{ env.VCLUSTER_NAMESPACE }}
234+
exit 1
235+
236+
# Skips NetworkPolicy tests because they require network plugin with support (e.g. Calico)
237+
- name: Execute tests
238+
id: execute-tests
239+
working-directory: ./test
240+
run: |
241+
set -x
242+
243+
sudo chmod +x ./deploy_changes/${{ matrix.test }}/*.test
244+
245+
VCLUSTER_SUFFIX=${{ env.VCLUSTER_SUFFIX }} VCLUSTER_NAME=${{ env.VCLUSTER_NAME }} VCLUSTER_NAMESPACE=${{ env.VCLUSTER_NAMESPACE }} ./deploy_changes/${{ matrix.test }}/*.test -test.v --ginkgo.v --ginkgo.skip='.*NetworkPolicy.*' --ginkgo.fail-fast
246+
247+
if kubectl logs -l app=${{ env.VCLUSTER_SUFFIX }} -n ${{ env.VCLUSTER_NAMESPACE }} -c syncer --tail=-1 -p >/dev/null 2>/dev/null; then
248+
echo "vCluster has restarted during testing, failing..."
249+
exit 1
250+
fi
251+
252+
continue-on-error: true
253+
254+
- name: Print logs if tests fail
255+
if: steps.execute-tests.outcome == 'failure'
256+
run: |
257+
set -x
258+
kubectl get pods -o yaml -n ${{ env.VCLUSTER_NAMESPACE }}
259+
echo "======================================================================================================================"
260+
kubectl get events -n ${{ env.VCLUSTER_NAMESPACE }} --sort-by='.lastTimestamp'
261+
echo "======================================================================================================================"
262+
kubectl logs -l app=${{ env.VCLUSTER_SUFFIX }} -n ${{ env.VCLUSTER_NAMESPACE }} -c syncer --tail=-1 -p || kubectl logs -l app=${{ env.VCLUSTER_SUFFIX }} -n ${{ env.VCLUSTER_NAMESPACE }} -c syncer --tail=-1
263+
echo "======================================================================================================================"
264+
kubectl describe pods -n ${{ env.VCLUSTER_NAMESPACE }}
265+
exit 1
266+

0 commit comments

Comments
 (0)