feat: add --inject-label flag to apply, diff, show and export - #2095
Open
colega wants to merge 1 commit into
Open
feat: add --inject-label flag to apply, diff, show and export#2095colega wants to merge 1 commit into
colega wants to merge 1 commit into
Conversation
Adds a repeatable --inject-label key=value flag that sets a label on every rendered resource, overriding any pre-existing value. Useful for ad-hoc identification of the resources a given run touched, without editing the Environment's spec.json. Distinct from spec.injectLabels, which only toggles the tanka.dev/environment label used by garbage collection.
|
|
colega
marked this pull request as ready for review
June 26, 2026 09:37
NickAnge
reviewed
Jun 30, 2026
| return func() map[string]string { | ||
| m := make(map[string]string) | ||
| for _, s := range *injectLabels { | ||
| split := strings.SplitN(s, "=", 2) |
Contributor
There was a problem hiding this comment.
If we have --inject-label =value, i think it will pass through the format check — SplitN produces ["", "value"] which has length 2. Do we wanna allow it ? I assume the rendering will fail
dblinkhorn
reviewed
Jun 30, 2026
| for _, s := range *injectLabels { | ||
| split := strings.SplitN(s, "=", 2) | ||
| if len(split) != 2 { | ||
| log.Fatal().Msgf("--inject-label argument has wrong format: `%s`. Expected `key=value`", s) |
Contributor
There was a problem hiding this comment.
What do you think of adding some additional validation here so that invalid k8s labels don't sneak through?
https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set
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 a repeatable
--inject-label key=valueflag totk apply,diff,showandexport.The flag sets the given label on every rendered resource, overriding any pre-existing value. This makes it easy to identify, in a cluster, which resources a given run touched (e.g.
--inject-label created-by=alice) without having to edit the Environment'sspec.json.It is intentionally distinct from
spec.injectLabels(the boolean toggling thetanka.dev/environmentlabel) and fromspec.resourceDefaults.labels(which only fills in missing keys). Labels are injected at the singleLoadManifestschokepoint, so all four commands behave consistently.