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
Added support for multiple --from-env flags #101646
Conversation
@lauchokyip: This issue is currently awaiting triage. If a SIG or subproject determines this is a relevant issue, they will accept it by applying the The 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 @KnVerey |
@@ -429,20 +476,28 @@ func TestCreateConfigMap(t *testing.T) { | |||
} | |||
} | |||
|
|||
func setupEnvFile(lines ...string) func(*testing.T, *ConfigMapOptions) func() { | |||
func setupEnvFile(filenames []string, lines [][]string) func(*testing.T, *ConfigMapOptions) func() { |
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.
Do the tests actually need to control the filenames? If not, I'd suggest simply including the index in the filename below, to simplify setup. If they do, I'd suggest making the argument filemap map[string][]string
(e.g. "filename": {"l1", "l2"}
so that it's easier to understand what's going where.
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.
no, it's no needed 😕
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.
Great work! I have a few small questions/quibbles, but I tried it out locally and it is working nicely.
@@ -87,7 +87,7 @@ type ConfigMapOptions struct { | |||
// LiteralSources to derive the configMap from (optional) | |||
LiteralSources []string | |||
// EnvFileSource to derive the configMap from (optional) | |||
EnvFileSource string | |||
EnvFileSource []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.
Let's change the variable/method naming to be plural all around, like it is for the other sources.
EnvFileSource []string | |
EnvFileSources []string |
return fmt.Errorf("error reading %s: %v", envFileSource, err.Err) | ||
default: | ||
return fmt.Errorf("error reading %s: %v", envFileSource, err) | ||
func handleConfigMapFromEnvFileSource(configMap *corev1.ConfigMap, envFileSources []string) error { |
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.
func handleConfigMapFromEnvFileSource(configMap *corev1.ConfigMap, envFileSources []string) error { | |
func handleConfigMapFromEnvFileSources(configMap *corev1.ConfigMap, envFileSources []string) error { |
@@ -414,8 +458,11 @@ func TestCreateConfigMap(t *testing.T) { | |||
defer teardown() | |||
} | |||
} | |||
err := configMapOptions.Validate() |
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.
Why is this added?
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 was the one that remove the generator of the ConfigMap (https://github.com/pulls?q=is%3Apr+author%3Alauchokyip+archived%3Afalse+is%3Aclosed) and when I wrote the test cases for example this test cases
"create_invalid_configmap_too_many_args": { |
Validate()
would actually catch the error here if len(o.EnvFileSource) > 0 && (len(o.FileSources) > 0 || len(o.LiteralSources) > 0) { |
create_secret_test.go
err := secretOptions.Validate() |
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.
What I still don't understand is why this PR makes this change necessary. If the errors the cases you point to are meant to hit are in Validate
and only createConfigMap
is being called on master today, then how are the tests passing on master? Are they hitting errors other than the ones they're meant to? Incidentally, that possibility is one reason why I personally prefer to make error expectations strings to match on rather than booleans, to provide better assurances that the error that happens is the one I expect.
To be clear, I'm not opposed to this change--just want to make sure I understand it.
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.
Will take a look into it
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.
Turn out the error happened during createConfigMap
For instance the test case create_invalid_configmap_too_many_args
, instead of throwing the error (from-env-file cannot be combined with from-file or from-literal
) it actually tries to create a config map from the file and it cannot read the file therefore throws an error
I agree comparing string error is way better so I will make a change from that
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.
Thanks for digging into this, and great job with the improvements to this file!
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.
@lauchokyip your latest rebase seems to have lost the changes from this discussion, i.e. the ones visible in https://github.com/kubernetes/kubernetes/compare/cc37d5df54caaaa50291d37c93042d73ea506778..977ca6feb4fe433e667df051dfa4b4c21e4fce02. Can you please restore them? Note that one of the error strings that shows up in that diff answers @eddiezane question. 😄
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.
Yes I am restoring them! Thanks for the reminder 😃
e92e84b
to
e00ee11
Compare
/retest |
if !test.expectErr && err != nil { | ||
t.Errorf("test %s, unexpected error: %v", name, err) | ||
t.Errorf("unexpected error: %v", err) |
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.
removed the name
because if the unit test fails it would already output the name so in my opinion it's repetitive and confusing
/assign @eddiezane |
@@ -86,8 +86,8 @@ type ConfigMapOptions struct { | |||
FileSources []string | |||
// LiteralSources to derive the configMap from (optional) | |||
LiteralSources []string | |||
// EnvFileSource to derive the configMap from (optional) | |||
EnvFileSource 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.
This struct and field are exported. This will be a breaking change to any external consumers. Not sure if there are any 🤔.
https://cs.k8s.io/?q=EnvFileSource&i=nope&files=&excludeFiles=&repos=
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 guess with our refactoring of the commands anyways it doesn't matter.
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.
My instinct is that the flags used to build a CLI are particular to that CLI itself, and not intended for library use. That search isn't really showing any consumers in any case; Kustomize's implementation matches but is independent, and driver-registrar is just showing up as vendored, not used. The rest is this code itself and its mirror. So IMO there's no problem with this change, but we can check with other approvers if you're worried about it. :)
expectErr bool | ||
expected *corev1.ConfigMap | ||
expectErr bool | ||
expectErrStr 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.
I'd suggest consolidating into only the string field. We should never expect a blank error, so the boolean is kinda redundant and needs to be synchronized (e.g. right now you could set an error string but forget to set expectErr to true and it wouldn't get checked).
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.
makes sense
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
@@ -86,8 +86,8 @@ type ConfigMapOptions struct { | |||
FileSources []string | |||
// LiteralSources to derive the configMap from (optional) | |||
LiteralSources []string | |||
// EnvFileSource to derive the configMap from (optional) | |||
EnvFileSource 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.
My instinct is that the flags used to build a CLI are particular to that CLI itself, and not intended for library use. That search isn't really showing any consumers in any case; Kustomize's implementation matches but is independent, and driver-registrar is just showing up as vendored, not used. The rest is this code itself and its mirror. So IMO there's no problem with this change, but we can check with other approvers if you're worried about it. :)
@@ -414,8 +458,11 @@ func TestCreateConfigMap(t *testing.T) { | |||
defer teardown() | |||
} | |||
} | |||
err := configMapOptions.Validate() |
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.
Thanks for digging into this, and great job with the improvements to this file!
@lauchokyip sorry I missed this. Please rebase when you get a chance and we can get merged after code thaw. |
@eddiezane Rebased. PTAL 😄 |
Thanks! What's the intended behavior for duplicate entries? Second one overrides the first? |
Second one is rejected. Regardless of original source, the entries are added with |
In case my comment is hard to find, I noticed yesterday that the latest force push seems to have lost some of the previous requested changes: #101646 (comment) |
15dbb42
to
8b91b8c
Compare
@KnVerey and @eddiezane , I restored the previous changes, PTAL, thank you 👍🏼 |
|
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.
Just a tiny request to revert an additional change that slipped in, otherwise looks good!
@@ -68,8 +68,8 @@ var ( | |||
# Create a new config map named my-config from the key=value pairs in the file | |||
kubectl create configmap my-config --from-file=path/to/bar | |||
|
|||
# Create a new config map named my-config from an env file | |||
kubectl create configmap my-config --from-env-file=path/to/bar.env`)) | |||
# Create a new configmap named my-config from an env file |
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.
Please revert this change--it's spelled as two words in all the other help text above
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.
Will do! Thanks for the fast review!
/retest |
/retest-required |
/lgtm |
Great job team! Awesome work on this one. /approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: eddiezane, lauchokyip 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 |
What type of PR is this?
/kind feature
What this PR does / why we need it:
Added support for multiple --from-env flags
Which issue(s) this PR fixes:
Fixes kubernetes/kubectl#1033
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: