Skip to content

Commit 51174e4

Browse files
committed
ci: Add smoke test workflow
Add a new GitHub Actions workflow for smoke testing. This workflow triggers on pull requests to the main and release branches as well as direct pushes to the main branch. It sets up a Kind cluster, installs necessary tools, and runs a series of installation and verification steps for the Cluster API Operator, cert-manager, and provider components. The workflow includes steps for error handling and cleanup after tests. Signed-off-by: kahirokunn <[email protected]>
1 parent c773386 commit 51174e4

File tree

1 file changed

+220
-0
lines changed

1 file changed

+220
-0
lines changed

.github/workflows/smoke-test.yaml

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
name: Smoke Test
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
- 'release-*'
8+
push:
9+
branches:
10+
- main
11+
workflow_dispatch:
12+
13+
permissions:
14+
contents: read
15+
16+
jobs:
17+
smoke-test:
18+
runs-on: ubuntu-latest
19+
timeout-minutes: 15
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
25+
26+
- name: Set up Go
27+
uses: actions/setup-go@v5
28+
with:
29+
go-version-file: 'go.mod'
30+
31+
- name: Install kubectl
32+
run: |
33+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
34+
chmod +x kubectl
35+
sudo mv kubectl /usr/local/bin/
36+
37+
- name: Install Helm
38+
run: |
39+
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
40+
41+
- name: Build Docker image
42+
run: |
43+
# Build the operator image with a specific tag for smoke test
44+
CONTROLLER_IMG=cluster-api-operator TAG=smoke-test make docker-build
45+
echo "Built image: cluster-api-operator-amd64:smoke-test"
46+
47+
# Tag the image for easier reference
48+
docker tag cluster-api-operator-amd64:smoke-test cluster-api-operator:smoke-test
49+
50+
- name: Build charts
51+
run: |
52+
make release-chart
53+
54+
# Extract HELM_CHART_TAG from Makefile
55+
HELM_CHART_TAG=$(make -s -f Makefile -p | grep '^HELM_CHART_TAG :=' | cut -d' ' -f3)
56+
echo "HELM_CHART_TAG=$HELM_CHART_TAG" >> $GITHUB_ENV
57+
echo "Detected HELM_CHART_TAG: $HELM_CHART_TAG"
58+
59+
- name: Create kind cluster
60+
run: |
61+
chmod +x ./hack/ensure-kind.sh
62+
./hack/ensure-kind.sh
63+
kind create cluster --name capi-operator-smoke-test --wait 5m
64+
kubectl cluster-info --context kind-capi-operator-smoke-test
65+
66+
- name: Load Docker image to kind
67+
run: |
68+
# Load the built image into kind cluster
69+
kind load docker-image cluster-api-operator:smoke-test --name capi-operator-smoke-test
70+
echo "Loaded image cluster-api-operator:smoke-test into kind cluster"
71+
72+
- name: Add Helm repositories
73+
run: |
74+
helm repo add jetstack https://charts.jetstack.io
75+
helm repo update
76+
77+
- name: Install cert-manager
78+
run: |
79+
helm install cert-manager jetstack/cert-manager \
80+
--namespace cert-manager \
81+
--create-namespace \
82+
--set installCRDs=true \
83+
--wait \
84+
--timeout 5m
85+
86+
- name: Install Cluster API Operator
87+
run: |
88+
# Use exact chart filename based on HELM_CHART_TAG
89+
CHART_PACKAGE="out/package/cluster-api-operator-${HELM_CHART_TAG}.tgz"
90+
echo "Using chart package: $CHART_PACKAGE"
91+
92+
# Verify the file exists
93+
if [ ! -f "$CHART_PACKAGE" ]; then
94+
echo "Error: Chart package not found: $CHART_PACKAGE"
95+
ls -la out/package/
96+
exit 1
97+
fi
98+
99+
helm install capi-operator "$CHART_PACKAGE" \
100+
--create-namespace \
101+
-n capi-operator-system \
102+
--set image.manager.repository=cluster-api-operator \
103+
--set image.manager.tag=smoke-test \
104+
--set image.manager.pullPolicy=IfNotPresent \
105+
--wait \
106+
--timeout 90s
107+
108+
- name: Wait for CAPI Operator to be ready
109+
run: |
110+
kubectl wait --for=condition=Available --timeout=300s -n capi-operator-system deployment/capi-operator-controller-manager
111+
112+
- name: Deploy providers using cluster-api-operator-providers chart
113+
run: |
114+
# Create values file for providers
115+
cat <<EOF > /tmp/providers-values.yaml
116+
core:
117+
cluster-api:
118+
namespace: capi-system
119+
createNamespace: false
120+
infrastructure:
121+
docker:
122+
namespace: capd-system
123+
createNamespace: false
124+
configSecret:
125+
name: credentials-secret
126+
namespace: default
127+
EOF
128+
129+
# Use exact providers chart filename based on HELM_CHART_TAG
130+
PROVIDERS_CHART_PACKAGE="out/package/cluster-api-operator-providers-${HELM_CHART_TAG}.tgz"
131+
echo "Using providers chart package: $PROVIDERS_CHART_PACKAGE"
132+
133+
# Verify the file exists
134+
if [ ! -f "$PROVIDERS_CHART_PACKAGE" ]; then
135+
echo "Error: Providers chart package not found: $PROVIDERS_CHART_PACKAGE"
136+
ls -la out/package/
137+
exit 1
138+
fi
139+
140+
helm install capi-providers "$PROVIDERS_CHART_PACKAGE" \
141+
-f /tmp/providers-values.yaml \
142+
--wait
143+
144+
- name: Wait for providers to be ready
145+
run: |
146+
echo "Waiting for Core Provider to be ready..."
147+
kubectl wait --for=condition=Ready --timeout=300s -n capi-system coreprovider/cluster-api || true
148+
149+
echo "Waiting for Infrastructure Provider to be ready..."
150+
kubectl wait --for=condition=Ready --timeout=300s -n capd-system infrastructureprovider/docker || true
151+
152+
# Additional wait for deployments
153+
kubectl wait --for=condition=Available --timeout=300s -n capi-system deployment/capi-controller-manager || true
154+
kubectl wait --for=condition=Available --timeout=300s -n capd-system deployment/capd-controller-manager || true
155+
156+
- name: Verify installation
157+
run: |
158+
echo "=== Cluster API Operator Status ==="
159+
kubectl get pods -n capi-operator-system
160+
161+
echo -e "\n=== Core Provider Status ==="
162+
kubectl get coreprovider -A -o wide
163+
kubectl describe coreprovider -n capi-system cluster-api || true
164+
165+
echo -e "\n=== Infrastructure Provider Status ==="
166+
kubectl get infrastructureprovider -A -o wide
167+
kubectl describe infrastructureprovider -n capd-system docker || true
168+
169+
echo -e "\n=== All Pods ==="
170+
kubectl get pods -A | grep -E "(capi-|capd-)"
171+
172+
echo -e "\n=== CRDs ==="
173+
kubectl get crds | grep -E "(cluster.x-k8s.io|operator.cluster.x-k8s.io)"
174+
175+
- name: Check provider health
176+
run: |
177+
# Check if core provider is ready
178+
CORE_READY=$(kubectl get coreprovider -n capi-system cluster-api -o jsonpath='{.status.conditions[?(@.type=="Ready")].status}')
179+
if [ "$CORE_READY" != "True" ]; then
180+
echo "Core provider is not ready"
181+
kubectl get coreprovider -n capi-system cluster-api -o yaml
182+
exit 1
183+
fi
184+
185+
# Check if infrastructure provider is ready
186+
INFRA_READY=$(kubectl get infrastructureprovider -n capd-system docker -o jsonpath='{.status.conditions[?(@.type=="Ready")].status}')
187+
if [ "$INFRA_READY" != "True" ]; then
188+
echo "Infrastructure provider is not ready"
189+
kubectl get infrastructureprovider -n capd-system docker -o yaml
190+
exit 1
191+
fi
192+
193+
echo "All providers are ready!"
194+
195+
- name: Collect debug information on failure
196+
if: failure()
197+
run: |
198+
echo "=== Events ==="
199+
kubectl get events -A --sort-by='.lastTimestamp' | tail -50
200+
201+
echo -e "\n=== CAPI Operator Logs ==="
202+
kubectl logs -n capi-operator-system deployment/capi-operator-controller-manager --tail=100 || true
203+
204+
echo -e "\n=== Core Provider Logs ==="
205+
kubectl logs -n capi-system deployment/capi-controller-manager --tail=100 || true
206+
207+
echo -e "\n=== Infrastructure Provider Logs ==="
208+
kubectl logs -n capd-system deployment/capd-controller-manager --tail=100 || true
209+
210+
echo -e "\n=== Describe Failed Pods ==="
211+
kubectl get pods -A | grep -v Running | grep -v Completed | tail -n +2 | while read namespace name ready status restarts age; do
212+
echo "Describing pod $name in namespace $namespace"
213+
kubectl describe pod -n $namespace $name
214+
echo "---"
215+
done
216+
217+
- name: Clean up
218+
if: always()
219+
run: |
220+
kind delete cluster --name capi-operator-smoke-test || true

0 commit comments

Comments
 (0)