From dea1bc7521693275ac0238d38ea8ed4b93b524ab Mon Sep 17 00:00:00 2001 From: "juvenal.diaz" Date: Thu, 1 Oct 2026 08:04:00 -0600 Subject: [PATCH] refactor: derive cluster settings from active profile --- homelab.yml | 22 +++++++++++++++++++ lib/jeannie/env.sh | 46 ++++++++++++++++++++++++++++++++------- lib/jeannie/pipeline.sh | 48 +++++++++++++++++++++++++++++++++-------- 3 files changed, 99 insertions(+), 17 deletions(-) diff --git a/homelab.yml b/homelab.yml index d7a8b3b..c236f4e 100644 --- a/homelab.yml +++ b/homelab.yml @@ -38,6 +38,28 @@ network: address_pool: 192.168.100.240-192.168.100.250 tailscale_cgnat_cidr: 100.64.0.0/10 +cluster: + active_profile: debian + profiles: + debian: + control_plane: + node_name: debian + lan_ip: 192.168.100.73 + user: jv + kubeconfig: /home/jv/.kube/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 + hosts: debian: role: control-plane diff --git a/lib/jeannie/env.sh b/lib/jeannie/env.sh index ad8f64e..133bb80 100644 --- a/lib/jeannie/env.sh +++ b/lib/jeannie/env.sh @@ -22,11 +22,11 @@ mapping = { "network.lan_cidr": "LAB_LAN_CIDR", "network.lan_ip_prefix": "LAB_LAN_IP_PREFIX", "network.metallb.traefik_ip": "LAB_TRAEFIK_LB_IP", + "cluster.active_profile": "LAB_CLUSTER_PROFILE", "hosts.debian.user": "LAB_DEBIAN_USER", "hosts.debian.lan_ip": "LAB_DEBIAN_LAN_IP", "hosts.debian.tailscale_ip": "LAB_DEBIAN_TAILSCALE_IP", "hosts.debian.docker_root": "LAB_DEBIAN_DOCKER_ROOT", - "hosts.debian.kubeconfig": "LAB_KUBECONFIG_PATH", "hosts.rpi4.user": "LAB_RPI_USER", "hosts.rpi4.lan_ip": "LAB_RPI_HOST", "hosts.rpi4.tailscale_ip": "LAB_RPI_TAILSCALE_IP", @@ -43,7 +43,6 @@ mapping = { "services.gitea.http_port": "LAB_GITEA_HTTP_PORT", "services.gitea.ssh_port": "LAB_GITEA_SSH_PORT", "services.gitea.root_url": "LAB_GITEA_ROOT_URL", - "services.gitea.ssh_remote": "LAB_GITOPS_REPO_URL", "services.heimdall.install_dir": "LAB_HEIMDALL_INSTALL_DIR", "services.heimdall.http_port": "LAB_HEIMDALL_HTTP_PORT", "services.heimdall.public_url": "LAB_HEIMDALL_PUBLIC_URL", @@ -55,7 +54,6 @@ mapping = { "services.dex.public_url": "LAB_DEX_PUBLIC_URL", "services.jellyfin.http_port": "LAB_JELLYFIN_HTTP_PORT", "services.jellyfin.public_url": "LAB_JELLYFIN_PUBLIC_URL", - "services.local_registry.endpoint": "LAB_REGISTRY_ENDPOINT", "services.ollama.bind_address": "LAB_OLLAMA_BIND_ADDRESS", "services.ollama.models_dir": "LAB_OLLAMA_MODELS_DIR", "services.ollama.igpu_enable": "LAB_OLLAMA_IGPU_ENABLE", @@ -125,6 +123,35 @@ for path, env_name in mapping.items(): if value: print(f": ${{{env_name}:={shlex.quote(value)}}}") +cluster_profile = values.get("cluster.active_profile") or "debian" +print(f": ${{LAB_CLUSTER_PROFILE:={shlex.quote(cluster_profile)}}}") +profile_prefix = f"cluster.profiles.{cluster_profile}" +profile_mapping = { + "control_plane.node_name": ("LAB_CLUSTER_CONTROL_PLANE_NODE_NAME", None), + "control_plane.lan_ip": ("LAB_CLUSTER_CONTROL_PLANE_LAN_IP", "hosts.debian.lan_ip"), + "control_plane.user": ("LAB_CLUSTER_CONTROL_PLANE_USER", "hosts.debian.user"), + "control_plane.kubeconfig": ("LAB_KUBECONFIG_PATH", "hosts.debian.kubeconfig"), + "control_plane.kubeconfig_owner": ("LAB_CLUSTER_KUBECONFIG_OWNER", None), + "registry.endpoint": ("LAB_REGISTRY_ENDPOINT", "services.local_registry.endpoint"), + "provisioning.host": ("LAB_CLUSTER_PROVISIONING_HOST", "hosts.debian.lan_ip"), + "provisioning.user": ("LAB_CLUSTER_PROVISIONING_USER", "hosts.debian.user"), + "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), +} +for relative_path, (env_name, fallback_path) in profile_mapping.items(): + value = values.get(f"{profile_prefix}.{relative_path}") + if not value and fallback_path: + value = values.get(fallback_path) + if not value and relative_path == "control_plane.node_name" and cluster_profile == "debian": + value = "debian" + if not value and relative_path == "platform.calico_operator_node_name": + value = values.get(f"{profile_prefix}.control_plane.node_name") + if not value and cluster_profile == "debian": + value = "debian" + if value: + print(f": ${{{env_name}:={shlex.quote(value)}}}") + debian_ip = values.get("hosts.debian.lan_ip") gitea_http = values.get("services.gitea.http_port") if debian_ip: @@ -166,16 +193,18 @@ export_if_unset() { export_homelab_inventory_tf_vars() { export_if_unset TF_VAR_kubeconfig_path "${LAB_KUBECONFIG_PATH:-}" - export_if_unset TF_VAR_control_plane_endpoint "${LAB_DEBIAN_LAN_IP:-}" + 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:-}}" + export_if_unset TF_VAR_kubeconfig_owner "${LAB_CLUSTER_KUBECONFIG_OWNER:-}" export_if_unset TF_VAR_registry_endpoint "${LAB_REGISTRY_ENDPOINT:-}" - export_if_unset TF_VAR_provisioning_host "${LAB_DEBIAN_LAN_IP:-}" - export_if_unset TF_VAR_provisioning_user "${LAB_DEBIAN_USER:-}" - export_if_unset TF_VAR_http_host "${LAB_DEBIAN_LAN_IP:-}" + export_if_unset TF_VAR_provisioning_host "${LAB_CLUSTER_PROVISIONING_HOST:-${LAB_DEBIAN_LAN_IP:-}}" + 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_PIMOX_HOST:-}" export_if_unset TF_VAR_pimox_user "${LAB_PIMOX_USER:-}" export_if_unset TF_VAR_pimox_worker_storage "${LAB_PIMOX_WORKER_STORAGE:-}" export_if_unset TF_VAR_pimox_template_bridge "${LAB_PIMOX_BRIDGE:-}" - export_if_unset TF_VAR_pimox_template_build_user "${LAB_DEBIAN_USER:-}" + export_if_unset TF_VAR_pimox_template_build_user "${LAB_CLUSTER_PROVISIONING_USER:-${LAB_DEBIAN_USER:-}}" export_if_unset TF_VAR_pimox_template_guest_ip_prefix "${LAB_LAN_IP_PREFIX:-}" export_if_unset TF_VAR_edge_host "${LAB_EDGE_HOST:-}" export_if_unset TF_VAR_edge_user "${LAB_EDGE_USER:-}" @@ -198,6 +227,7 @@ export_homelab_inventory_tf_vars() { export_if_unset TF_VAR_jellyfin_backend_host "${LAB_JELLYFIN_BACKEND_HOST:-${LAB_DEBIAN_TAILSCALE_IP:-}}" export_if_unset TF_VAR_jellyfin_backend_port "${LAB_JELLYFIN_HTTP_PORT:-}" export_if_unset TF_VAR_gitops_repo_url "${LAB_GITOPS_REPO_URL:-}" + export_if_unset TF_VAR_calico_operator_node_name "${LAB_CALICO_OPERATOR_NODE_NAME:-${LAB_CLUSTER_CONTROL_PLANE_NODE_NAME:-}}" export_if_unset TF_VAR_worker_tailscale_enabled "${LAB_PIMOX_WORKER_TAILSCALE_ENABLED:-}" export_if_unset TF_VAR_worker_tailscale_accept_routes "${LAB_PIMOX_WORKER_TAILSCALE_ACCEPT_ROUTES:-}" export_if_unset TF_VAR_worker_tailscale_pod_egress_snat "${LAB_PIMOX_WORKER_TAILSCALE_POD_EGRESS_SNAT:-}" diff --git a/lib/jeannie/pipeline.sh b/lib/jeannie/pipeline.sh index 2e071c3..b0ee339 100644 --- a/lib/jeannie/pipeline.sh +++ b/lib/jeannie/pipeline.sh @@ -23,11 +23,11 @@ mapping = { "network.lan_cidr": "LAB_LAN_CIDR", "network.lan_ip_prefix": "LAB_LAN_IP_PREFIX", "network.metallb.traefik_ip": "LAB_TRAEFIK_LB_IP", + "cluster.active_profile": "LAB_CLUSTER_PROFILE", "hosts.debian.user": "LAB_DEBIAN_USER", "hosts.debian.lan_ip": "LAB_DEBIAN_LAN_IP", "hosts.debian.tailscale_ip": "LAB_DEBIAN_TAILSCALE_IP", "hosts.debian.docker_root": "LAB_DEBIAN_DOCKER_ROOT", - "hosts.debian.kubeconfig": "LAB_KUBECONFIG_PATH", "hosts.rpi4.user": "LAB_RPI_USER", "hosts.rpi4.lan_ip": "LAB_RPI_HOST", "hosts.rpi4.tailscale_ip": "LAB_RPI_TAILSCALE_IP", @@ -44,7 +44,6 @@ mapping = { "services.gitea.http_port": "LAB_GITEA_HTTP_PORT", "services.gitea.ssh_port": "LAB_GITEA_SSH_PORT", "services.gitea.root_url": "LAB_GITEA_ROOT_URL", - "services.gitea.ssh_remote": "LAB_GITOPS_REPO_URL", "services.heimdall.install_dir": "LAB_HEIMDALL_INSTALL_DIR", "services.heimdall.http_port": "LAB_HEIMDALL_HTTP_PORT", "services.heimdall.public_url": "LAB_HEIMDALL_PUBLIC_URL", @@ -56,7 +55,6 @@ mapping = { "services.dex.public_url": "LAB_DEX_PUBLIC_URL", "services.jellyfin.http_port": "LAB_JELLYFIN_HTTP_PORT", "services.jellyfin.public_url": "LAB_JELLYFIN_PUBLIC_URL", - "services.local_registry.endpoint": "LAB_REGISTRY_ENDPOINT", "services.ollama.bind_address": "LAB_OLLAMA_BIND_ADDRESS", "services.ollama.models_dir": "LAB_OLLAMA_MODELS_DIR", "services.ollama.igpu_enable": "LAB_OLLAMA_IGPU_ENABLE", @@ -126,6 +124,35 @@ for path, env_name in mapping.items(): if value: print(f": ${{{env_name}:={shlex.quote(value)}}}") +cluster_profile = values.get("cluster.active_profile") or "debian" +print(f": ${{LAB_CLUSTER_PROFILE:={shlex.quote(cluster_profile)}}}") +profile_prefix = f"cluster.profiles.{cluster_profile}" +profile_mapping = { + "control_plane.node_name": ("LAB_CLUSTER_CONTROL_PLANE_NODE_NAME", None), + "control_plane.lan_ip": ("LAB_CLUSTER_CONTROL_PLANE_LAN_IP", "hosts.debian.lan_ip"), + "control_plane.user": ("LAB_CLUSTER_CONTROL_PLANE_USER", "hosts.debian.user"), + "control_plane.kubeconfig": ("LAB_KUBECONFIG_PATH", "hosts.debian.kubeconfig"), + "control_plane.kubeconfig_owner": ("LAB_CLUSTER_KUBECONFIG_OWNER", None), + "registry.endpoint": ("LAB_REGISTRY_ENDPOINT", "services.local_registry.endpoint"), + "provisioning.host": ("LAB_CLUSTER_PROVISIONING_HOST", "hosts.debian.lan_ip"), + "provisioning.user": ("LAB_CLUSTER_PROVISIONING_USER", "hosts.debian.user"), + "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), +} +for relative_path, (env_name, fallback_path) in profile_mapping.items(): + value = values.get(f"{profile_prefix}.{relative_path}") + if not value and fallback_path: + value = values.get(fallback_path) + if not value and relative_path == "control_plane.node_name" and cluster_profile == "debian": + value = "debian" + if not value and relative_path == "platform.calico_operator_node_name": + value = values.get(f"{profile_prefix}.control_plane.node_name") + if not value and cluster_profile == "debian": + value = "debian" + if value: + print(f": ${{{env_name}:={shlex.quote(value)}}}") + debian_ip = values.get("hosts.debian.lan_ip") gitea_http = values.get("services.gitea.http_port") if debian_ip: @@ -167,16 +194,18 @@ export_if_unset() { export_homelab_inventory_tf_vars() { export_if_unset TF_VAR_kubeconfig_path "${LAB_KUBECONFIG_PATH:-}" - export_if_unset TF_VAR_control_plane_endpoint "${LAB_DEBIAN_LAN_IP:-}" + 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:-}}" + export_if_unset TF_VAR_kubeconfig_owner "${LAB_CLUSTER_KUBECONFIG_OWNER:-}" export_if_unset TF_VAR_registry_endpoint "${LAB_REGISTRY_ENDPOINT:-}" - export_if_unset TF_VAR_provisioning_host "${LAB_DEBIAN_LAN_IP:-}" - export_if_unset TF_VAR_provisioning_user "${LAB_DEBIAN_USER:-}" - export_if_unset TF_VAR_http_host "${LAB_DEBIAN_LAN_IP:-}" + export_if_unset TF_VAR_provisioning_host "${LAB_CLUSTER_PROVISIONING_HOST:-${LAB_DEBIAN_LAN_IP:-}}" + 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_PIMOX_HOST:-}" export_if_unset TF_VAR_pimox_user "${LAB_PIMOX_USER:-}" export_if_unset TF_VAR_pimox_worker_storage "${LAB_PIMOX_WORKER_STORAGE:-}" export_if_unset TF_VAR_pimox_template_bridge "${LAB_PIMOX_BRIDGE:-}" - export_if_unset TF_VAR_pimox_template_build_user "${LAB_DEBIAN_USER:-}" + export_if_unset TF_VAR_pimox_template_build_user "${LAB_CLUSTER_PROVISIONING_USER:-${LAB_DEBIAN_USER:-}}" export_if_unset TF_VAR_pimox_template_guest_ip_prefix "${LAB_LAN_IP_PREFIX:-}" export_if_unset TF_VAR_edge_host "${LAB_EDGE_HOST:-}" export_if_unset TF_VAR_edge_user "${LAB_EDGE_USER:-}" @@ -199,6 +228,7 @@ export_homelab_inventory_tf_vars() { export_if_unset TF_VAR_jellyfin_backend_host "${LAB_JELLYFIN_BACKEND_HOST:-${LAB_DEBIAN_TAILSCALE_IP:-}}" export_if_unset TF_VAR_jellyfin_backend_port "${LAB_JELLYFIN_HTTP_PORT:-}" export_if_unset TF_VAR_gitops_repo_url "${LAB_GITOPS_REPO_URL:-}" + export_if_unset TF_VAR_calico_operator_node_name "${LAB_CALICO_OPERATOR_NODE_NAME:-${LAB_CLUSTER_CONTROL_PLANE_NODE_NAME:-}}" export_if_unset TF_VAR_worker_tailscale_enabled "${LAB_PIMOX_WORKER_TAILSCALE_ENABLED:-}" export_if_unset TF_VAR_worker_tailscale_accept_routes "${LAB_PIMOX_WORKER_TAILSCALE_ACCEPT_ROUTES:-}" export_if_unset TF_VAR_worker_tailscale_pod_egress_snat "${LAB_PIMOX_WORKER_TAILSCALE_POD_EGRESS_SNAT:-}" @@ -443,7 +473,7 @@ adopt_apps_existing_resources() { } ensure_homelab_node_labels() { - local control_plane_node="${LAB_CONTROL_PLANE_NODE_NAME:-debian}" + local control_plane_node="${LAB_CLUSTER_CONTROL_PLANE_NODE_NAME:-${LAB_CONTROL_PLANE_NODE_NAME:-debian}}" local raspberry_node="${LAB_RASPBERRY_NODE_NAME:-raspberry}" local prometheus_selector="homelab.dev/node-role=app,homelab.dev/storage=ssd" local node