Skip to content

Commit 0cc2efa

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

File tree

63 files changed

+668
-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

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

0 commit comments

Comments
 (0)