Repository navigation
Read required environment variable prompts as a whole line - #6781
Conversation
Closes stacklok#6780. Signed-off-by: Chen Yufeiyang <fei76161@gmail.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7b921247c5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
jhrozek
left a comment
There was a problem hiding this comment.
Fix looks right, a few things around the non-interactive path.
Mention --env and --secret in the missing-variable error, keep EOF with data, and reject a partial line followed by any other read error.
|
All four points are in at
Run from the worktree: |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6781 +/- ##
==========================================
+ Coverage 79.98% 80.08% +0.09%
==========================================
Files 834 834
Lines 85190 85197 +7
==========================================
+ Hits 68140 68226 +86
+ Misses 17045 16966 -79
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
thv runprompts for a required, non-secret registry variable withfmt.Scanln, which reads one whitespace-delimited token. A value containing a space fails the read withexpected newline, the caller logs a warning and continues, and the workload starts without a variable the registry declaresrequired: true. The unread remainder stays in the stream, so the next prompt reads a fragment of the previous answer.bufio.Readershared by every prompt in aValidatecall. A required variable that cannot be read or is answered empty now returns an error with a--env/--secrethint instead of a warning.Fixes #6780
Type of change
API Compatibility
v1beta1API, OR theapi-break-allowedlabel is applied and the migration guidance is described above.Nothing here touches the operator CRD schema.
Test plan
go test -count=1 ./pkg/runner/—okgo test -count=1 ./pkg/runner/ -run 'TestDetachedEnvVarValidator_Validate|TestCLIEnvVarValidator_PromptsRequiredEnvVars|TestPromptForEnvironmentVariable'—okgo vet ./pkg/runner/— cleangofmt -l pkg/runner/— no outputNot run:
golangci-lintis not installed here, and the e2e/Kind/chainsaw suites. The change touches onlypkg/runner/env.goand its test file.Changes
pkg/runner/env.gobufio.Reader; a read error or empty answer for a required variable returnsmissing required environment variable NAME (pass it with --env NAME=<value> or --secret <name>,target=NAME); the same helper now backsDetachedEnvVarValidator;promptForEnvironmentVariablekeepsio.EOFonly when a line was readpkg/runner/env_test.goio.EOF; a direct test that a partial line followed by a non-EOF read error is rejectedDoes this introduce a user-facing change?
Yes. In a non-interactive run (
thv run ... </dev/nullin CI), before this branch a missing required variable printed the prompt, loggedfailed to read input ... EOFand started the workload without it. Now it exits, for example:The secret branch changed the same way: a failed
term.ReadPassword(for exampleinappropriate ioctl for devicewhen stdin is not a TTY) used to warn and continue, and now aborts with the same hint. The secret branch still reads a whole line throughterm.ReadPassword; only its failure handling changed. No TTY check was copied fromupgrade.gointothv run, so piping an answer still works and a required secret that the secrets manager can supply is still resolved before the prompt.Implementation plan
Plan followed
fmt.Scanlnwithbufio.Reader.ReadString('\n'), one reader perValidatecall so a buffered line is not discarded between prompts.io.EOFwith data). Reject any other read error even when a partial line came back, so a truncated required value cannot start the workload.DetachedEnvVarValidator(pkg/runner/env.go:57), and use one helper so both validators say how to pass the value without a prompt.Special notes for reviewers
promptForEnvironmentVariablenow takes a*bufio.Readerinstead of constructing one per call. It is package-private, so no exported signature changes.The
DetachedEnvVarValidatorerror text also gains the hint; its oldmissing required environment variable: NAMEshape had no test pinning the exact string.