-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
PR for using a env file in oc cmdline #10766
Conversation
@@ -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.") |
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.
"Specify a file", and needs the same caveat as --env has about not being applicable to templates.
where did the two .py files in this PR come from? |
@openshift/cli-review |
@ravisantoshgudimetla thanks for the PR! You need to run |
I think, I did messed up rebasing my fork, please ignore this, I will update it again with only my changes. |
@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") | ||
} |
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.
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"
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.
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.
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.
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.
@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 | ||
} |
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.
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.
@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.") |
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.
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?
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.
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.
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.
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
.
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.
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.
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.
@bparees I agree. It's in the builder, I don't think it's reusable.
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.
@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")
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, 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.
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.
Ok, thanks, will do that.
One more question, do we need that statement, its already not applying any restrictions on the extension of 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.
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. ;)
@ravisantoshgudimetla can you please squash the commits into a single commit and then lgtm. this will be a post 3.3 merge. |
LGTM from a cli perspective. |
Is this still for 1.4? |
@ncdc no and unfortunately it appears to be abandoned. |
Origin Action Required: Pull request cannot be automatically merged, please rebase your branch from latest HEAD and push again |
this was implemented in #12164 |
@bparees, As discussed this is PR for #7585. Please provide some feedback on the set of changes made.