Env vars given with --env/--env-value-from/--env-file are silently dropped when they can't be matched in the command line

Open Beginner friendly
#2,277 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@NopeCharon is already working on this.

Since Oct 28, 2026.

  • #2279 by @NopeCharon — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go
Domain
cli

Research direction

Start by reading UpdateEnvVars in pkg/flags/podspec_helper.go and trace how the --env, --env-value-from, and --env-file entries are collected and ordered from command-line arguments. Ensure matching affects order only, so unmatched entries are still applied. Done means the reported short-flag, repeated-name, and plugin cases retain all requested variables.

Written by the indexing model from the issue text.

Description

Bug report

kn service create / kn service update silently drop some of the environment variables given with --env, --env-value-from or --env-file. The command succeeds, but the variables are missing from the created revision.

UpdateEnvVars in pkg/flags/podspec_helper.go determines the order of the env vars by walking os.Args and matching every argument against the next expected NAME=value entry of each flag. Any entry that can't be matched this way is never added to the container. This happens for example when:

  • the short flag is used without a separator, e.g. -eFOO=bar (only -e FOO=bar, -e=FOO=bar and --env=FOO=bar are recognized),
  • a name is given more than once, e.g. -e A=1 -e B=2 -e A=3: the matching gets stuck on A=3 while B=2 passes by, so B is lost,
  • the pkg library is used from another binary (e.g. a plugin) whose os.Args don't contain the kn flags at all: then no env var is set.
Expected behavior

All requested environment variables are set. Matching against the arguments should only influence the order, never whether a variable is applied.

Steps to reproduce the problem
kn service create foo --image gcr.io/knative-samples/helloworld-go -eFOO=bar --no-wait
kn service describe foo -o yaml | grep -A3 env   # FOO is missing

kn service create bar --image gcr.io/knative-samples/helloworld-go -e A=1 -e B=2 -e A=3 --no-wait
kn service describe bar -o yaml | grep -A5 env   # only A=3, B is missing
kn version
main (f2bfc7f3)
Knative (serving/eventing) version

Nightly

Dominant language
Go
Stars
387
Forks
278
Avg merge
2d 10h
Merged PRs (30d)
8

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from knative/client

All issues in knative/client

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.