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

PR for using a env file in oc cmdline #10766

Closed
wants to merge 5 commits into from
Closed

PR for using a env file in oc cmdline #10766

wants to merge 5 commits into from

Conversation

ravisantoshgudimetla
Copy link
Contributor

@bparees, As discussed this is PR for #7585. Please provide some feedback on the set of changes made.

@bparees bparees assigned php-coder and unassigned php-coder Sep 1, 2016
@@ -164,6 +167,7 @@ func NewCmdNewApplication(commandName string, f *clientcmd.Factory, out io.Write
cmd.Flags().StringSliceVarP(&config.TemplateParameters, "param", "p", config.TemplateParameters, "Specify a list of key value pairs (e.g., -p FOO=BAR,BAR=FOO) to set/override parameter values in the template.")
cmd.Flags().StringSliceVar(&config.Groups, "group", config.Groups, "Indicate components that should be grouped together as <comp1>+<comp2>.")
cmd.Flags().StringSliceVarP(&config.Environment, "env", "e", config.Environment, "Specify key-value pairs of environment variables to set into each container. This doesn't apply to objects created from a template, use parameters instead.")
cmd.Flags().StringVar(&config.EnvironmentFile, "env-file", "", "Specify file containing key-value pairs of environment variables to set into each container.")
Copy link
Contributor

Choose a reason for hiding this comment

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

"Specify a file", and needs the same caveat as --env has about not being applicable to templates.

@bparees
Copy link
Contributor

bparees commented Sep 1, 2016

where did the two .py files in this PR come from?

@fabianofranz
Copy link
Member

@openshift/cli-review

@fabianofranz
Copy link
Member

@ravisantoshgudimetla thanks for the PR! You need to run hack/update-generated-docs.sh ; hack/update-generated-completions.sh to generate docs and completions.

@ravisantoshgudimetla
Copy link
Contributor Author

I think, I did messed up rebasing my fork, please ignore this, I will update it again with only my changes.

@ravisantoshgudimetla
Copy link
Contributor Author

@fabianofranz , sure, I will generate them once I am done with initial review. Thanks

// Environment File where the parameters are stored
if len(g.EnvironmentFile) != 0 && !app.IsPossibleEnvironmentFile(g.EnvironmentFile) {
return nil, fmt.Errorf("when --env-file is specified you must provide a valid env file location")
}
if len(g.Strategy) != 0 && len(repositories) == 0 && !g.BinaryBuild {
return nil, fmt.Errorf("when --strategy is specified you must provide at least one source code location")
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

While I agree with your logic, I think it still doesn't explain validation for above lines, especially the logic for checking strategy and repository location should be moved to another function, if I understood you correctly. However, I made the changes the you suggested, now the validation logic resides in newapp.go within validate() function. Also, please note that format for env file is "--env-file=myenvfile" not "--env-file myenvfile"

Copy link
Contributor

Choose a reason for hiding this comment

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

cobra supports either syntax. the = is optional.

The repository logic belongs here because we are in a section of code that is resolving what type of argument has been supplied. the environment-file argument does not need to be handled in that way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh great, thanks for correcting me. I just tried that without = & it works perfectly fine and for the second part, I get your point now, since we are trying to resolve a component type called repository, we have it here- makes sense.

@ravisantoshgudimetla
Copy link
Contributor Author

@fabianofranz, I have generated the docs and autocompletion.

@bparees , I think I made all the changes suggested by you, except for IsPossibleEnvironmentFile - whether it should be there or not. Please let me know, if you have any other concerns. Once we finalize IsPossibleEnvironmentFile and other concerns, I wish to get started on writing test cases.

fileexists = false
}
return isFile(value) && fileexists
}
Copy link
Contributor

Choose a reason for hiding this comment

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

seems like it would make more sense to just move this logic inside the GetEnvironmentVars function and have GetEnvironmentVars return an error if the path is not an existing file.

@bparees
Copy link
Contributor

bparees commented Sep 2, 2016

@ravisantoshgudimetla one last nit and i think you're in good shape to start on tests.

@@ -164,6 +167,7 @@ func NewCmdNewApplication(commandName string, f *clientcmd.Factory, out io.Write
cmd.Flags().StringSliceVarP(&config.TemplateParameters, "param", "p", config.TemplateParameters, "Specify a list of key value pairs (e.g., -p FOO=BAR,BAR=FOO) to set/override parameter values in the template.")
cmd.Flags().StringSliceVar(&config.Groups, "group", config.Groups, "Indicate components that should be grouped together as <comp1>+<comp2>.")
cmd.Flags().StringSliceVarP(&config.Environment, "env", "e", config.Environment, "Specify key-value pairs of environment variables to set into each container. This doesn't apply to objects created from a template, use parameters instead.")
cmd.Flags().StringVar(&config.EnvironmentFile, "env-file", "", "Specify a file containing key-value pairs of environment variables to set into each container. This doesn't apply to objects created from a template, use parameters instead.")
Copy link
Member

Choose a reason for hiding this comment

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

A few of the other commands that support files also support a directory or the URL to a file. Should we also support it here, or just local path to a single file?

Copy link
Member

Choose a reason for hiding this comment

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

cmd.MarkFlagFilename("env-file") will make command line completions work. You can optionally pass the accepted file extensions but I think that's not the case here.

Copy link
Member

Choose a reason for hiding this comment

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

Also I'm mostly good with the chosen flag name, but here are other options based on some other places where we accept something similar: --env-from-file, --env-from.

Copy link
Contributor

Choose a reason for hiding this comment

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

if we can get url support for free from some existing tools in openshift/k8s i'm fine with supporting that, otherwise i'm not convinced it's worth it for now.

Copy link
Member

Choose a reason for hiding this comment

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

@bparees I agree. It's in the builder, I don't think it's reusable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@fabianofranz . Can I append it to cmd.MarkFlagFilename("file", "yaml", "yml", "json") so that it becomes something like cmd.MarkFlagFilename("file", "yaml", "yml", "json", "env-file")

Copy link
Member

Choose a reason for hiding this comment

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

No, just add cmd.MarkFlagFilename("env-file") (the first argument is the flag name) right after the flag declaration. I don't think we should restrict on file extensions once you can have anything here, like a .txt, a filename without extension, etc.

Copy link
Contributor Author

@ravisantoshgudimetla ravisantoshgudimetla Sep 2, 2016

Choose a reason for hiding this comment

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

Ok, thanks, will do that.
One more question, do we need that statement, its already not applying any restrictions on the extension of file.

Copy link
Member

Choose a reason for hiding this comment

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

We need that statement for command line completions. Meaning if you do --env-file=[tab][tab] it will suggest files and dirs based on the local path. ;)

@bparees
Copy link
Contributor

bparees commented Sep 8, 2016

@ravisantoshgudimetla can you please squash the commits into a single commit and then lgtm.
@fabianofranz anything else?

this will be a post 3.3 merge.

@bparees bparees added this to the 1.3.1 milestone Sep 8, 2016
@fabianofranz
Copy link
Member

LGTM from a cli perspective.

@openshift-bot openshift-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 16, 2016
@openshift-bot openshift-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 16, 2016
@smarterclayton smarterclayton modified the milestones: 1.3.1, 1.4.0 Sep 19, 2016
@openshift-bot openshift-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 29, 2016
@openshift-bot openshift-bot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Oct 23, 2016
@openshift-bot openshift-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 27, 2016
@openshift-bot openshift-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 7, 2016
@ncdc
Copy link
Contributor

ncdc commented Nov 22, 2016

Is this still for 1.4?

@bparees bparees removed this from the 1.4.0 milestone Nov 22, 2016
@bparees
Copy link
Contributor

bparees commented Nov 22, 2016

@ncdc no and unfortunately it appears to be abandoned.

@openshift-bot openshift-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 21, 2017
@openshift-bot
Copy link
Contributor

Origin Action Required: Pull request cannot be automatically merged, please rebase your branch from latest HEAD and push again

@openshift-bot openshift-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 21, 2017
@bparees
Copy link
Contributor

bparees commented Jan 21, 2017

this was implemented in #12164

@bparees bparees closed this Jan 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. priority/P2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants