feat(controller): guarded repo-wide prune for git-as-source (homelab B2)#135
Merged
Conversation
Makes the repo the desired SET, not just an additive source: after a pull, resources whose manifest file was removed from the repo are deleted. Opt-in via manifests.gitops.pull.prune (default OFF — this deletes real infrastructure). manifests.Pruner is deliberately conservative; every path errs toward NOT deleting: - A resource whose file is still on disk is desired → never a candidate. - Composite children are skipped (owner labels AND the operative k3s `k3s.openctl.io/cluster` label — the live Cluster.Apply path uses the latter, not owner labels, so checking only one would orphan-delete a cluster's VMs). Deleting the parent composite cascades to its children. - Resources whose latest successful apply was cli/ui-sourced are protected (provenance read from the operations table, since applied_manifests has no source column). Unknown provenance (GC'd ops) is treated as prunable, not protected-forever, so the feature keeps working after op GC — but the child guard still applies. Wired after Watcher.Sync in the pull loop; deletes go through the same gitops-sourced Delete-op path as deleteOnRemove. Unit tests cover every guard branch (file-present keep, gitops/unknown prune, cli-source skip, both child label schemes skip, nil-source-lookup still guards children). Target B2 of Homelab-completion. Next: B3 (GitHub/PR flow).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Roadmap target B2. Makes the repo the desired SET, not just an additive source: after a pull, resources whose manifest file was removed from the repo are deleted. Opt-in via
manifests.gitops.pull.prune(default OFF — this deletes real infrastructure).Safety-first design
manifests.Pruneris deliberately conservative — every path errs toward NOT deleting:openctl.io/owner-kind/name) and the operativek3s.openctl.io/clusterlabel. The liveCluster.Applypath tags a cluster's VMs with the latter, not owner labels — checking only one scheme would orphan-delete a running cluster's VMs. Deleting the parent composite cascades to its children instead.cli/ui-sourced is skipped. Provenance comes from the operations table (there's nosourcecolumn onapplied_manifests). Unknown provenance (GC'd ops) is treated as prunable — so the feature keeps working after op GC — but the child guard still applies.Wired after
Watcher.Syncin the pull loop; deletes go through the same gitops-sourced Delete-op path asdeleteOnRemove.Why these guards matter (from a safety audit)
applied_manifestshas no source column → provenance must come from the ops table, and may be GC'd.Reconcilere-materializes missing files — but prune runs in the pull loop and deletes the store row, so a re-materialize can't revive a pruned resource.Tests
Every guard branch: file-present keep, gitops/unknown-provenance prune, cli-source skip, both child-label schemes skip, and nil-source-lookup still guards children.
Next: B3 (GitHub/PR flow).