From 8ba05883f7bea006f3c840277f84416adb884382 Mon Sep 17 00:00:00 2001 From: "juvenal.diaz" Date: Mon, 2 Nov 2026 14:02:11 -0600 Subject: [PATCH] Allow guarded k3s platform bootstrap preflight --- lib/jeannie/pipeline.sh | 7 ++++++- scripts/scheduling-preflight.py | 28 +++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/lib/jeannie/pipeline.sh b/lib/jeannie/pipeline.sh index a058f92..19a7d21 100644 --- a/lib/jeannie/pipeline.sh +++ b/lib/jeannie/pipeline.sh @@ -840,11 +840,15 @@ kubernetes_scheduling_preflight() { shift local directory status arg plan_output retry_pattern local -a plan_args=() + local -a preflight_args=() [[ "${stack}" == "bootstrap/platform" || "${stack}" == "bootstrap/apps" ]] || return 0 if [[ -z "${LAB_CLUSTER_CONTROL_PLANE_NODE_NAME:-}" ]]; then echo "Scheduling preflight requires the selected control-plane node name." >&2 return 1 fi + if [[ "${stack}" == "bootstrap/platform" && "${LAB_CLUSTER_PROFILE:-}" == "k3s" ]]; then + preflight_args+=(--bootstrap-node "${LAB_CLUSTER_CONTROL_PLANE_NODE_NAME}") + fi for arg in "$@"; do [[ "${arg}" == "-auto-approve" ]] || plan_args+=("${arg}") done @@ -874,7 +878,8 @@ kubernetes_scheduling_preflight() { status=0 python3 "${REPO_ROOT}/scripts/scheduling-preflight.py" \ --plan "${directory}/plan.json" --kubeconfig "${KUBECONFIG_PATH}" \ - --repo-root "${REPO_ROOT}" --expected-node "${LAB_CLUSTER_CONTROL_PLANE_NODE_NAME}" || status=$? + --repo-root "${REPO_ROOT}" --expected-node "${LAB_CLUSTER_CONTROL_PLANE_NODE_NAME}" \ + "${preflight_args[@]}" || status=$? # The private directory can contain sensitive planned chart values. rm -rf -- "${directory}" return "${status}" diff --git a/scripts/scheduling-preflight.py b/scripts/scheduling-preflight.py index 9ead249..13c420c 100644 --- a/scripts/scheduling-preflight.py +++ b/scripts/scheduling-preflight.py @@ -165,7 +165,7 @@ def repository_identity(url): class Estimate: - def __init__(self, nodes, pods, controllers, pvcs, pvs, storage_classes=(), namespaces=()): + def __init__(self, nodes, pods, controllers, pvcs, pvs, storage_classes=(), namespaces=(), bootstrap_node=None): self.nodes = {n["metadata"]["name"]: n for n in nodes} self.pods = [p for p in pods if p.get("status", {}).get("phase") not in ("Succeeded", "Failed")] self.controllers = {identity(c): c for c in controllers} @@ -174,6 +174,7 @@ class Estimate: self.storage_classes = {s["metadata"]["name"]: s for s in storage_classes} self.namespaces = {n["metadata"]["name"]: n["metadata"].get("labels", {}) for n in namespaces} self.notices = set() + self.bootstrap_node = bootstrap_node def notice(self, message): if message not in self.notices: @@ -284,16 +285,28 @@ class Estimate: reasons.append("nodeName mismatch") if node.get("spec", {}).get("unschedulable"): reasons.append("cordoned") - if not any(c["type"] == "Ready" and c["status"] == "True" for c in node.get("status", {}).get("conditions", [])): + node_ready = any(c["type"] == "Ready" and c["status"] == "True" for c in node.get("status", {}).get("conditions", [])) + bootstrap = name == self.bootstrap_node + if not node_ready and not bootstrap: reasons.append("NotReady") - if any(labels.get(k) != v for k, v in spec.get("nodeSelector", {}).items()): + selector_mismatch = any(labels.get(k) != v for k, v in spec.get("nodeSelector", {}).items()) + if bootstrap and spec.get("nodeSelector", {}).get("homelab.dev/workload-class") == "platform": + # The k3s bootstrap node receives this label from the cluster + # stack, but platform is intentionally checked before that apply. + selector_mismatch = any( + k != "homelab.dev/workload-class" and labels.get(k) != v + for k, v in spec.get("nodeSelector", {}).items() + ) + if selector_mismatch: reasons.append("nodeSelector mismatch") affinity = spec.get("affinity", {}) required = affinity.get("nodeAffinity", {}).get("requiredDuringSchedulingIgnoredDuringExecution") if required is not None and not affinity_matches(required, node): reasons.append("required node affinity mismatch") for taint in node.get("spec", {}).get("taints", []): - if taint["effect"] in ("NoSchedule", "NoExecute") and not tolerates(taint, spec.get("tolerations", [])): + if (taint["effect"] in ("NoSchedule", "NoExecute") + and not (bootstrap and taint.get("key") == "node.kubernetes.io/not-ready") + and not tolerates(taint, spec.get("tolerations", []))): reasons.append(f"untolerated taint {taint['key']}") namespace = pod["metadata"].get("namespace", "default") for volume in spec.get("volumes") or []: @@ -310,6 +323,9 @@ class Estimate: defaults = [s for s in self.storage_classes.values() if s["metadata"].get("annotations", {}).get("storageclass.kubernetes.io/is-default-class") == "true"] storage_class = defaults[0] if len(defaults) == 1 else None if not storage_class or storage_class.get("provisioner") == "kubernetes.io/no-provisioner": + if self.bootstrap_node: + self.notice(f"{namespace}/{claim}: dynamic storage will be provided by the platform bootstrap") + continue raise CannotCheck(f"{namespace}/{claim}: unbound claim has no known dynamic provisioner") selected_node = pvc["metadata"].get("annotations", {}).get("volume.kubernetes.io/selected-node") if selected_node and selected_node != name: @@ -621,6 +637,7 @@ def main(): parser.add_argument("--kubeconfig", required=True) parser.add_argument("--repo-root", required=True) parser.add_argument("--expected-node", required=True) + parser.add_argument("--bootstrap-node", help="Allow the selected node to be NotReady while the initial CNI/storage platform is installed") args = parser.parse_args() kubectl = ["kubectl", "--kubeconfig", args.kubeconfig, "--request-timeout=15s"] nodes = json.loads(run(kubectl + ["get", "nodes", "-o", "json"]))["items"] @@ -633,7 +650,8 @@ def main(): with open(args.plan, encoding="utf-8") as handle: documents = manifests_from_plan(args, json.load(handle), kubectl) engine = Estimate(nodes, [p for p in objects if p["kind"] == "Pod"], objects, - [p for p in objects if p["kind"] == "PersistentVolumeClaim"], pvs, storage_classes, namespaces) + [p for p in objects if p["kind"] == "PersistentVolumeClaim"], pvs, storage_classes, namespaces, + bootstrap_node=args.bootstrap_node) for item in documents: if item["kind"] == "PersistentVolumeClaim": key = item["metadata"]["namespace"], item["metadata"]["name"]