Repository navigation
fix: dry-run k8s manifests before approval instead of applying them (#102) - #106
Merged
Merged
Conversation
With AUTO_APPLY=false and dry_run=false, apply_manifest ran the live `kubectl apply` first and only then returned requires_approval (#102). The approval it sent was also unusable: it pointed at the temp manifest file, which was deleted before anyone could approve it. Now, without AUTO_APPLY, only `kubectl apply --dry-run=client` runs. If validation fails, no approval is requested. Otherwise the live command carries the manifest as base64 piped into `kubectl apply -f -` and is retained as a single-use approval reference (CommandApprovalStore, from #103), so it fits in a Slack button and can be executed once approved. Namespace and paths are shell-quoted. Fixes #102 Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Description
Fixes #102.
With
AUTO_APPLY=falseanddry_run=false,K8sTools.apply_manifestran the livekubectl applyand only afterwards returnedrequires_approvalwith "Manifest validated (dry-run OK)". The cluster was changed before anyone approved anything, and no dry run had actually happened.There was a second bug on the same path: the approval request contained
kubectl apply -f /tmp/xxx.yaml, but that temp file was deleted infinallybefore the method returned. Even after a human approved, the command would have failed with "file not found".Now, when approval is needed:
kubectl apply -f <tmp> -n <ns> --dry-run=clientruns.printf %s <base64> | base64 --decode | kubectl apply -f - -n <ns>. It is stored withCommandApprovalStore.retain(from fix: require approval for host-mutating tools when AUTO_APPLY is disabled (#89, #70) #103), so Slack gets a short single-use reference instead of a manifest-sized button value. Approving it runs the apply exactly once.shlex.quoted.dry_run=trueandAUTO_APPLY=truebehave as before.Type of Change
Platform/Component
Testing
tests/test_k8s_apply_approval.py(7 tests). Against the oldk8s_tools.py, 4 of them fail: live apply before approval, unusable approval, approval sent after failed validation, and manifest round-trip.--dry-runand without the temp-file path; a replay is blockedshwithkubectlswapped forcat, reproduces a manifest containing$( ), backticks, quotes and| & >byte-for-bytedry_run=trueonly validates;AUTO_APPLY=trueapplies directly; a disallowed namespace runs nothingflake8 --select=E9,F63,F7,F82: 0;bandit -llon tracked files: no issuesBreaking Changes
None. The approval message changes from "Manifest validated (dry-run OK)…" to "Manifest passed kubectl --dry-run=client. Approval request sent to Slack; nothing was applied."
Thanks to @Nitjsefnie for finding and reporting this while working on #103.
🤖 Generated with Claude Code