fix(longhorn): use jq instead of jsonpath for node/volume queries

bitnami/kubectl:latest includes jq, simpler than complex jsonpath filters.
Tested: successfully expanded all 1-replica volumes to 3 replicas.
This commit is contained in:
Story Crater Bot
2026-07-22 08:57:02 -07:00
parent e76ad914d2
commit 1685bca027
@@ -1,6 +1,4 @@
# PostSync hook Job that expands all Longhorn volumes to 3 replicas.
# Runs after the longhorn-config Application syncs (which adds cp-2/cp-3 nodes
# + taint toleration), ensuring there are 3 nodes available before expanding.
apiVersion: batch/v1
kind: Job
metadata:
@@ -28,9 +26,8 @@ spec:
echo "Waiting for all 3 Longhorn nodes to be Ready..."
for i in {1..30}; do
READY_COUNT=$(kubectl -n longhorn-system get nodes.longhorn.io \
-o jsonpath='{range .items[?(@.status.conditions[?(@.type=="Ready")].status=="True")]}{.metadata.name}{"\n"}{end}' \
| wc -l | tr -d ' ')
READY_COUNT=$(kubectl -n longhorn-system get nodes.longhorn.io -o json | \
jq -r '[.items[] | select(.status.conditions[] | select(.type=="Ready" and .status=="True"))] | length')
if [ "$READY_COUNT" -ge 3 ]; then
echo "✓ All 3 nodes Ready"
@@ -49,16 +46,19 @@ spec:
echo
echo "Expanding volumes with < 3 replicas..."
kubectl -n longhorn-system get volumes.longhorn.io \
-o jsonpath='{range .items[?(@.spec.numberOfReplicas<3)]}{.metadata.name}{"\n"}{end}' | \
while read -r vol; do
if [ -n "$vol" ]; then
VOLUMES=$(kubectl -n longhorn-system get volumes.longhorn.io -o json | \
jq -r '.items[] | select(.spec.numberOfReplicas < 3) | .metadata.name')
if [ -z "$VOLUMES" ]; then
echo " No volumes need expansion"
else
echo "$VOLUMES" | while read -r vol; do
CURRENT=$(kubectl -n longhorn-system get volume "$vol" -o jsonpath='{.spec.numberOfReplicas}')
echo " $vol: $CURRENT → 3 replicas"
kubectl -n longhorn-system patch volume "$vol" --type merge \
-p '{"spec":{"numberOfReplicas":3}}'
fi
done
done
fi
echo
echo "Done. Final replica counts:"