From 334fbbb9e3d1c71f4e42593a3c37036bf68171d2 Mon Sep 17 00:00:00 2001 From: Erich Blume Date: Wed, 18 Mar 2026 12:53:00 -0700 Subject: [PATCH] Fix TeslaMate/UnPoller dashboard UID sed clobbering datasource refs The previous sed replaced ALL "uid" fields in dashboard JSON files, including datasource references inside panels, causing dashboards to go dark. Scope the replacement to only the first occurrence (the top-level dashboard UID) using GNU sed 0,/pattern/ addressing. Co-Authored-By: Claude Opus 4.6 (1M context) --- argocd/manifests/grafana/deployment.yaml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/argocd/manifests/grafana/deployment.yaml b/argocd/manifests/grafana/deployment.yaml index 2f4c7b8..3fda945 100644 --- a/argocd/manifests/grafana/deployment.yaml +++ b/argocd/manifests/grafana/deployment.yaml @@ -80,10 +80,12 @@ spec: ; do wget -q -O "$DEST/$f" "$BASE_URL/$f" done - # Stamp stable UIDs so stars/bookmarks survive pod restarts + # Stamp stable top-level UIDs so stars/bookmarks survive pod restarts + # Uses 0,/pattern/ to replace only the first "uid" (the dashboard UID), + # leaving datasource UIDs inside panels untouched. for f in "$DEST"/*.json; do uid="teslamate-$(basename "$f" .json)" - sed -i "s/\"uid\": *\"[^\"]*\"/\"uid\": \"${uid}\"/" "$f" + sed -i "0,/\"uid\": *\"[^\"]*\"/{s/\"uid\": *\"[^\"]*\"/\"uid\": \"${uid}\"/}" "$f" done echo "Fetched $(ls "$DEST" | wc -l) TeslaMate dashboards" securityContext: @@ -120,11 +122,11 @@ spec: # Fix datasource UIDs to match our Prometheus instance sed -i 's/"uid": *"bdkj55oguty4gd"/"uid": "prometheus"/g' "$DEST"/*.json sed -i 's/"uid": *"\${DS_PROMETHEUS}"/"uid": "prometheus"/g' "$DEST"/*.json - # Stamp stable UIDs so stars/bookmarks survive pod restarts + # Stamp stable top-level UIDs so stars/bookmarks survive pod restarts for f in "$DEST"/*.json; do slug=$(basename "$f" .json | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g' | sed 's/--*/-/g' | sed 's/^-//;s/-$//') uid="unpoller-${slug}" - sed -i "s/\"uid\": *\"[^\"]*\"/\"uid\": \"${uid}\"/" "$f" + sed -i "0,/\"uid\": *\"[^\"]*\"/{s/\"uid\": *\"[^\"]*\"/\"uid\": \"${uid}\"/}" "$f" done echo "Fetched $(ls "$DEST" | wc -l) UnPoller dashboards" securityContext: