Skip to content

feat(k8s): argo cd keeps the homelab cluster at the current release branch, with automated sync, prune and self-heal that never delete data #755

Closed

Description

@dan-petty

Problem

The owner decided on 2026-10-03 that:

  • everything in the homelab cluster is in code and git;
  • Argo CD reconciles it with automated sync, prune and self-heal;
  • it tracks the current release branch, and devops release prepare moves the revision at each cut.

Today nothing reconciles the cluster, and nothing removes what git no longer has.

Evidence of 2026-10-03, at 321ecda (live reads on homelab-k3s; Secrets by name only):

Argo CD has no Applications, and the ones in git cannot sync.

  • Argo CD v3.5.3 (chart argo-cd 10.9.6) runs with zero Applications.

  • The app-of-apps points at paths that do not exist:

    • k8s/argocd/apps/root-app.yaml:14 (argocd/apps);
    • infra-apps.yaml:14 and :38 (monitoring, otel);
    • llm-apps.yaml:14 (llm).

    All use targetRevision: HEAD.

  • All three files carry resources-finalizer.argocd.argoproj.io, so deleting one would delete everything it synced.

  • kubectl kustomize k8s/llm fails on ca-configmap.yaml (k8s/llm/kustomization.yaml:7), which feat(k8s): modernize monitoring stack, llm profiles, traefik routing, and remove squid proxy #734 deleted.

The cluster is built by hand-run commands.

  • deploy-stack runs helm upgrade --install for each release in _HELM_RELEASES_BY_STACK (src/devops_cli/commands/k8s/stack_lifecycle.py:63) with no --version (_build_helm_upgrade_cmd, :514). It then applies _MANIFESTS_BY_STACK (:148) and runs kubectl apply -k k8s/ (:772).

  • helm list -A shows argocd at revision 107, open-webui at 115, otel-collector at 112 and qdrant at 110.

  • Live chart versions:

    That is 13 releases: 12 in _HELM_RELEASES_BY_STACK, plus traefik.

  • The k8s-monitoring chart's alloy-operator installs its own releases (k8s-monitoring-alloy-logs, -metrics, -singleton).

  • Other hand steps:

Leftovers are removed by hand.

Data.

  • All 7 PVs are local-path with reclaim Delete.
  • Chart PVCs (grafana, prometheus-server, open-webui) and registry-data (k8s/registry/pvc.yaml) would be tracked.
  • StatefulSet claims are created by their controllers. qdrant-storage-qdrant-0 and data-pyroscope-0 have no owner.
  • storage-loki-0 is owned by its StatefulSet: the loki StatefulSet has persistentVolumeClaimRetentionPolicy.whenDeleted: Delete (chart value singleBinary.persistence.enableStatefulSetAutoDeletePVC: true). Deleting or recreating it would delete the claim, and the logs with it.
  • Argo CD's Delete=false covers only Application deletion. A manifest removed from git is pruned unless it carries Prune=false. Several options share one argocd.argoproj.io/sync-options annotation, comma-separated.
  • Pruning a Namespace deletes its PVCs and Secrets.

Objects Argo CD would list as orphans.

  • In the namespaces it will manage, these have no owner and will never be in git:
    • the PVCs above;
    • Secrets llm/llm-gateway-secrets, llm/qdrant-api-key, cloudflared/cloudflared-token, argocd/argocd-initial-admin-secret and argocd/argocd-redis;
    • Helm records sh.helm.release.v1.*.
  • k8s/ingress/ingress-routes.yaml puts an IngressRoute (:509-520) and an Ingress (:512) in kube-system.
  • k8s/gpu-feature-discovery/daemonset.yaml:5 deploys into default.

Duplicates.

  • Namespaces argocd, llm, monitoring and otel are declared in k8s/namespaces.yaml and again in per-directory namespace.yaml files. The root file's labels are a superset of the per-directory ones and match the live namespaces.
  • monitoring/service-aliases.yaml and monitoring/dashboards sit in both the root and the monitoring kustomizations (this issue's comment of 2026-10-01).
  • k8s/overlays/templated/kustomization.yaml lists ../../cloudflared, which the root kustomization also lists (k8s/kustomization.yaml:6).
  • k8s/llm/kustomization.yaml lists portkey (:15-18) and valkey-runs (:9). Neither runs, and valkey-runs-auth does not exist.

Policies, live against git (kubectl diff):

The domain.

  • 23 Ingress hosts and one IngressRoute match (Host(`traefik.example.com`), ingress-routes.yaml:520) use the placeholder example.com. It is substituted at apply time (src/devops_cli/k8s/template.py:66-70).
  • Argo CD renders git as it is.

Generated values.

  • k8s/monitoring/grafana-values.yaml:27 sets adminPassword: "", so helm template generates a new password on every render.
  • argocd-secret is rendered by the chart.

Health. All 19 Ingresses have an empty status.loadBalancer, and the traefik Service is ClusterIP. Argo CD reports such Ingresses as Progressing.

Secrets out of band: cloudflared/cloudflared-token, llm/llm-gateway-secrets (master-key) and llm/qdrant-api-key, plus the Argo CD-generated argocd-initial-admin-secret and argocd-redis. #741's devops k8s push-secrets writes the first three from the keyring, and deploy-stack runs it before applying anything that reads them.

Release.

Drift. devops argo gitops drift (src/devops_cli/commands/argo.py:924) reports only local working-tree changes. devops argo cd apps list (:186) shows Sync and Health.

Proposed solution

Applications

  • k8s/argocd/bootstrap/bootstrap.yaml: Application bootstrap, on main, path k8s/argocd/bootstrap, which holds only cluster.yaml.
  • cluster.yaml: Application cluster, on release/vX.Y.Z (the current release), path k8s/argocd/apps.
  • Both use project default and carry no resources finalizer.
  • k8s/argocd/apps/projects.yaml defines two AppProjects. Both have clusterResourceWhitelist: [{group: '*', kind: '*'}] and sourceRepos = this repo, the Helm repos of _HELM_REPOS (stack_lifecycle.py:38-60) and traefik's.
  • One Application per directory:
    • in homelab: base (the root kustomization), monitoring, llm, otel, logging and devops (k8s/overlays/homelab/devops);
    • in homelab-system: ingress (k8s/overlays/homelab/ingress) and gpu-feature-discovery.
  • One multi-source Application per release in _HELM_RELEASES_BY_STACK, plus traefik in homelab-system. Each pins its chart (targetRevision: <x.y.z>) and reads $values/k8s/... from this repo at the current release branch.
  • Every Application: syncPolicy.automated: {prune: true, selfHeal: true}, with a retry and backoff.
    • Leaf Applications carry resources-finalizer.argocd.argoproj.io. bootstrap, cluster and argocd carry none.
    • prometheus-operator-crds uses ServerSideApply=true.
    • Applications that render custom resources whose CRDs another Application installs use SkipDryRunOnMissingResource=true: k8s-monitoring, dcgm-exporter, and ingress (for the IngressRoute).

Release tracking

Data safety

  • Every Namespace and PVC rendered from the repo carries Prune=false,Delete=false.
  • loki sets singleBinary.persistence.enableStatefulSetAutoDeletePVC: false.
  • The argo-cd chart sets crds.annotations argocd.argoproj.io/sync-options: ServerSideApply=true,Prune=false,Delete=false. crds.keep stays true.
  • Before the merge, a person sets every bound PV to Retain.

Ownership. Every object belongs to exactly one Application.

Secrets. devops k8s push-secrets (#741) writes every out-of-band Secret from the keyring. This item adds the monitoring/grafana-admin row.

deploy-stack. Every release gains its pinned version. Where Application cluster exists in argocd, deploy-stack still pushes the same Secrets it pushes without Argo CD (#741), then applies nothing else and says that Argo CD manages the rest; teardown-stack refuses.

Drift is reported by Argo CD (see the key questions).

Scope

Argo CD files

  • Delete k8s/argocd/apps/root-app.yaml, infra-apps.yaml and llm-apps.yaml.
  • Add k8s/argocd/bootstrap/bootstrap.yaml, k8s/argocd/bootstrap/cluster.yaml, k8s/argocd/apps/projects.yaml and one file per Application.
  • In argo.py, --root-app defaults to k8s/argocd/bootstrap/bootstrap.yaml (:336) and --app-name to cluster (:864, :977). docs/commands/argo.md is regenerated.

Ownership clean-up

Domain

  • k8s/overlays/homelab/ingress/ (resources: ../../../ingress only) and k8s/overlays/homelab/devops/ (resources: ../../../devops) replace k8s/overlays/templated/, which nothing references.
  • Each patches every Ingress host and the IngressRoute match from example.com to the homelab domain.
  • k8s/coredns/ stays outside Argo CD, and the README names it.

Values

  • grafana: admin.existingSecret: grafana-admin.
  • The PVC annotation keys of grafana (persistence.annotations), prometheus (server.persistentVolume.annotations) and open-webui (persistence annotations) are set to Prune=false,Delete=false.
  • loki: singleBinary.persistence.enableStatefulSetAutoDeletePVC: false.
  • argo-cd: crds.annotations as above.
  • traefik: providers.kubernetesIngress.publishedService.enabled: true. If a ClusterIP Service leaves the Ingress status empty, add an Ingress health customization in k8s/argocd/values.yaml.
  • k8s/registry/pvc.yaml gets the sync-options annotation.

push-secrets row (#741's table): monitoring/grafana-admin, stack infra.

deploy-stack

Release

Docs

  • A k8s/README.md "GitOps" section covering:
    • bootstrap and adoption;
    • recovery: helm upgrade --install argocd argo/argo-cd --version 10.9.6 -n argocd -f k8s/argocd/values.yaml, then devops argo cd apps bootstrap-gitops;
    • the drift commands;
    • the table of replaced hand steps.
  • changelog.d/755.md; task file docs/agent/tasks/task-755-argocd-reconciles-cluster.md.

Acceptance criteria

In the gate (pure Python file reads, a stub store and a patched runner; under 1 s: uv run pytest tests/test_k8s_argocd_apps.py tests/test_release.py tests/test_k8s_stack_lifecycle.py --durations=0):

  • Applications (tests/test_k8s_argocd_apps.py):
    • Every Application's project is homelab or homelab-system, except bootstrap and cluster, which use default.
    • No homelab Application targets kube-system or default.
    • Each has automated.prune and automated.selfHeal true.
    • Git sources name this repo, and their targetRevisions are equal and match release/v\d+\.\d+\.\d+, except bootstrap, which uses main.
    • Helm sources pin exact versions.
    • Every path exists, and every resource each synced kustomization lists exists, including a kustomization.yaml in each listed directory.
    • The Helm Applications match _HELM_RELEASES_BY_STACK plus traefik by name, chart, namespace, values file and version.
    • bootstrap, cluster and argocd carry no resources-finalizer.argocd.argoproj.io.
    • Both projects whitelist cluster-scoped kinds.
    • homelab has orphanedResources.warn: true, with ignore entries for each push-table Secret name, sh.helm.release.v1.*, PersistentVolumeClaim and Job devops-cli-*.
  • Ownership. Each rendered raw object (group, kind, namespace, name) appears in exactly one Application's synced paths. Each Namespace is declared once.
  • Data safety.
    • Every Namespace and PVC in a synced raw manifest has sync-options containing Prune=false and Delete=false.
    • The grafana, prometheus and open-webui values set that annotation at the chart's PVC annotation key.
    • loki's enableStatefulSetAutoDeletePVC is false.
    • argo-cd's crds.annotations sync-options contain ServerSideApply=true, Prune=false and Delete=false.
  • Perimeters.
    • No Application syncs a kustomization that lists k8s/argocd/networkpolicy.yaml.
    • The otel Application's kustomization lists networkpolicy.yaml.
    • tests/test_k8s_network_policies.py passes unchanged.
  • Domain.
    • No synced raw manifest, after the overlay patches, contains example.com.
    • Every Ingress host and the IngressRoute match equal the template render (template.py:66-70) for the overlay's domain.
  • Release.
    • With a store whose open releases are v0.2.27 and v0.2.28, release prepare 0.2.27 on a tmp_path tree sets every git-source targetRevision to release/v0.2.28 and leaves chart versions alone.
    • With no open release above the one being prepared, it exits 1 and changes nothing.
    • _release_paths(root) contains k8s/argocd/.
    • Mismatched targetRevisions make release check exit 1.
  • deploy-stack.
  • push-secrets.
  • Docs regenerate, changelog.d/755.md exists, CHANGELOG.md and docs/ROADMAP.md are untouched, and uv run devops ci passes within budget.

Pending a person (homelab-k3s). Merges into the current release branch deploy.

  • Before merge, data:
    • Record kubectl --context homelab-k3s get pvc -A -o custom-columns=NS:.metadata.namespace,NAME:.metadata.name,UID:.metadata.uid in the PR.
    • Set each bound PV to Retain: first kubectl --context homelab-k3s patch pv <name> -p '{"spec":{"persistentVolumeReclaimPolicy":"Retain"}}' --dry-run=server, then the same without --dry-run.
  • Before merge, diff:
    • kubectl --context homelab-k3s diff -k for k8s, monitoring, llm, otel, logging, gpu-feature-discovery, k8s/overlays/homelab/ingress and k8s/overlays/homelab/devops.
    • helm template <release> <repo>/<chart> --version <v> -n <ns> -f k8s/<values> | kubectl --context homelab-k3s diff -n <ns> -f - for each chart.
    • Every difference is settled in the PR. Expected: the monitoring perimeter drops the 0.0.0.0/0 peer and adds 4040; otel adds 4040.
    • Record count by (job) (up == 1) from Prometheus.
  • Secrets: uv run devops k8s push-secrets --stack infra --context homelab-k3s --dry-run shows monitoring/grafana-admin admin-password as would adopt or unchanged, never differs. The same without --dry-run exits 0, and the Grafana admin login still works.
  • After merge:
    1. uv run devops argo cd apps bootstrap-gitops -f k8s/argocd/bootstrap/cluster.yaml --context homelab-k3s.
    2. Within 15 minutes, kubectl --context homelab-k3s -n argocd get applications -o custom-columns=NAME:.metadata.name,SYNC:.status.sync.status,HEALTH:.status.health.status,CONDITIONS:.status.conditions[*].type shows every Application Synced and Healthy, with only OrphanedResourceWarning conditions.
    3. The PVC UIDs equal the recorded ones. Every tracked PVC shows Prune=false,Delete=false (jsonpath on .metadata.annotations.argocd\.argoproj\.io/sync-options).
    4. Monitoring under its first synced perimeter: count by (job) (up == 1) equals the recorded value, and Grafana's Prometheus, Loki, Jaeger and Pyroscope datasources pass "Save & test" (fix(k8s): deploy-stack applies the monitoring namespace perimeter #913's checks).
  • Leftovers:
    • Delete only cloudflared/cloudflared-tunnel-token and monitoring/kube-prometheus-kube-prome-admission, each first with --dry-run=server.
    • Record in the PR any other resource an OrphanedResourceWarning names, and leave it alone. Never delete on that warning alone a PVC, a Secret, a NetworkPolicy, or anything in kube-system, default or local-path-storage.
    • kubectl --context homelab-k3s get ns -o go-template='{{range .items}}{{if not (index .metadata.annotations "argocd.argoproj.io/tracking-id")}}{{.metadata.name}}{{"\n"}}{{end}}{{end}}' prints only default, kube-node-lease, kube-public, kube-system and local-path-storage.
  • Helm records:
    • For each release an Application adopted (not the alloy-operator's k8s-monitoring-alloy-* releases), run kubectl --context homelab-k3s -n <ns> delete secret -l owner=helm,name=<release> --dry-run=server, then the same without --dry-run.
    • Afterwards helm --kube-context homelab-k3s list -A lists only the alloy-operator's releases.
  • Self-heal: kubectl --context homelab-k3s -n otel scale deploy jaeger --replicas=2. Within 5 minutes, kubectl --context homelab-k3s -n otel get deploy jaeger -o jsonpath='{.spec.replicas}' prints 1 (k8s/otel/jaeger.yaml:10).
  • At this release's ship:
    1. uv run devops argo cd apps bootstrap-gitops --context homelab-k3s (the new default, bootstrap.yaml).
    2. After feat(github): current release admission, cap, descoping and stall rules (devops roadmap reprioritize) #740 creates the next branch, kubectl -n argocd get application cluster -o jsonpath='{.spec.source.targetRevision}' prints it.

Key questions

Out of scope

Strategic alignment

Readiness check (2026-10-04)

Checked at b61e5a0 (release/v0.2.26).

Dependencies.

Since #548. fluent-bit has left _HELM_RELEASES_BY_STACK (stack_lifecycle.py:65), which now holds 11 releases.

Since #741.

  • The push table is CLUSTER_SECRETS (src/devops_cli/k8s/cluster_secrets.py:161), and the reference guard is tests/test_k8s_push_secrets.py:226.
  • devops is a detached stack (DETACHED_STACKS, cluster_secrets.py:25). Its k8s/devops/namespace.yaml stays the one devops declaration and also gets the annotation.
  • deploy-stack has --push-secrets/--no-push-secrets (stack_lifecycle.py:688-690). Under Argo CD it pushes only when that flag is on.

Since #982.

  • The bump block is _apply_cut_modifications (release.py:1034-1049). The targetRevision step goes after _update_service_image_tag (:1040).
  • cut_release (:1328) calls it, and serves release prepare (:893), release pr (:1457) and the automatic cut in devops roadmap close (commands/roadmap.py:461). So every cut moves the revision.
  • release.py:747-757 now refers to this block, _release_paths is at :656-676, and release check is at :1568.

Moved citations.

  • In stack_lifecycle.py:
    • _HELM_REPOS :38-60 → :58, with _HELM_REPOS_BY_STACK at :41;
    • _MANIFESTS_BY_STACK :148 → :144;
    • _build_helm_upgrade_cmd :514 → :461;
    • kubectl apply -k :772 → :749.
  • k8s/README.md:267, :275 and :69 → :417, :425 and :70.
  • ingress-routes.yaml: the only object in kube-system is the IngressRoute traefik-dashboard (:484-495, match at :495). There is no Ingress there.
  • _sync_grafana_credentials → credentials.py:512.
  • tests/test_k8s_stack_lifecycle.py does not exist yet. Like tests/test_k8s_argocd_apps.py, it is a new file; today's deploy-stack tests are in tests/test_k8s.py.
  • Alerts fire into nothing: no Alertmanager, and k3s false positives #549 is delivered.

Rule alignment: dry run (#412). A dry run makes no request, reads included.

Amended criteria:

  • Under --dry-run, deploy-stack and teardown-stack exit 0 and record no kubectl or helm call on the patched runner, the Argo CD probe included. release prepare 0.2.27 --dry-run makes no call on the stub store and changes no file.
  • (replaces the Secrets person step) uv run devops k8s push-secrets --stack infra --context homelab-k3s --plan shows monitoring/grafana-admin admin-password as would adopt or unchanged, never differs. The same command without --plan exits 0, and the Grafana admin login still works.

Activity

  1. added
    type/bug
    scope/k8s
    priority/p2-medium
    on Sep 30, 2026
  2. dan-petty commented on Oct 1, 2026

    @dan-petty
    OwnerAuthor

    When this lands, watch for one thing. #692 makes the root kustomization apply k8s/monitoring/dashboards, and k8s/monitoring/kustomization.yaml lists dashboards too. Once the monitoring-stack ArgoCD app points at k8s/monitoring (prune and self-heal on), ArgoCD and devops k8s deploy-stack will both apply the dashboard ConfigMaps. Either leave dashboards out of the ArgoCD app, or have deploy-stack stop applying it, so the ConfigMaps have one owner and teardown-stack --stack all doesn't fight self-heal.

  3. added a commit that references this issue on Oct 1, 2026
  4. added this to the v0.2.27 milestone on Oct 3, 2026
  5. changed the title [-]fix(k8s): argocd applications point at repo paths that don't exist[/-] [+]feat(k8s): argo cd keeps the homelab cluster at the current release branch, with automated sync, prune and self-heal that never delete data[/+] on Oct 3, 2026
  6. added
    type/feature
    priority/p1-high
    scope/release
    and removed
    type/bug
    priority/p2-medium
    on Oct 3, 2026
  7. 3 remaining items

  8. added this to the v0.2.28 milestone on Oct 6, 2026
  9. dan-petty-bot commented on Oct 6, 2026

    @dan-petty-bot
    Collaborator

    Moved to v0.2.28: every other item in v0.2.27 is done, and it had not started. (devops roadmap reprioritize)

  10. modified the milestones: v0.2.28, v0.2.27 on Oct 6, 2026
  11. removed this from the v0.2.27 milestone on Oct 6, 2026
  12. dan-petty-bot commented on Oct 6, 2026

    @dan-petty-bot
    Collaborator

    Moved to the backlog: after v0.2.27 started, only a critical fix can join it. A person can place it in a planned release, and that placement stands. (devops roadmap reprioritize)

  13. added this to the v0.2.27 milestone on Oct 6, 2026
  14. removed this from the v0.2.27 milestone on Oct 6, 2026
  15. dan-petty-bot commented on Oct 6, 2026

    @dan-petty-bot
    Collaborator

    Moved to the backlog: after v0.2.27 started, only a critical fix can join it. A person can place it in a planned release, and that placement stands. (devops roadmap reprioritize)

  16. dan-petty-bot commented on Oct 6, 2026

    @dan-petty-bot
    Collaborator

    What changed

    #1256, merged into release/v0.2.27 as 5f37f2f.

    Summary

    Closes #755

    This PR introduces declared GitOps cluster state reconciliation via Argo CD, enhances devops ai rag index progress tracking and responsiveness across all ingestion stages, and aligns release orchestration to use canonical release/vX.Y.Z branches.

    90 file(s) changed.

    How it was verified

    Check runs at 3ad85cb:

    • Prune PR DevContainer Images: pass
    • CodeQL: pass
    • Service Image: skipping
    • Analyze (actions): pass
    • Analyze (python): pass
    • Static Analysis: pass
    • Tests & Coverage: pass
    • DevContainer Image: skipping
    • Dependency Freshness: skipping

    Acceptance Criteria of docs/agent/tasks/task-755-argocd-reconciles-cluster.md:

    No Acceptance Criteria section.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p1-highscope/k8sscope/releasetype/feature

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions