From 7e6661073d8d3bccf66d8435a1a82dcca9dbce6d Mon Sep 17 00:00:00 2001 From: Gandalf the Greybeard Date: Sun, 15 Mar 2026 20:39:35 +0000 Subject: [PATCH] fix: add plugin deploy script and fix Dockerfile plugin directory Root cause of E2E failures: the E2E tests run against a live Headlamp instance but never deploy the current PR's plugin code. The deployed plugin still uses the old registerPluginSettings name, so the settings component never renders. - Fix Dockerfile output directory from headlamp-polaris-plugin to polaris, matching the deployed plugin identity - Add scripts/deploy-plugin-to-headlamp.sh to build and deploy the plugin to Headlamp via kubectl before E2E tests The e2e.yaml workflow needs a matching update to call this script before running Playwright (requires workflows permission). Co-Authored-By: Paperclip --- Dockerfile | 4 +- scripts/deploy-plugin-to-headlamp.sh | 70 ++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 2 deletions(-) create mode 100755 scripts/deploy-plugin-to-headlamp.sh diff --git a/Dockerfile b/Dockerfile index 80272c0..9def731 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,5 +6,5 @@ COPY src/ src/ RUN npx @kinvolk/headlamp-plugin build FROM alpine:3.20 -COPY --from=build /app/dist/ /plugins/headlamp-polaris-plugin/ -COPY --from=build /app/package.json /plugins/headlamp-polaris-plugin/ +COPY --from=build /app/dist/ /plugins/polaris/ +COPY --from=build /app/package.json /plugins/polaris/ diff --git a/scripts/deploy-plugin-to-headlamp.sh b/scripts/deploy-plugin-to-headlamp.sh new file mode 100755 index 0000000..8175497 --- /dev/null +++ b/scripts/deploy-plugin-to-headlamp.sh @@ -0,0 +1,70 @@ +#!/usr/bin/env bash +# Deploy the built plugin to a live Headlamp instance via kubectl. +# +# Prerequisites: +# - kubectl configured with access to the Headlamp namespace +# - Plugin already built (npm run build → dist/) +# +# Environment variables (all optional, with defaults): +# HEADLAMP_URL — Headlamp URL for readiness check +# HEADLAMP_NS — Kubernetes namespace (default: kube-system) +# HEADLAMP_PLUGIN_DIR — Plugin path inside the pod (default: /headlamp/static-plugins/polaris) +# +# Usage: +# npm run build +# ./scripts/deploy-plugin-to-headlamp.sh +# +# Intended to be called from the E2E workflow before running Playwright tests, +# so that E2E always tests the current commit's plugin code rather than whatever +# was previously deployed. + +set -euo pipefail + +HEADLAMP_URL="${HEADLAMP_URL:-http://headlamp.kube-system.svc.cluster.local}" +HEADLAMP_NS="${HEADLAMP_NS:-kube-system}" +HEADLAMP_PLUGIN_DIR="${HEADLAMP_PLUGIN_DIR:-/headlamp/static-plugins/polaris}" + +if [ ! -d "dist" ]; then + echo "Error: dist/ not found. Run 'npm run build' first." >&2 + exit 1 +fi + +# Find the Headlamp pod +POD=$(kubectl get pod -n "$HEADLAMP_NS" -l app.kubernetes.io/name=headlamp \ + -o jsonpath='{.items[0].metadata.name}') +echo "Headlamp pod: $POD" + +# Remove stale plugin and copy current build +kubectl exec -n "$HEADLAMP_NS" "$POD" -c headlamp -- \ + rm -rf "$HEADLAMP_PLUGIN_DIR" 2>/dev/null || true +kubectl cp dist/. "$HEADLAMP_NS/$POD:$HEADLAMP_PLUGIN_DIR" -c headlamp + +# Copy package.json so Headlamp can read plugin metadata +kubectl cp package.json "$HEADLAMP_NS/$POD:$HEADLAMP_PLUGIN_DIR/package.json" -c headlamp + +# Verify the copy +echo "Deployed files:" +kubectl exec -n "$HEADLAMP_NS" "$POD" -c headlamp -- \ + ls -la "$HEADLAMP_PLUGIN_DIR" + +# Restart the Headlamp process to reload plugins. +# Killing PID 1 restarts the container without replacing the pod, +# so the emptyDir volume (and our copied files) is preserved. +echo "Restarting Headlamp process..." +kubectl exec -n "$HEADLAMP_NS" "$POD" -c headlamp -- kill 1 || true + +# Wait for Headlamp to come back +echo "Waiting for Headlamp to restart..." +sleep 10 +for i in $(seq 1 30); do + HTTP_CODE=$(curl -s -o /dev/null -w '%{http_code}' --connect-timeout 5 "$HEADLAMP_URL" || true) + if [ "$HTTP_CODE" = "200" ]; then + echo "Headlamp is ready" + exit 0 + fi + echo " attempt $i/30 — HTTP $HTTP_CODE" + sleep 5 +done + +echo "Error: Headlamp did not recover after plugin deploy" >&2 +exit 1