Preserve manual worker topology file
This commit is contained in:
parent
8cd0b14e5e
commit
1a8bf9a77d
62
jeannie
62
jeannie
|
|
@ -957,8 +957,11 @@ sudo '${qm_bin}' start '${vmid}'"
|
|||
}
|
||||
|
||||
write_cluster_worker_var_file() {
|
||||
local spec_file="$1"
|
||||
local var_file="$2"
|
||||
local var_file="$1"
|
||||
local default_platform_labels_json='{"node-role.kubernetes.io/worker":"worker","homelab.dev/node-role":"app","homelab.dev/storage":"ssd","homelab.dev/workload-class":"platform"}'
|
||||
local pimox_labels_json="${LAB_PIMOX_WORKER_NODE_LABELS_JSON:-${default_platform_labels_json}}"
|
||||
local manual_labels_json="${LAB_MANUAL_WORKER_NODE_LABELS_JSON:-${pimox_labels_json}}"
|
||||
shift
|
||||
|
||||
LAB_INCLUDE_RASPBERRY_WORKER="${LAB_INCLUDE_RASPBERRY_WORKER:-false}" \
|
||||
LAB_RASPBERRY_HOST="${LAB_RASPBERRY_HOST:-192.168.100.89}" \
|
||||
|
|
@ -966,18 +969,22 @@ write_cluster_worker_var_file() {
|
|||
LAB_RASPBERRY_NODE_NAME="${LAB_RASPBERRY_NODE_NAME:-raspberry}" \
|
||||
LAB_RASPBERRY_SSH_KEY_PATH="${LAB_RASPBERRY_SSH_KEY_PATH:-/home/jv/.ssh/id_ed25519}" \
|
||||
LAB_RASPBERRY_NODE_LABELS_JSON="${LAB_RASPBERRY_NODE_LABELS_JSON:-{\"node-role.kubernetes.io/worker\":\"worker\",\"homelab.dev/node-role\":\"edge-app\",\"homelab.dev/storage\":\"local\",\"homelab.dev/workload-class\":\"edge\"}}" \
|
||||
LAB_PIMOX_WORKER_NODE_LABELS_JSON="${LAB_PIMOX_WORKER_NODE_LABELS_JSON:-{\"node-role.kubernetes.io/worker\":\"worker\",\"homelab.dev/node-role\":\"app\",\"homelab.dev/storage\":\"ssd\",\"homelab.dev/workload-class\":\"platform\"}}" \
|
||||
python3 - "${spec_file}" "${var_file}" <<'PY'
|
||||
LAB_MANUAL_WORKER_NODE_LABELS_JSON="${manual_labels_json}" \
|
||||
LAB_PIMOX_WORKER_NODE_LABELS_JSON="${pimox_labels_json}" \
|
||||
python3 - "${var_file}" "$@" <<'PY'
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
spec_file, var_file = sys.argv[1:3]
|
||||
var_file = sys.argv[1]
|
||||
spec_files = sys.argv[2:]
|
||||
nodes = {}
|
||||
node_labels = {}
|
||||
|
||||
try:
|
||||
raspberry_labels = json.loads(os.environ["LAB_RASPBERRY_NODE_LABELS_JSON"])
|
||||
manual_labels = json.loads(os.environ["LAB_MANUAL_WORKER_NODE_LABELS_JSON"])
|
||||
pimox_labels = json.loads(os.environ["LAB_PIMOX_WORKER_NODE_LABELS_JSON"])
|
||||
except json.JSONDecodeError as exc:
|
||||
raise SystemExit(f"Invalid node label JSON: {exc}") from exc
|
||||
|
|
@ -991,19 +998,30 @@ if os.environ["LAB_INCLUDE_RASPBERRY_WORKER"].lower() not in {"0", "false", "no"
|
|||
}
|
||||
node_labels["raspberrypi"] = raspberry_labels
|
||||
|
||||
with open(spec_file, encoding="utf-8") as handle:
|
||||
for line in handle:
|
||||
line = line.rstrip("\n")
|
||||
if not line:
|
||||
continue
|
||||
key, host, user, node_name, ssh_key_path = line.split("\t")
|
||||
nodes[key] = {
|
||||
"host": host,
|
||||
"user": user,
|
||||
"node_name": node_name,
|
||||
"ssh_key_path": ssh_key_path,
|
||||
}
|
||||
node_labels[key] = pimox_labels
|
||||
for spec_file in spec_files:
|
||||
path = Path(spec_file)
|
||||
if not path.exists() or path.stat().st_size == 0:
|
||||
continue
|
||||
labels = pimox_labels if path.name == "pimox-workers.tsv" else manual_labels
|
||||
with path.open(encoding="utf-8") as handle:
|
||||
for line_number, line in enumerate(handle, start=1):
|
||||
line = line.rstrip("\n")
|
||||
if not line or line.startswith("#"):
|
||||
continue
|
||||
try:
|
||||
key, host, user, node_name, ssh_key_path = line.split("\t")
|
||||
except ValueError as exc:
|
||||
raise SystemExit(
|
||||
f"{spec_file}:{line_number}: expected tab-separated "
|
||||
"key, host, user, node_name, ssh_key_path"
|
||||
) from exc
|
||||
nodes[key] = {
|
||||
"host": host,
|
||||
"user": user,
|
||||
"node_name": node_name,
|
||||
"ssh_key_path": ssh_key_path,
|
||||
}
|
||||
node_labels[key] = labels
|
||||
|
||||
with open(var_file, "w", encoding="utf-8") as handle:
|
||||
json.dump({"worker_nodes": nodes, "worker_node_labels": node_labels}, handle, indent=2)
|
||||
|
|
@ -1013,14 +1031,14 @@ PY
|
|||
|
||||
prepare_cluster_worker_var_file() {
|
||||
local include_raspberry_default="$1"
|
||||
local spec_file="${REPO_ROOT}/.lab/manual-workers.tsv"
|
||||
local manual_spec_file="${REPO_ROOT}/.lab/manual-workers.tsv"
|
||||
local pimox_spec_file="${REPO_ROOT}/.lab/pimox-workers.tsv"
|
||||
local var_file="${REPO_ROOT}/.lab/cluster-workers.auto.tfvars.json"
|
||||
|
||||
export LAB_INCLUDE_RASPBERRY_WORKER="${LAB_INCLUDE_RASPBERRY_WORKER:-${include_raspberry_default}}"
|
||||
|
||||
mkdir -p "${REPO_ROOT}/.lab"
|
||||
: >"${spec_file}"
|
||||
write_cluster_worker_var_file "${spec_file}" "${var_file}"
|
||||
write_cluster_worker_var_file "${var_file}" "${manual_spec_file}" "${pimox_spec_file}"
|
||||
export LAB_CLUSTER_VAR_FILE="${var_file}"
|
||||
}
|
||||
|
||||
|
|
@ -1447,7 +1465,7 @@ fi" 2>&1)"
|
|||
"${worker_cpu_affinity}"
|
||||
done
|
||||
|
||||
write_cluster_worker_var_file "${spec_file}" "${var_file}"
|
||||
write_cluster_worker_var_file "${var_file}" "${REPO_ROOT}/.lab/manual-workers.tsv" "${spec_file}"
|
||||
export LAB_CLUSTER_VAR_FILE="${var_file}"
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue