feat(prune): add --target flag support to tk prune#2032
Open
zalegrala wants to merge 2 commits into
Open
Conversation
tk prune now accepts the same --target / -t flag as tk apply, tk delete, and tk show. This lets operators restrict pruning to a subset of resource kinds and names using the standard kind/name RE2 regex syntax, e.g.: tk prune -t 'statefulset/.*' . tk prune -t 'statefulset/live-store.*' . tk prune -t '!deployment/.*' . When a literal kind name is given in the filter (no regex metacharacters in the kind position), Orphaned() restricts the Kubernetes API query to only that resource type. This avoids listing every resource kind in large environments and makes targeted prune operations significantly cheaper. Changes: - process: add Matchers.KindsFor() + kindFromFilterPattern() to extract literal kind names from compiled filter expressions - kubernetes: add OrphanedOpts, thread Filters through Orphaned() for both kind-level pre-filtering of API queries and post-filtering of results - tanka: pass opts.Filters into Orphaned() via OrphanedOpts - cmd/tk: wire workflowFlags (--target, --name, --jsonnet-implementation) into pruneCmd, matching the pattern used by applyCmd and deleteCmd - docs: document --target usage on tk prune in garbage-collection.md
|
|
1 similar comment
|
|
- gofmt: reformat apply_test.go and filter_test.go - staticcheck QF1012: replace WriteString(fmt.Sprintf(...)) with fmt.Fprintf in find_importers.go and pkg/kubernetes/util/diff.go
zalegrala
commented
May 13, 2026
|
|
||
| var sb strings.Builder | ||
| for _, importer := range importersList { | ||
| sb.WriteString(fmt.Sprintf("%s: %d\n", importer.File, importer.Count)) |
Author
There was a problem hiding this comment.
These changes showed up in the lint when running locally.
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.
Adds
--target/-ttotk prune, bringing it in line withtk apply,tk delete, andtk show. See the updateddocs/garbage-collection.mdfor usage and examples.Efficiency note
Without
--target,tk prunelists every resource type that supports LIST before reconciling UIDs — expensive in environments with many CRDs. When the filter specifies a literal kind name (no regex metacharacters in the kind position),Orphaned()restricts the cluster query to only that resource type, avoiding the cost of listing everything else.