-
Notifications
You must be signed in to change notification settings - Fork 39.8k
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
create configmap from-env-file #38882
create configmap from-env-file #38882
Conversation
Hi @fraenkel. 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 If you have questions or suggestions related to this bot's behavior, please file an issue against the kubernetes/test-infra repository. |
764d60c
to
e153ccc
Compare
@adohe Can we get this reviewed now that the proposal has been accepted. I will add some kubectl tests. I don't think e2e is needed. |
ref #8800 |
@k8s-bot ok to test |
e1750ed
to
9f254db
Compare
pkg/kubectl/cmd/create_configmap.go
Outdated
@@ -71,6 +77,7 @@ func NewCmdCreateConfigMap(f cmdutil.Factory, cmdOut io.Writer) *cobra.Command { | |||
cmdutil.AddGeneratorFlags(cmd, cmdutil.ConfigMapV1GeneratorName) | |||
cmd.Flags().StringSlice("from-file", []string{}, "Key files can be specified using their file path, in which case a default name will be given to them, or optionally with a name and file path, in which case the given name will be used. Specifying a directory will iterate each named file in the directory that is a valid configmap key.") | |||
cmd.Flags().StringArray("from-literal", []string{}, "Specify a key and literal value to insert in configmap (i.e. mykey=somevalue)") | |||
cmd.Flags().String("from-env-file", "", "Specify an env file which contains key=val pairs that are inserted into a configmap.") |
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.
Reading the proposal, I think this should make it clear that multiple key=val pairs can be specified in lines, and that Docker .env is an example of valid file format. I'd suggest something like Specify the path to a file from which to read lines of key=val pairs to create as configmaps (i.e. a Docker .env file)
.
pkg/kubectl/cmd/create_secret.go
Outdated
@@ -85,6 +88,7 @@ func NewCmdCreateSecretGeneric(f cmdutil.Factory, cmdOut io.Writer) *cobra.Comma | |||
cmdutil.AddGeneratorFlags(cmd, cmdutil.SecretV1GeneratorName) | |||
cmd.Flags().StringSlice("from-file", []string{}, "Key files can be specified using their file path, in which case a default name will be given to them, or optionally with a name and file path, in which case the given name will be used. Specifying a directory will iterate each named file in the directory that is a valid secret key.") | |||
cmd.Flags().StringArray("from-literal", []string{}, "Specify a key and literal value to insert in secret (i.e. mykey=somevalue)") | |||
cmd.Flags().String("from-env-file", "", "Specify an env file which contains key=val pairs that are inserted into a secret.") |
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.
Same here.
pkg/kubectl/cmd/create_configmap.go
Outdated
# Create a new configmap named my-config from the key=value pairs in the file | ||
kubectl create configmap my-config --from-file=path/to/bar | ||
|
||
# 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 correct the indentation here.
pkg/kubectl/cmd/create_configmap.go
Outdated
kubectl create configmap my-config --from-file=path/to/bar | ||
|
||
# Create a new configmap named my-config from an env file | ||
kubectl create configmap my-config --from-env-file=path/to/bar`) |
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 using .env
in the examples, like ... --from-env-file=path/to/file.env
.
pkg/kubectl/cmd/create_secret.go
Outdated
kubectl create secret generic my-secret --from-literal=key1=supersecret --from-literal=key2=topsecret`) | ||
kubectl create secret generic my-secret --from-literal=key1=supersecret --from-literal=key2=topsecret | ||
|
||
# Create a new secret named my-secret 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.
Indentation.
pkg/kubectl/cmd/create_secret.go
Outdated
kubectl create secret generic my-secret --from-literal=key1=supersecret --from-literal=key2=topsecret | ||
|
||
# Create a new secret named my-secret from an env file | ||
kubectl create secret generic my-secret --from-env-file=path/to/bar`) |
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.
Same, .env
in the example.
pkg/kubectl/configmap.go
Outdated
@@ -186,6 +210,27 @@ func handleConfigMapFromFileSources(configMap *api.ConfigMap, fileSources []stri | |||
return nil | |||
} | |||
|
|||
// handleConfigMapFromEnvFileSources adds the specified env file source information |
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.
handleConfigMapFromEnvFileSource
} | ||
} | ||
if info.IsDir() { | ||
return fmt.Errorf("must be a 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.
"from-env-file must point to a file, not directory"
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.
Right, if its a directory, we error saying it needs to be a file.
pkg/kubectl/configmap.go
Outdated
@@ -209,3 +254,48 @@ func addKeyFromLiteralToConfigMap(configMap *api.ConfigMap, keyName, data string | |||
configMap.Data[keyName] = data | |||
return nil | |||
} | |||
|
|||
// addFromEnvFileToConfigMap adds an env file to a ConfigMap or returns an error. | |||
func addFromEnvFileToConfigMap(configMap *api.ConfigMap, filePath 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.
Reuse the one in env_file.go
?
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 needed to be removed.
pkg/kubectl/env_file.go
Outdated
) | ||
|
||
// addFromEnvFile adds an env file to a ConfigMap or returns an error. | ||
func addFromEnvFile(filePath string, addTo func(key, value string) error) 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.
Make it clear it's a generic func, not mentioning ConfigMap.
9f254db
to
a20349e
Compare
@fabianofranz All your concerns/comments should be resolved with this latest set of commits. |
@fraenkel tks! Note that the release note only mentions 'create configmap', must also include 'create secret'. |
/lgtm |
@fabianofranz release note updated |
/approve |
/approve |
a20349e
to
f281515
Compare
Can someone add back the lgtm that got removed due to a rebase? |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED The following people have approved this PR: AdoHe, fabianofranz, fraenkel Needs approval from an approver in each of these OWNERS Files:
We suggest the following people: |
Automatic merge from submit-queue (batch tested with PRs 41139, 41186, 38882, 37698, 42034) |
Allow ConfigMaps to be created from Docker based env files.
See proposal kubernetes/community#165
Release-note: