feat: isolate platform component deployments

This commit is contained in:
juvenal.diaz 2026-10-20 21:53:49 -06:00
parent 3a3291c40e
commit e1b499f362
3 changed files with 114 additions and 6 deletions

View File

@ -0,0 +1,22 @@
# Platform components
The platform stack keeps one OpenTofu state file, but Jeannie exposes isolated
component applies. A component apply passes only that component's resource
addresses as `-target` arguments; OpenTofu includes required dependencies and
does not apply unrelated platform resources.
Run these on the Debian homelab host with the active cluster profile:
```bash
LAB_CLUSTER_PROFILE=pimox ./jeannie platform monitoring
LAB_CLUSTER_PROFILE=pimox ./jeannie platform logging
LAB_CLUSTER_PROFILE=pimox ./jeannie platform argocd
LAB_CLUSTER_PROFILE=pimox ./jeannie platform all
```
Available components are `calico`, `metrics`, `dns`, `metallb`, `ingress`,
`storage`, `argocd`, `security`, `logging`, `monitoring`, and `tools`.
Targeted applies skip the legacy existing-resource adoption pass, which avoids
touching unrelated platform state during a small change. Use `platform all`
for the full reconciliation and adoption path.

View File

@ -115,7 +115,8 @@ Observability And GitOps
dex-secret {ensure|file} Generate/check SOPS-encrypted Dex bootstrap secrets.
gitea-runner-secret {migrate|apply|file} Convert/apply the Gitea runner SOPS secret.
gitops-status Print focused Argo CD health and sync status.
platform Deploy platform stack only.
platform [all|calico|metrics|dns|metallb|ingress|storage|argocd|security|logging|monitoring|tools]
Deploy one platform component or the full platform stack.
edge Deploy/check the OCI edge stack only.
edge-cache-flush Clear Nginx, Varnish, and Squid edge caches.
promote {plan|validate|rollback APP} Run canary promotion gates and rollback plan.
@ -259,7 +260,7 @@ case "${1:-}" in
require_debian_server "platform"
jeannie_log_start "platform"
jeannie_step_plan 1
run_step "Platform OpenTofu apply" platform_apply
run_step "Platform OpenTofu apply" platform_apply "${2:-all}"
echo "Log: ${JEANNIE_LOG_FILE}"
;;
edge)

View File

@ -524,6 +524,14 @@ adopt_apps_existing_resources() {
"supply-chain-policy"
}
tofu_apply_has_targets() {
local arg
for arg in "$@"; do
[[ "${arg}" == -target=* ]] && return 0
done
return 1
}
ensure_homelab_node_labels() {
local control_plane_node="${LAB_CLUSTER_CONTROL_PLANE_NODE_NAME:-${LAB_CONTROL_PLANE_NODE_NAME:-debian}}"
local raspberry_node="${LAB_RASPBERRY_NODE_NAME:-raspberry}"
@ -636,7 +644,7 @@ tofu_apply_with_kubernetes_retry() {
while true; do
echo "OpenTofu ${stack} apply still hit Kubernetes API/OpenAPI read errors after ${attempt} attempt(s); trying guarded -refresh=false apply ${refresh_attempt}/${refresh_fallback_attempts}." >&2
ensure_kubernetes_api_ready_for_tofu_stack "${stack}"
if [[ "${stack}" == "bootstrap/platform" ]]; then
if [[ "${stack}" == "bootstrap/platform" ]] && ! tofu_apply_has_targets "$@"; then
adopt_platform_existing_resources
elif [[ "${stack}" == "bootstrap/apps" ]]; then
adopt_apps_existing_resources
@ -668,7 +676,7 @@ tofu_apply_with_kubernetes_retry() {
echo "OpenTofu ${stack} apply hit a transient Kubernetes API/OpenAPI error; waiting for API stability before retry ${attempt}/${max_attempts}..." >&2
rm -f "${output_file}"
ensure_kubernetes_api_ready_for_tofu_stack "${stack}"
if [[ "${stack}" == "bootstrap/platform" ]]; then
if [[ "${stack}" == "bootstrap/platform" ]] && ! tofu_apply_has_targets "$@"; then
adopt_platform_existing_resources
elif [[ "${stack}" == "bootstrap/apps" ]]; then
adopt_apps_existing_resources
@ -679,8 +687,18 @@ tofu_apply_with_kubernetes_retry() {
run_tofu_stack() {
local stack="$1"
shift
local auto_approve="${LAB_AUTO_APPROVE:-true}"
local -a apply_args=()
local target
# Component applies use OpenTofu targets. Dependencies are still included by
# OpenTofu, while unrelated platform resources remain untouched.
while (($#)); do
target="$1"
apply_args+=("-target=${target}")
shift
done
if [[ "${stack}" == "bootstrap/cluster" ]]; then
ensure_cluster_worker_var_file
@ -715,7 +733,7 @@ run_tofu_stack() {
tofu -chdir="${REPO_ROOT}/${stack}" init
ensure_kubernetes_api_ready_for_tofu_stack "${stack}"
if [[ "${stack}" == "bootstrap/platform" ]]; then
if [[ "${stack}" == "bootstrap/platform" ]] && ! tofu_apply_has_targets "${apply_args[@]}"; then
adopt_platform_existing_resources
fi
if [[ "${stack}" == "bootstrap/apps" ]]; then
@ -7618,7 +7636,74 @@ apps() {
platform_apply() {
require_debian_server "platform"
run_tofu_stack "bootstrap/platform"
local component="${1:-all}"
local -a targets=()
case "${component}" in
all)
;;
calico)
targets=(
helm_release.calico_crds
null_resource.calico_helm_recovery
helm_release.calico
null_resource.calico_ready
)
;;
metrics)
targets=(helm_release.metrics_server null_resource.metrics_server_ready)
;;
dns)
targets=(
kubernetes_manifest.nodelocal_dns_service_account
kubernetes_manifest.nodelocal_dns_upstream_service
kubernetes_manifest.nodelocal_dns_config_map
kubernetes_manifest.nodelocal_dns_daemonset
kubernetes_manifest.nodelocal_dns_metrics_service
)
;;
metallb)
targets=(helm_release.metallb null_resource.metallb_l2_config)
;;
ingress)
targets=(helm_release.traefik)
;;
storage)
targets=(helm_release.openebs kubernetes_storage_class_v1.openebs_hostpath_retain)
;;
argocd)
targets=(helm_release.argocd null_resource.argocd_ready null_resource.argocd_private_repo)
;;
security)
targets=(
null_resource.kyverno_helm_recovery
helm_release.kyverno
helm_release.kyverno_policies
)
;;
logging)
targets=(helm_release.loki helm_release.promtail)
;;
monitoring)
targets=(
kubernetes_namespace_v1.monitoring
helm_release.mimir
null_resource.prometheus_stack_helm_recovery
helm_release.prometheus_stack
null_resource.prometheus_stack_readiness
kubernetes_config_map.grafana_dashboards
)
;;
tools)
targets=(helm_release.extra_tools)
;;
*)
echo "Unknown platform component '${component}'. Use all, calico, metrics, dns, metallb, ingress, storage, argocd, security, logging, monitoring, or tools." >&2
return 2
;;
esac
run_tofu_stack "bootstrap/platform" "${targets[@]}"
}
edge_apply() {