-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhf.cluster.patch.sh
More file actions
executable file
·28 lines (22 loc) · 974 Bytes
/
hf.cluster.patch.sh
File metadata and controls
executable file
·28 lines (22 loc) · 974 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/bash
# Increment the counter field in cluster spec or labels
# Usage: hf.cluster.patch.sh spec|labels [cluster_id]
source "$(dirname "$(realpath "$0")")/hf.lib.sh"
hf_require_config api-url api-version cluster-id
hf_require_jq
TARGET="${1:-}"
if [[ "$TARGET" != "spec" && "$TARGET" != "labels" ]]; then
hf_usage "spec|labels [cluster_id]"
echo "Arguments:"
echo " spec|labels Which section to increment the counter field in (required)"
echo " cluster_id Cluster ID (default: current cluster)"
exit 1
fi
CLUSTER_ID=$(hf_cluster_id "${2:-}")
hf_info "Fetching cluster: $CLUSTER_ID"
CURRENT=$(hf_get "/clusters/${CLUSTER_ID}")
COUNTER=$(echo "$CURRENT" | jq -r ".${TARGET}.counter // \"0\"")
NEW_COUNTER=$((COUNTER + 1))
hf_info "Incrementing ${TARGET}.counter: $COUNTER → $NEW_COUNTER"
PAYLOAD=$(echo "$CURRENT" | jq --arg t "$TARGET" --arg v "$NEW_COUNTER" '{($t): (.[$t] + {counter: $v})}')
hf_patch "/clusters/${CLUSTER_ID}" "$PAYLOAD" | jq