Skip to content

feat: add --inject-label flag to apply, diff, show and export - #2095

Open
colega wants to merge 1 commit into
grafana:mainfrom
colega:colega/inject-label-flag
Open

feat: add --inject-label flag to apply, diff, show and export#2095
colega wants to merge 1 commit into
grafana:mainfrom
colega:colega/inject-label-flag

Conversation

@colega

@colega colega commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Adds a repeatable --inject-label key=value flag to tk apply, diff, show and export.

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's spec.json.

It is intentionally distinct from spec.injectLabels (the boolean toggling the tanka.dev/environment label) and from spec.resourceDefaults.labels (which only fills in missing keys). Labels are injected at the single LoadManifests chokepoint, so all four commands behave consistently.

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.
@cla-assistant

cla-assistant Bot commented Jun 26, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@cla-assistant

cla-assistant Bot commented Jun 26, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@colega
colega marked this pull request as ready for review June 26, 2026 09:37
@colega
colega requested a review from a team as a code owner June 26, 2026 09:37
Comment thread cmd/tk/flags.go
return func() map[string]string {
m := make(map[string]string)
for _, s := range *injectLabels {
split := strings.SplitN(s, "=", 2)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread cmd/tk/flags.go
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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of adding some additional validation here so that invalid k8s labels don't sneak through?

Image

https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants