Skip to content

Fix: read flags from environment variables, as documented - #70

Open
briankane wants to merge 3 commits into
kubevela:mainfrom
briankane:feat/flags-from-env
Open

briankane wants to merge 3 commits into
kubevela:mainfrom
briankane:feat/flags-from-env

Conversation

@briankane

@briankane briankane commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Description of your changes

kubetrigger --help and the README's configuration reference say every option can be given as an environment variable named after its flag ($LOG_LEVEL for --log-level), with the precedence command line, then environment, then default. Nothing read the environment, so these variables were ignored.

Before running, each flag not given on the command line is now set from its variable: the flag's name in capitals, with - as _. A value that does not parse is an error naming the variable ($MAX_RETRY: invalid argument "lots" ...).

Options were also validated in NewCommand, before any flag was parsed, so only the defaults were ever checked: --workers=0 passed validation. They are now validated after the command line and the environment are both applied.

I have:

  • Read and followed KubeVela's pull request process.
  • All commits are signed off (DCO).
  • Related Docs updated properly. Not needed: the README and help already describe this behaviour.
  • Run make reviewable to ensure this PR is ready for review. (Ran make lint, make checklicense and go mod tidy; no generated code is affected.)
  • Added backport release-x.y labels to auto-backport this PR if necessary. Not needed: kube-trigger has no release branches.

How has this code been tested

pkg/cmd/env_test.go: a variable sets a flag not given; a flag given on the command line beats its variable; the default applies with neither; names map - to _ for ints, bools and durations (PER_WORKER_QPS, LEADER_ELECT, LEADER_ELECTION_LEASE_DURATION); a bad value names its variable; and validation sees the final values (WORKERS=0 is refused). go test ./pkg/... ./controllers/... passes; golangci-lint and staticcheck are clean.

Special notes for your reviewer

Independent of the other open kube-trigger PRs. #68 adds --enable-cel-expressions with its README ENV entry marked TODO; whichever of the two merges second should set it to ENABLE_CEL_EXPRESSIONS.


Summary by cubic

Honors the environment variables kubetrigger documents for its flags ($LOG_LEVEL for --log-level, and so on), and fixes flag validation so it no longer runs before flags are parsed.

  • Flags not given on the command line are read from $FLAG_NAME (capitals, - as _), with precedence command line, then environment, then default; a value that fails to parse errors naming the variable.
  • Validation now runs in PreRunE after the command line and environment are applied, so invalid final values like WORKERS=0 are rejected with an error naming the variable or flag, and --action-retry (documented but never registered) is now wired up alongside $ACTION_RETRY.
  • Tests clear every flag's variable first, so inherited variables like LOG_LEVEL=bogus can't break them.

Written for commit 67b744a. Summary will update on new commits.

View guided diff

The command's help and the README say every option can be given as an
environment variable named after its flag, with flags taking precedence
over the environment and the environment over defaults. Nothing read the
environment, so $LOG_LEVEL and the rest were ignored.

Before running, each flag not given on the command line is now set from
its variable: the flag's name in capitals, with - as _. A value that does
not parse is an error naming the variable.

Options were also validated in NewCommand, before any flag was parsed,
so only the defaults were ever checked. They are now validated after the
command line and the environment are both applied.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HGACRqRjRF3TqH6B9vVijh
Signed-off-by: Brian Kane <briankane1@gmail.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 3 files

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread pkg/cmd/env_test.go Resolved
Comment thread pkg/cmd/cmd.go Resolved
Comment thread pkg/cmd/env.go Resolved
@codecov

codecov Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.61%. Comparing base (3949320) to head (67b744a).

Files with missing lines Patch % Lines
pkg/cmd/cmd.go 77.77% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #70      +/-   ##
==========================================
+ Coverage   45.39%   48.61%   +3.21%     
==========================================
  Files          31       32       +1     
  Lines        1454     1475      +21     
==========================================
+ Hits          660      717      +57     
+ Misses        794      758      -36     
Flag Coverage Δ
unittests 48.61% <92.00%> (+3.21%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Review follow-ups.

- --action-retry was documented, and had its constant and option field,
  but was never registered, so neither it nor $ACTION_RETRY could turn on
  retries. It is now a flag like the rest.
- A validation error for a value from the environment says which
  variables were applied, so WORKERS=0 or LOG_LEVEL=bogus point at the
  variable to fix. A bad log level now names --log-level too.
- The test of defaults clears every flag's variable first, so nothing
  the test process inherits can change the result.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HGACRqRjRF3TqH6B9vVijh
Signed-off-by: Brian Kane <briankane1@gmail.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 4 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread pkg/cmd/env_test.go Resolved
Each test applies every flag's variable, so an inherited LOG_LEVEL or
WORKERS could fail one that sets something else. Every test now clears
them all before setting its own; the tests pass with LOG_LEVEL=bogus,
WORKERS=0 and MAX_RETRY=7 in the environment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HGACRqRjRF3TqH6B9vVijh
Signed-off-by: Brian Kane <briankane1@gmail.com>
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.

1 participant