Skip to content
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

Merged
merged 2 commits into from
Mar 24, 2017

Conversation

fraenkel
Copy link
Contributor

@fraenkel fraenkel commented Dec 16, 2016

Allow ConfigMaps to be created from Docker based env files.

See proposal kubernetes/community#165

Release-note:

1. create configmap has a new option --from-env-file that populates a configmap from file which follows a key=val format for each line.
2. create secret has a new option --from-env-file that populates a configmap from file which follows a key=val format for each line.

@k8s-ci-robot
Copy link
Contributor

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 @k8s-bot ok to test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

If you have questions or suggestions related to this bot's behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Dec 16, 2016
@k8s-reviewable
Copy link

This change is Reviewable

@k8s-github-robot k8s-github-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. release-note-label-needed labels Dec 16, 2016
@k8s-github-robot k8s-github-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-label-needed labels Jan 8, 2017
@fraenkel
Copy link
Contributor Author

@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.

@bgrant0607
Copy link
Member

ref #8800

@fabianofranz
Copy link
Contributor

@k8s-bot ok to test

@fraenkel fraenkel force-pushed the configmap_env_file branch 2 times, most recently from e1750ed to 9f254db Compare February 15, 2017 17:11
@@ -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.")
Copy link
Contributor

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).

@@ -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.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

# 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
Copy link
Contributor

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.

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`)
Copy link
Contributor

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.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation.

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`)
Copy link
Contributor

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.

@@ -186,6 +210,27 @@ func handleConfigMapFromFileSources(configMap *api.ConfigMap, fileSources []stri
return nil
}

// handleConfigMapFromEnvFileSources adds the specified env file source information
Copy link
Contributor

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")
Copy link
Contributor

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"

Copy link
Contributor Author

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.

@@ -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 {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

)

// addFromEnvFile adds an env file to a ConfigMap or returns an error.
func addFromEnvFile(filePath string, addTo func(key, value string) error) error {
Copy link
Contributor

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.

@fraenkel
Copy link
Contributor Author

@fabianofranz All your concerns/comments should be resolved with this latest set of commits.

@fabianofranz
Copy link
Contributor

@fraenkel tks! Note that the release note only mentions 'create configmap', must also include 'create secret'.

@fabianofranz
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 20, 2017
@fraenkel
Copy link
Contributor Author

@fabianofranz release note updated

@fabianofranz
Copy link
Contributor

/approve
Thanks @fraenkel!

@fabianofranz
Copy link
Contributor

/approve

@k8s-github-robot k8s-github-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Feb 21, 2017
@k8s-github-robot k8s-github-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. and removed approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Mar 1, 2017
@k8s-github-robot k8s-github-robot removed lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Mar 8, 2017
@fraenkel
Copy link
Contributor Author

Can someone add back the lgtm that got removed due to a rebase?

@adohe-zz
Copy link

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 12, 2017
@k8s-github-robot
Copy link

[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:
cc
You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 41139, 41186, 38882, 37698, 42034)

@k8s-github-robot k8s-github-robot merged commit 0e17e5b into kubernetes:master Mar 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants