Compare commits

..

No commits in common. "0a26ca03a482f05f17bbea03b85bd57defc8de2a" and "3f7ff10131da4256ef25dd5e6556f361cc398d2d" have entirely different histories.

10 changed files with 22 additions and 214 deletions

View File

@ -13,89 +13,7 @@ terraform {
}
}
resource "null_resource" "k3s_control_plane" {
count = local.k3s_enabled ? 1 : 0
triggers = {
node_name = var.control_plane_node_name
host = var.control_plane_host
user = var.control_plane_user
ssh_key_path = var.control_plane_ssh_key_path
advertise_address = var.control_plane_advertise_address
kubeconfig_path = var.kubeconfig_path
kubeconfig_owner = var.kubeconfig_owner
k3s_version = var.k3s_version
pod_network_cidr = var.pod_network_cidr
}
connection {
type = "ssh"
user = self.triggers.user
private_key = file(self.triggers.ssh_key_path)
host = self.triggers.host
timeout = "30m"
}
provisioner "remote-exec" {
inline = [<<EOT
set -euo pipefail
if sudo test -s /etc/kubernetes/manifests/kube-apiserver.yaml || sudo test -s /etc/kubernetes/admin.conf; then
echo "A kubeadm control plane is already present; refusing to install k3s over it." >&2
exit 1
fi
if ! command -v k3s >/dev/null 2>&1; then
curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION='${self.triggers.k3s_version}' sh -s - server \
--node-name '${self.triggers.node_name}' \
--node-ip '${self.triggers.advertise_address}' \
--advertise-address '${self.triggers.advertise_address}' \
--flannel-backend=none --disable-network-policy --disable=traefik \
--write-kubeconfig-mode=0644 --cluster-cidr '${self.triggers.pod_network_cidr}'
fi
sudo systemctl enable k3s >/dev/null
sudo systemctl restart k3s
for _ in $(seq 1 90); do
if sudo k3s kubectl get --raw=/readyz >/dev/null 2>&1; then exit 0; fi
sleep 2
done
sudo systemctl status k3s --no-pager -l || true
sudo journalctl -u k3s --no-pager -n 160 || true
exit 1
EOT
]
}
}
resource "null_resource" "k3s_kubeconfig" {
count = local.k3s_enabled ? 1 : 0
depends_on = [null_resource.k3s_control_plane]
triggers = {
control_plane_id = null_resource.k3s_control_plane[0].id
host = var.control_plane_host
user = var.control_plane_user
ssh_key_path = var.control_plane_ssh_key_path
advertise_address = var.control_plane_advertise_address
kubeconfig_path = var.kubeconfig_path
kubeconfig_owner = var.kubeconfig_owner
}
provisioner "local-exec" {
interpreter = ["/bin/bash", "-lc"]
command = <<EOT
set -euo pipefail
tmp_file="$(mktemp)"
trap 'rm -f "$tmp_file"' EXIT
mkdir -p "$(dirname "${self.triggers.kubeconfig_path}")"
ssh -i "${self.triggers.ssh_key_path}" -o BatchMode=yes -o ConnectTimeout=10 -o StrictHostKeyChecking=accept-new \
"${self.triggers.user}@${self.triggers.host}" "sudo cat /etc/rancher/k3s/k3s.yaml" >"$tmp_file"
sed -i "s#https://127.0.0.1:6443#https://${self.triggers.advertise_address}:6443#g" "$tmp_file"
install -m 0600 "$tmp_file" "${self.triggers.kubeconfig_path}"
EOT
}
}
locals {
kubeadm_enabled = var.cluster_runtime == "kubeadm"
k3s_enabled = var.cluster_runtime == "k3s"
}
resource "null_resource" "kubeadm_control_plane" {
count = local.kubeadm_enabled ? 1 : 0
triggers = {
node_name = var.control_plane_node_name
advertise_address = var.control_plane_advertise_address
@ -572,11 +490,10 @@ EOT
}
resource "null_resource" "kubeconfig_pullback" {
count = local.kubeadm_enabled ? 1 : 0
depends_on = [null_resource.kubeadm_control_plane]
triggers = {
control_plane_id = null_resource.kubeadm_control_plane[0].id
control_plane_id = null_resource.kubeadm_control_plane.id
host = var.control_plane_host
user = var.control_plane_user
ssh_key_path = var.control_plane_ssh_key_path
@ -608,7 +525,6 @@ EOT
}
resource "null_resource" "kube_system_resource_policy" {
count = local.kubeadm_enabled ? 1 : 0
depends_on = [null_resource.kubeconfig_pullback]
triggers = {
@ -759,7 +675,6 @@ EOT
}
resource "null_resource" "worker_nodes_required" {
count = local.kubeadm_enabled ? 1 : 0
triggers = {
worker_count = tostring(length(var.worker_nodes))
}
@ -773,7 +688,7 @@ resource "null_resource" "worker_nodes_required" {
}
resource "null_resource" "kubeadm_worker" {
for_each = local.kubeadm_enabled ? var.worker_nodes : {}
for_each = var.worker_nodes
depends_on = [
null_resource.kubeadm_control_plane,
@ -1667,8 +1582,6 @@ resource "null_resource" "node_labels" {
null_resource.kubeadm_control_plane,
null_resource.kubeconfig_pullback,
null_resource.kubeadm_worker,
null_resource.k3s_control_plane,
null_resource.k3s_kubeconfig,
]
triggers = {

View File

@ -3,23 +3,6 @@ variable "control_plane_node_name" {
default = "debian"
}
variable "cluster_runtime" {
type = string
description = "Control-plane runtime to install on the selected profile host."
default = "kubeadm"
validation {
condition = contains(["kubeadm", "k3s"], var.cluster_runtime)
error_message = "cluster_runtime must be kubeadm or k3s."
}
}
variable "k3s_version" {
type = string
description = "Pinned k3s release installed for the direct Debian profile."
default = "v1.31.5+k3s1"
}
variable "control_plane_node_labels" {
type = map(string)
default = {

View File

@ -26,7 +26,7 @@ const maxOutputBytes = 1 << 20
// with the public top-level cases in ./jeannie. Internal __up-task and the
// recursive remote command are intentionally excluded.
var allowedCommands = map[string]bool{
"help": true, "up": true, "plan": true, "cluster": true, "cluster-context": true,
"help": true, "up": true, "plan": true,
"cluster-profile": true, "rebuild-cluster": true, "stop-cluster": true,
"start-cluster": true, "cleanup-debian-k8s": true,
"shutdown": true, "start": true,

View File

@ -112,14 +112,6 @@ func TestStorageCommandIsRemotelyEnabled(t *testing.T) {
}
}
func TestClusterBootstrapCommandsAreRemotelyEnabled(t *testing.T) {
for _, command := range []string{"cluster", "cluster-context", "stop-cluster", "cleanup-debian-k8s", "platform", "apps"} {
if !allowedCommands[command] {
t.Fatalf("%s must be exposed through the remote API", command)
}
}
}
func TestMeshCommandIsRemotelyEnabled(t *testing.T) {
if !allowedCommands["mesh"] {
t.Fatal("mesh must be exposed through the remote API")

View File

@ -88,26 +88,6 @@ cluster:
control_plane_vmid: 9001
worker_count: 2
worker_static_ips: 192.168.100.66 192.168.100.67
k3s:
control_plane:
node_name: debian
lan_ip: 192.168.100.73
user: jv
ssh_key_path: /home/jv/.ssh/id_ed25519
kubeconfig: /home/jv/.kube/k3s-config
kubeconfig_owner: jv:jv
registry:
endpoint: 192.168.100.73:30500
provisioning:
host: 192.168.100.73
user: jv
http:
host: 192.168.100.73
gitops:
repo_url: ssh://git@192.168.100.73:32222/jv/my-homelab-configs.git
platform:
calico_operator_node_name: debian
runtime: k3s
hosts:
debian:

View File

@ -59,7 +59,6 @@ Base, Inventory, And Planning
Build And Bootstrap
up Deploy the full homelab pipeline.
cluster Apply the selected cluster runtime only.
deploy-gitea Deploy the Debian-hosted Gitea container.
deploy-api Deploy the Temporal-backed Jeannie API on Debian.
deploy-heimdall Deploy the Debian-hosted Heimdall dashboard.
@ -263,9 +262,6 @@ case "${1:-}" in
record_change_journal "up" "$@"
up
;;
cluster)
cluster_apply "${@:2}"
;;
plan)
plan_homelab "${2:-all}"
;;

View File

@ -8,7 +8,7 @@ plan_homelab() {
require_debian_server "plan"
if [[ "${target}" == "all" ]]; then
if [[ -z "${LAB_CLUSTER_VAR_FILE:-}" && "${LAB_CLUSTER_RUNTIME:-kubeadm}" != "k3s" ]]; then
if [[ -z "${LAB_CLUSTER_VAR_FILE:-}" ]]; then
prepare_cluster_worker_var_file false
fi
stacks=(
@ -20,7 +20,7 @@ plan_homelab() {
)
else
stack="$(tofu_stack_from_plan_target "${target}")"
if [[ "${stack}" == "bootstrap/cluster" && -z "${LAB_CLUSTER_VAR_FILE:-}" && "${LAB_CLUSTER_RUNTIME:-kubeadm}" != "k3s" ]]; then
if [[ "${stack}" == "bootstrap/cluster" && -z "${LAB_CLUSTER_VAR_FILE:-}" ]]; then
prepare_cluster_worker_var_file false
fi
stacks=("${stack}")
@ -142,7 +142,6 @@ Provisioning host: ${LAB_CLUSTER_PROVISIONING_HOST:-${LAB_DEBIAN_LAN_IP:-}}
Provisioning user: ${LAB_CLUSTER_PROVISIONING_USER:-${LAB_DEBIAN_USER:-}}
GitOps repo URL: ${LAB_GITOPS_REPO_URL:-}
Calico operator node: ${LAB_CALICO_OPERATOR_NODE_NAME:-${LAB_CLUSTER_CONTROL_PLANE_NODE_NAME:-}}
Cluster runtime: ${LAB_CLUSTER_RUNTIME:-kubeadm}
External services host: ${LAB_SERVICES_HOST:-debian} (${LAB_SERVICES_HOST_LAN_IP:-${LAB_DEBIAN_LAN_IP:-}}, tailscale ${LAB_SERVICES_HOST_TAILSCALE_IP:-${LAB_DEBIAN_TAILSCALE_IP:-}})
Gitea backend host: ${LAB_GITEA_BACKEND_HOST:-${LAB_GITEA_TAILSCALE_IP:-${LAB_GITEA_HOST:-}}}
Dex backend host: ${LAB_DEX_BACKEND_HOST:-${LAB_DEBIAN_TAILSCALE_IP:-}}
@ -156,15 +155,6 @@ Pimox worker static IPs: ${LAB_CLUSTER_PIMOX_WORKER_STATIC_IPS:-${LAB_PIMOX_WORK
EOF
}
cluster_apply() {
require_debian_server "cluster"
record_change_journal "cluster" "$@"
jeannie_log_start "cluster"
jeannie_step_plan 1
run_step "Cluster OpenTofu apply" run_tofu_stack "bootstrap/cluster"
echo "Log: ${JEANNIE_LOG_FILE}"
}
rebuild_cluster() {
require_debian_server "rebuild-cluster"

View File

@ -152,7 +152,6 @@ profile_mapping = {
"http.host": ("LAB_CLUSTER_HTTP_HOST", "hosts.debian.lan_ip"),
"gitops.repo_url": ("LAB_GITOPS_REPO_URL", "services.gitea.ssh_remote"),
"platform.calico_operator_node_name": ("LAB_CALICO_OPERATOR_NODE_NAME", None),
"runtime": ("LAB_CLUSTER_RUNTIME", "cluster.runtime"),
"pimox.host": ("LAB_CLUSTER_PIMOX_HOST", "hosts.opi5_pimox.lan_ip"),
"pimox.user": ("LAB_CLUSTER_PIMOX_USER", "hosts.opi5_pimox.user"),
"pimox.bridge": ("LAB_CLUSTER_PIMOX_BRIDGE", "hosts.opi5_pimox.bridge"),
@ -250,9 +249,6 @@ export_if_unset() {
}
export_homelab_inventory_tf_vars() {
if [[ "${LAB_CLUSTER_PROFILE:-}" == "k3s" ]]; then
export LAB_CLUSTER_RUNTIME=k3s
fi
export_if_unset TF_VAR_kubeconfig_path "${LAB_KUBECONFIG_PATH:-}"
export_if_unset TF_VAR_control_plane_node_name "${LAB_CLUSTER_CONTROL_PLANE_NODE_NAME:-debian}"
export_if_unset TF_VAR_control_plane_advertise_address "${LAB_CLUSTER_CONTROL_PLANE_LAN_IP:-${LAB_DEBIAN_LAN_IP:-}}"
@ -265,7 +261,6 @@ export_homelab_inventory_tf_vars() {
export_if_unset TF_VAR_provisioning_user "${LAB_CLUSTER_PROVISIONING_USER:-${LAB_DEBIAN_USER:-}}"
export_if_unset TF_VAR_http_host "${LAB_CLUSTER_HTTP_HOST:-${LAB_CLUSTER_CONTROL_PLANE_LAN_IP:-${LAB_DEBIAN_LAN_IP:-}}}"
export_if_unset TF_VAR_pimox_host "${LAB_CLUSTER_PIMOX_HOST:-${LAB_PIMOX_HOST:-}}"
export_if_unset TF_VAR_cluster_runtime "${LAB_CLUSTER_RUNTIME:-kubeadm}"
export_if_unset TF_VAR_pimox_user "${LAB_CLUSTER_PIMOX_USER:-${LAB_PIMOX_USER:-}}"
export_if_unset TF_VAR_pimox_worker_storage "${LAB_CLUSTER_PIMOX_STORAGE:-${LAB_PIMOX_WORKER_STORAGE:-}}"
export_if_unset TF_VAR_pimox_template_bridge "${LAB_CLUSTER_PIMOX_BRIDGE:-${LAB_PIMOX_BRIDGE:-}}"

View File

@ -971,10 +971,7 @@ run_tofu_stack() {
local -a apply_args=()
local target
# A new profile has no pinned identity until its control plane bootstrap
# completes. Platform/apps remain guarded by cluster-context as usual.
if [[ "${stack}" == "bootstrap/platform" || "${stack}" == "bootstrap/apps" ]] ||
[[ "${stack}" == "bootstrap/cluster" && -f "${HOMELAB_STATE_DIR}/clusters/${LAB_CLUSTER_PROFILE}/identity.json" ]]; then
if [[ "${stack}" == "bootstrap/cluster" || "${stack}" == "bootstrap/platform" || "${stack}" == "bootstrap/apps" ]]; then
cluster_context_require || return 1
fi
@ -986,7 +983,7 @@ run_tofu_stack() {
shift
done
if [[ "${stack}" == "bootstrap/cluster" && "${LAB_CLUSTER_RUNTIME:-kubeadm}" != "k3s" ]]; then
if [[ "${stack}" == "bootstrap/cluster" ]]; then
ensure_cluster_worker_var_file
fi
if [[ "${stack}" == "bootstrap/edge" ]]; then
@ -1054,7 +1051,7 @@ run_tofu_plan_stack() {
local stack="$1"
local -a plan_args=()
if [[ "${stack}" == "bootstrap/cluster" && "${LAB_CLUSTER_RUNTIME:-kubeadm}" != "k3s" ]]; then
if [[ "${stack}" == "bootstrap/cluster" ]]; then
ensure_cluster_worker_var_file
fi
if [[ "${stack}" == "bootstrap/edge" ]]; then
@ -8967,11 +8964,6 @@ ensure_edge_haproxy_stats_password() {
}
ensure_cluster_worker_var_file() {
if [[ "${LAB_CLUSTER_RUNTIME:-kubeadm}" == "k3s" ]]; then
rm -f "${REPO_ROOT}/.lab/cluster-workers.auto.tfvars.json"
unset LAB_CLUSTER_VAR_FILE
return 0
fi
if [[ -z "${LAB_CLUSTER_VAR_FILE:-}" ]]; then
prepare_cluster_worker_var_file false
fi
@ -9133,10 +9125,6 @@ up_task() {
deploy_rpi_services
;;
pimox-workers)
if [[ "${LAB_CLUSTER_RUNTIME:-kubeadm}" == "k3s" ]]; then
echo "Skipping Pimox worker provisioning for the direct Debian k3s profile."
return 0
fi
run_pimox_pipeline
;;
openwrt)

View File

@ -421,36 +421,16 @@ def proxy_tofu(args):
raise Refused("State/backend overrides are refused; use cluster-context migrate for reviewed legacy state")
legacy = directory / "terraform.tfstate"
if not state.exists() and legacy.exists():
fresh_k3s_cluster = (
name == "cluster"
and os.environ.get("TF_VAR_cluster_runtime") == "k3s"
and not context.binding.exists()
)
if fresh_k3s_cluster:
# The retained legacy state belongs to another profile. The
# scoped backend initializer will seed a new empty k3s state;
# never migrate or inspect the legacy snapshot here.
legacy = None
if legacy is None:
pass
else:
record = legacy_record(context, legacy)
if legacy is not None:
owner = document(record) if record.exists() else {}
if legacy is not None:
owner_profile = owner.get("profile", "")
if legacy is not None:
owner_binding = context.root.parent / owner_profile / "identity.json" if re.fullmatch(r"[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}", owner_profile) else None
if legacy is not None:
owner_identity = document(owner_binding) if owner_binding and owner_binding.exists() else {}
if legacy is not None:
owned_elsewhere = bool(owner_identity) and owner_profile != context.profile and owner.get("sha256") == hashlib.sha256(legacy.read_bytes()).hexdigest()
if legacy is not None:
owned_elsewhere = owned_elsewhere and all(owner.get(field) == owner_identity.get(field) for field in IDENTITY_FIELDS)
if legacy is not None:
owned_elsewhere = owned_elsewhere and (context.root.parent / owner_profile / "stacks" / name / "terraform.tfstate").exists()
if not owned_elsewhere:
raise Refused(f"Legacy {name} state is preserved and is not safely assigned elsewhere. Review ./jeannie cluster-context migrate --stack {name}, then migrate --stack {name} --yes")
record = legacy_record(context, legacy)
owner = document(record) if record.exists() else {}
owner_profile = owner.get("profile", "")
owner_binding = context.root.parent / owner_profile / "identity.json" if re.fullmatch(r"[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}", owner_profile) else None
owner_identity = document(owner_binding) if owner_binding and owner_binding.exists() else {}
owned_elsewhere = bool(owner_identity) and owner_profile != context.profile and owner.get("sha256") == hashlib.sha256(legacy.read_bytes()).hexdigest()
owned_elsewhere = owned_elsewhere and all(owner.get(field) == owner_identity.get(field) for field in IDENTITY_FIELDS)
owned_elsewhere = owned_elsewhere and (context.root.parent / owner_profile / "stacks" / name / "terraform.tfstate").exists()
if not owned_elsewhere:
raise Refused(f"Legacy {name} state is preserved and is not safely assigned elsewhere. Review ./jeannie cluster-context migrate --stack {name}, then migrate --stack {name} --yes")
env = dict(os.environ, TF_DATA_DIR=str(context.root / ".terraform" / name), TF_WORKSPACE="default")
env["JEANNIE_PROFILE_TF_DATA"] = env["TF_DATA_DIR"]
env["TF_VAR_kubeconfig_path"] = context.kubeconfig
@ -463,13 +443,7 @@ def proxy_tofu(args):
if command == "init":
return 0
mutable = command in ("apply", "destroy", "import", "refresh", "force-unlock", "taint", "untaint") or command == "state" and len(args) > 1 and args[1] not in ("list", "show", "pull")
initial_k3s_bootstrap = (
name == "cluster"
and command == "apply"
and os.environ.get("TF_VAR_cluster_runtime") == "k3s"
and not context.binding.exists()
)
observed = context.check() if mutable and not initial_k3s_bootstrap else None
observed = context.check() if mutable else None
if command in ("apply", "destroy", "import", "refresh", "plan"):
expression = "jsonencode(var.kubeconfig_path)"
if name == "cluster":
@ -482,12 +456,9 @@ def proxy_tofu(args):
if kubeconfig["node"] != context.expected_node or any(kubeconfig[key] != context.expected_host for key in ("host", "address")):
raise Refused("Control-plane provisioner host/name/address does not match the selected profile")
kubeconfig = kubeconfig["kubeconfig"]
effective = Context(kubeconfig=kubeconfig)
# A first k3s control-plane apply creates the kubeconfig and
# identity; enrollment is intentionally a separate reviewed
# step after the API is available.
if not initial_k3s_bootstrap:
observed = effective.check()
effective = Context(kubeconfig=kubeconfig)
# Plans can evaluate declarative imports; validate those reads too.
observed = effective.check()
saved = [arg for arg in positionals(args[1:]) if (directory / arg).is_file()]
if command == "apply" and saved:
if len(saved) != 1: