-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Exec] Allow expanding envs at tester runtime #110
Conversation
ping |
if strings.Contains(arg, `\$`) { | ||
expandedArgs[i] = strings.ReplaceAll(arg, `\$`, `$`) | ||
} else { | ||
expandedArgs[i] = os.ExpandEnv(arg) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if strings.Contains(arg, `\$`) { | |
expandedArgs[i] = strings.ReplaceAll(arg, `\$`, `$`) | |
} else { | |
expandedArgs[i] = os.ExpandEnv(arg) | |
} | |
if strings.Contains(arg, `\$`) { | |
arg = strings.ReplaceAll(arg, `\$`, `$`) | |
} | |
expandedArgs[i] = os.ExpandEnv(arg) |
flows a little better imo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we explicitly don't want to expand escaped $
hence the else
?
@@ -64,8 +65,23 @@ func (t *Tester) Execute() error { | |||
return t.Test() | |||
} | |||
|
|||
func expandEnv(args []string) []string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usually an expandenv function supports shell syntax like --foo=${BAR}
.
we should look at how kubernetes implements this for pods for ecosystem consistency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's using os.ExpandEnv
inside so this syntax also works?
Also note: This can currently be worked around by spawning a subshell (and letting it do the evaluation) as the test command instead of the actual test command.
But I think this (expanding envs at tester runtime) is going to be the more widely required use case, so it's better if the exec tester itself supports this and we can avoid having subshells in all the configs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
/lgtm
The syntax in the description is pretty straightforward to me re: when does my env get expanded
I sorta wonder if this should happen consistently for all testers though? Maybe exec is the only one that needs it for now
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: amwat, spiffxp The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
ref: kubernetes/test-infra#21331
kubetest2 passes a bunch of info through envs to the tester, but typical inline bash prow jobs imply that they will be expanded during deployer invocation and not tester invocation. This especially affects the exec tester.
Might be possible to quote it in some fancy way, but instead opted to support it directly in the tester.
Covered only the most common use cases and is not intended to cover all shell special character shenanigans.
Previously
Now
Note: while running on the command line users still need to keep in mind the shell expansion itself.
/cc @spiffxp @BenTheElder @MushuEE