Skip to content

Commit c697f7f

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 <okinakahiro@gmail.com>
1 parent c773386 commit c697f7f

File tree

1 file changed

+214
-0
lines changed

1 file changed

+214
-0
lines changed

.github/workflows/smoke-test.yaml

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

0 commit comments

Comments
 (0)