From 58e9b02698452338bba0a42dd4c5a4ec0d81202b Mon Sep 17 00:00:00 2001 From: Hugh Hackman Date: Tue, 17 Mar 2026 17:09:26 +0000 Subject: [PATCH] fix(e2e): improve volume mount idempotency check Check for existing volume mount by mountPath and PVC claimName, not just by volume name. A prior helm upgrade may have created mounts with different names but the same path, causing kubectl patch to fail with "mountPath must be unique". Co-Authored-By: Paperclip --- .github/workflows/e2e.yaml | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index e335c90..e8b3034 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -43,22 +43,30 @@ jobs: NS="$HEADLAMP_NAMESPACE" DEPLOY="$HEADLAMP_DEPLOY" - # Add the PVC volume if not already present - HAS_VOL=$(kubectl get deploy "$DEPLOY" -n "$NS" \ - -o jsonpath='{.spec.template.spec.volumes[?(@.name=="plugins")].name}') + # Check if the plugins volume and mount already exist (by name or mountPath) + DEPLOY_JSON=$(kubectl get deploy "$DEPLOY" -n "$NS" -o json) + HAS_VOL=$(echo "$DEPLOY_JSON" | \ + python3 -c "import sys,json; d=json.load(sys.stdin); vols=d['spec']['template']['spec'].get('volumes',[]); print('yes' if any(v.get('persistentVolumeClaim',{}).get('claimName')=='headlamp-plugins' or v.get('name')=='plugins' for v in vols) else '')") + HAS_MOUNT=$(echo "$DEPLOY_JSON" | \ + python3 -c "import sys,json; d=json.load(sys.stdin); mounts=d['spec']['template']['spec']['containers'][0].get('volumeMounts',[]); print('yes' if any(m.get('mountPath')=='/headlamp/plugins' or m.get('name')=='plugins' for m in mounts) else '')") + + NEEDS_PATCH=false + if [ -z "$HAS_VOL" ]; then + echo "Adding plugins PVC volume..." kubectl patch deploy "$DEPLOY" -n "$NS" --type=json -p '[ {"op":"add","path":"/spec/template/spec/volumes/-","value":{ "name":"plugins", "persistentVolumeClaim":{"claimName":"headlamp-plugins"} }} ]' + NEEDS_PATCH=true + else + echo "Plugins volume already present, skipping." fi - # Add the volume mount to the first container if not already present - HAS_MOUNT=$(kubectl get deploy "$DEPLOY" -n "$NS" \ - -o jsonpath='{.spec.template.spec.containers[0].volumeMounts[?(@.name=="plugins")].name}') if [ -z "$HAS_MOUNT" ]; then + echo "Adding plugins volume mount..." kubectl patch deploy "$DEPLOY" -n "$NS" --type=json -p '[ {"op":"add","path":"/spec/template/spec/containers/0/volumeMounts/-","value":{ "name":"plugins", @@ -66,6 +74,9 @@ jobs: "readOnly":true }} ]' + NEEDS_PATCH=true + else + echo "Plugins volume mount already present, skipping." fi # Set the plugins directory via env var