@@ -137,8 +137,12 @@ jobs:
137137 - name : Import images to kind
138138 run : |
139139 export SHELL=/bin/bash
140+ # Load images into Cluster 1 (test)
140141 kind load docker-image ghcr.io/headlamp-k8s/headlamp-plugins-test:latest --name test
141142 kind load docker-image ghcr.io/headlamp-k8s/headlamp:latest --name test
143+
144+ # Load Headlamp image into Cluster 2 (test2) so it can run in-cluster tests there
145+ kind load docker-image ghcr.io/headlamp-k8s/headlamp:latest --name test2
142146 - name : Test .plugins folder
143147 if : steps.cache-image-restore2.outputs.cache-hit != 'true'
144148 run : |
@@ -231,6 +235,70 @@ jobs:
231235 else
232236 echo "Playwright tests passed successfully"
233237 fi
238+ - name : Deploy Headlamp in in-cluster mode and run TS API tests
239+ run : |
240+ # Reuse Cluster 2 context for in-cluster tests
241+ kubectl config use-context test2
242+
243+ # Setup service account and RBAC for Headlamp
244+ kubectl create serviceaccount headlamp --namespace kube-system || true
245+ kubectl create clusterrolebinding headlamp --serviceaccount=kube-system:headlamp --clusterrole=cluster-admin || true
246+ kubectl get serviceaccount headlamp -n kube-system
247+
248+ # Deploy Headlamp with in-cluster mode
249+ kubectl apply -f e2e-tests/kubernetes-headlamp-incluster-ci.yaml
250+
251+ echo "Waiting for headlamp deployment to be available (in-cluster)..."
252+ kubectl wait deployment -n kube-system headlamp --for condition=Available=True --timeout=120s
253+ kubectl get pods -n kube-system -l app.kubernetes.io/name=headlamp
254+
255+ echo "Checking headlamp pod status (in-cluster)..."
256+ kubectl logs -n kube-system -l app.kubernetes.io/name=headlamp --tail=50 || true
257+
258+ # Start port-forward in background
259+ echo "Starting port-forward to headlamp service (in-cluster)..."
260+ kubectl port-forward -n kube-system service/headlamp 8080:80 &
261+ PORT_FORWARD_PID=$!
262+
263+ # Wait for port-forward to be ready
264+ sleep 5
265+
266+ # Verify port-forward is working
267+ if ! kill -0 $PORT_FORWARD_PID 2>/dev/null; then
268+ echo "❌ Port-forward failed to start for in-cluster test"
269+ exit 1
270+ fi
271+
272+ export HEADLAMP_TEST_URL="http://localhost:8080"
273+ echo "In-cluster Headlamp URL: $HEADLAMP_TEST_URL"
274+
275+ # Get service account token for API checks
276+ echo "Getting service account token for in-cluster test..."
277+ export HEADLAMP_SA_TOKEN=$(kubectl create token headlamp --duration=1h -n kube-system)
278+
279+ if [ -z "$HEADLAMP_SA_TOKEN" ]; then
280+ echo "❌ Failed to get service account token for in-cluster test"
281+ kill $PORT_FORWARD_PID 2>/dev/null || true
282+ exit 1
283+ fi
284+
285+ echo "✅ Service account token obtained"
286+ echo "Running in-cluster API Playwright tests..."
287+
288+ # Run the TypeScript in-cluster API tests
289+ cd e2e-tests
290+ npm ci
291+ npx playwright install --with-deps
292+ npx playwright test tests/incluster-api.spec.ts
293+ EXIT_CODE=$?
294+
295+ # Cleanup port-forward
296+ kill $PORT_FORWARD_PID 2>/dev/null || true
297+
298+ if [ $EXIT_CODE -ne 0 ]; then
299+ echo "❌ In-cluster API tests failed with exit code $EXIT_CODE"
300+ exit $EXIT_CODE
301+ fi
234302 # Clear disk space by removing unnecessary files, apt files and uninstall some playwright dependencies
235303 - name : Clear Disk Space
236304 if : steps.cache-image-restore2.outputs.cache-hit != 'true'
0 commit comments