-
Notifications
You must be signed in to change notification settings - Fork 39k
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
Fixed set env did not support keys with dot in it #98846
Conversation
Hi @lauchokyip. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/cc @soltysh |
/ok-to-test |
/retest |
TBH I'm a bit confused of what should be the right behavior: accept or not the env var with ".". If I try to export a variable with . in the name (like export LALA.BLABLA=1) shell will not allow me, because this is not a valid identifier. If we allow this to be done with kubectl, can this lead any other component (kubelet, the container runtime, etc) into some wrong behavior? I'll make some tests here |
OK now I saw the referenced PR of the past that this is strict only in shells. Will make some further tests here and let you know |
Yup @rikatz , I think that PR mentions K8s environment is different from shell environment. I tested in a deployment pod and added some test cases. |
@lauchokyip thank you for the PR. I'm taking a look into the 'parseIntoEnvVar' and I guess this could be a bit improved with your PR. As an example, what I guess could work:
This validation is being used in other parts of the code (including the PR you've referenced before), like here: https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/kubectl/pkg/cmd/util/env_file.go#L56-L60 This way, you can:
WDYT? |
do we still want to check for |
and should I include the dependency from https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/kubectl/pkg/cmd/util/env_file.go#L56-L60, or copy the code inside? |
Only including the util is enough IMO. About the suffix, I guess it would be good to keep the last case statement. |
/triage accepted |
32a4486
to
44bb4d4
Compare
/retest |
/lgtm Thank you! |
/priority important-longterm |
/lgtm |
|
||
// IsEnvironmentArgument checks whether a string is an environment argument, that is, whether it matches the "anycharacters=anycharacters" pattern. | ||
func IsEnvironmentArgument(s string) bool { | ||
return argumentEnvironment.MatchString(s) | ||
} | ||
|
||
// IsValidEnvironmentArgument checks whether a string is a valid environment argument, that is, whether it matches the "wordcharacters=anycharacters" pattern. Word characters can be letters, numbers, and underscores. | ||
func IsValidEnvironmentArgument(s string) bool { |
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.
This is an exported function but it doesn't look like it's being used elsewhere? Probably not a breaking change?
https://cs.k8s.io/?q=IsValidEnvironmentArgument&i=nope&files=&excludeFiles=&repos=
@soltysh thoughts?
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.
This shouldn't be an issue.
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.
this is being removed anyway :D
Moved to call validation.IsEnvVarName which is already used by other parts of the code
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.
Except for a small nit about import aliases, this looks good to me. I will approve this once import is updated.
@@ -23,23 +23,18 @@ import ( | |||
"regexp" | |||
"strings" | |||
|
|||
"k8s.io/api/core/v1" | |||
v1 "k8s.io/api/core/v1" |
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.
This import alias is redundant and unnecessary. In the future, most code is aliasing this import as "corev1".
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.
vscode does this trying to "help". Probably something we could get in the developer docs if it's not already there.
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.
I get beat by vscode ALWAYS with the autoimport doing this :/
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.
Oops
/retest |
@seans3 Fixed |
/lgtm |
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.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: lauchokyip, rikatz, seans3 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 |
/milestone v1.21 |
/retest |
What type of PR is this?
/kind bug
What this PR does / why we need it:
Fixed the bug that cannot set an environment variable name with a dot.
To reproduce:
kubectl set env deployment/app test.on=true
.An error will be thrown
error: environment variables must be of the form key=value and can only contain letters, numbers, and underscores
Which issue(s) this PR fixes:
Fixes kubernetes/kubectl#1014
Special notes for your reviewer:
/cc @rikatz
/cc @soltysh
Very similar PR #48986 <- was referring to this
Does this PR introduce a user-facing change?:
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: