Repository navigation
Conversation
|
WIP - would like to add some tests. |
|
Hrm - the @ syntax is unusual. How is it better than |
|
plumbing binary content or content with newlines through shell args is... not great I imagine the
|
|
At first I was expecting this to be |
8335fc4 to
8fb0c61
Compare
|
@smarterclayton The pflag library seems to be unable to handle multiline arguments. Also we try to support passing multiple variables separated by commas: edit: colon -> comma |
8fb0c61 to
745de66
Compare
|
We are removing support for |
745de66 to
440ee51
Compare
| err = errors.NewAggregate(errs) | ||
| return nil, fmt.Errorf("error processing template %s: %v", name, err) | ||
| if decode { | ||
| if errs := runtime.DecodeList(result.Objects, kapi.Codecs.UniversalDecoder()); len(errs) > 0 { |
There was a problem hiding this comment.
I'm not really sure what this does. However when I change oc process to do the decoding and then run it on this template the result is:
apiVersion: v1
items:
- FullName: ""
Groups: null
Identities: null
creationTimestamp: null
name: somename
kind: List
metadata: {}Instead of:
apiVersion: v1
items:
- apiVersion: v1
kind: User
metadata:
name: somename
kind: List
metadata: {}What am I missing?
There was a problem hiding this comment.
what do you mean by change oc process to do the decoding? this code here is just validating that the objects are valid and reporting errors if not.
There was a problem hiding this comment.
In current master, oc new-app calls runtime.DecodeList on the list of objects that is returned by the API endpoint /oapi/v1/namespaces/{namespace}/processedtemplates, oc process does not call this function.
When I modify oc process to call this function on the list of objects received from server and then run oc process -f test/testdata/template_required_params.yaml -v required_param=foo it gives me the first snippet which looks wrong.
I guess my question is what does this function do? It doesn't seem to only validate the objects since it overwrites the items in the slice passed to it as the first argument.
There was a problem hiding this comment.
// DecodeList alters the list in place, attempting to decode any objects found in
// the list that have the Unknown type. Any errors that occur are returned
// after the entire list is processed. Decoders are tried in order.
func DecodeList(objects []Object, decoders ...Decoder) []error {sounds like it is attempting to determine the actual api object type of each Object in the list, to convert it from a generic "unknown" to a specific type. Which might explain why the additional fields appear after you run something through it.
There was a problem hiding this comment.
but you can't run decodelist on https://github.com/openshift/origin/blob/master/test/testdata/template_required_params.yaml because that is a Template, not a List.
There was a problem hiding this comment.
Huh, looks like runtime.DecodeList really is innocent here. Will update PR once I figure out what's wrong.
There was a problem hiding this comment.
I think the invalid output is caused by the k8s printing machinery (kubectl.GetPrinter/kubectl.NewVersionedPrinter) which doesn't know about User objects as it is currently initialized.
It's probably better not to use DecodeList in oc process to keep the output format. For example it currently outputs
apiVersion: v1
items:
- apiVersion: v1
kind: User
metadata:
name: somename
kind: List
metadata: {}However if it used DecodeList (and changes were made to print User objects correctly) the output would look like this, with extra entries that weren't in the original template:
apiVersion: v1
items:
- apiVersion: v1
groups: null
identities: null
kind: User
metadata:
creationTimestamp: null
name: somename
kind: List
metadata: {}
that's a different feature that's coming (on the trello backlog anyway) |
440ee51 to
9849fcb
Compare
|
Force-pushed new version, please review. |
| cmd.Flags().StringP("filename", "f", "", "Filename or URL to file to read a template") | ||
| cmd.MarkFlagFilename("filename", "yaml", "yml", "json") | ||
| cmd.Flags().StringSliceP("value", "v", nil, "Specify a list of key-value pairs (eg. -v FOO=BAR,BAR=FOO) to set/override parameter values") | ||
| cmd.Flags().StringSliceP("value", "v", nil, "Specify a list of key-value pairs (eg. -v FOO=BAR,BAR=FOO) to set/override parameter values. Use FOO@path/to/file to load value from file.") |
There was a problem hiding this comment.
while we're in here, let's update this to "specify a key-value pair(eg -v FOO=BAR) to........." so we stop promoting the comma syntax.
| errs = append(errs, err) | ||
| continue | ||
| } | ||
| env[k] = string(value) |
There was a problem hiding this comment.
should be checking for duplicate key names here too right?
| return env, duplicates, errs | ||
| } | ||
|
|
||
| func ParseEnvironmentArgumentsFiles(s []string) (Environment, []string, []error) { |
There was a problem hiding this comment.
"ParseEnvironmentArguments"
There was a problem hiding this comment.
ok i see why you used a new name... how about ParseEnvironmentArgumentsWithFileValues. or update the existing helper to take a boolean arg that indicates if it should tolerate the @file syntax or not.
There was a problem hiding this comment.
I can update the existing helper, wasn't sure if such boolean arguments are acceptable style (haven't seen them much in the the codebase).
| if len(duplicates) > 0 { | ||
| return kcmdutil.UsageError(cmd, fmt.Sprintf("The following values were provided more than once: %s", strings.Join(duplicates, ", "))) | ||
| } | ||
|
|
There was a problem hiding this comment.
move this block up to just below where you processed the valueArgs.
There was a problem hiding this comment.
Done, I've also moved the block that checks for incompatible options to the very beginning so that the error behavior doesn't change too much.
9849fcb to
4d3849b
Compare
|
Updated, PTAL. |
| cmd.Flags().StringSliceVarP(&config.TemplateFiles, "file", "f", config.TemplateFiles, "Path to a template file to use for the app.") | ||
| cmd.MarkFlagFilename("file", "yaml", "yml", "json") | ||
| 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().StringSliceVarP(&config.TemplateParameters, "param", "p", config.TemplateParameters, "Specify a key value pair (e.g., -p FOO=BAR) to set/override parameter value in the template. Use FOO@path/to/file to load value from file.") |
There was a problem hiding this comment.
"to load the value from a file"
| cmd.Flags().StringP("filename", "f", "", "Filename or URL to file to read a template") | ||
| cmd.MarkFlagFilename("filename", "yaml", "yml", "json") | ||
| cmd.Flags().StringSliceP("value", "v", nil, "Specify a list of key-value pairs (eg. -v FOO=BAR,BAR=FOO) to set/override parameter values") | ||
| cmd.Flags().StringSliceP("value", "v", nil, "Specify a key-value pair (eg. -v FOO=BAR) to set/override parameter value in the template. Use FOO@path/to/file to load value from file.") |
| # values can be read from files | ||
| os::cmd::expect_success "oc process -f '${required_params}' required_param@${OS_ROOT}/test/testdata/template-value-file.txt" | ||
| # values can be read from files using --value | ||
| os::cmd::expect_success "oc process -f '${required_params}' --value=required_param@${OS_ROOT}/test/testdata/template-value-file.txt" |
There was a problem hiding this comment.
both of these tests should confirm that the value from the file is reflected in the output (demonstrating that the value was actually read and used)
4d3849b to
5736d5c
Compare
|
Updated. |
| cmd.Flags().StringSliceVarP(&config.TemplateFiles, "file", "f", config.TemplateFiles, "Path to a template file to use for the app.") | ||
| cmd.MarkFlagFilename("file", "yaml", "yml", "json") | ||
| 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().StringSliceVarP(&config.TemplateParameters, "param", "p", config.TemplateParameters, "Specify a key value pair (e.g., -p FOO=BAR) to set/override parameter value in the template. Use FOO@path/to/file to load the value from file.") |
There was a problem hiding this comment.
sigh, sorry i still missed an article. should be "to load the value from a file". my bad. (same below).
|
one final nit and we'll need @openshift/api-review to sign off. |
5736d5c to
9b423c6
Compare
|
Updated. I'll read something about articles in English instead of eating dinner tonight as a punishment. |
|
LGTM @bparees why this need API review? |
|
@mfojtik it's changing the CLI api (adding the @ syntax) |
|
Inventing new CLI syntax, changing existing behavior, and introduction of new forms generally requires API review. |
|
How often will a user use this? What are the use case examples that drive this in a day to day sense? Also, if we add this here, why wouldn't we use this in |
|
@smarterclayton i think the primary use case would be supplying a cert file/value as a parameter value. i'm don't think the syntax/use here applies in an obvious way to create secrets --from-file. it might apply to things like set env. |
|
@bparees i can have configMap in my template and I want to have a value there set to a config file that I will supply during the processing (might be one use-case). |
|
The cert file value thing won't work - JSON is going to eat your cert file On Mon, Sep 26, 2016 at 12:24 PM, Michal Fojtik [email protected]
|
|
Which is a case where you want "foo=$( cat file | base64encode )" On Mon, Sep 26, 2016 at 2:41 PM, Clayton Coleman [email protected]
|
|
(binary cert file, that is). Regular text cert files work with cat and On Mon, Sep 26, 2016 at 2:42 PM, Clayton Coleman [email protected]
|
|
@smarterclayton so are you rejecting this? I think @mfojtik and i have provided our use cases. you can also see the original issue/discussion: #10687 if we're not doing this, we need to investigate the "-v" bug reported in the issue (where it only takes the first line from the cat'd file as the value) and at least fix that (assuming it's within our power to fix it and not a cobra issue) |
|
I'm looking for the additional arguments that prove this is required and On Wed, Sep 28, 2016 at 12:22 PM, Ben Parees [email protected]
|
i think the answer is "probably not". I think we should investigate the -v truncation issue reported in the original issue and if we can address that, maybe we just call this done (with $(cat foo.txt) being our recommendation). However the $(cat file) approach is also broken for any value with a comma in it, until we remove our support for comma separated key/value pairs. Can we just go ahead and do that? |
|
Only following is broken for multiline files: Following form should work: The behaviour is caused by pflag library used by cobra which discards everything after the first newline. It can be fixed/worked around, however there will still be the risk that file containing comma will cause different parsing than intended. |
so my vote is to fix/workaround it, and also to drop support for comma parsing/splitting. but I doubt I can get @smarterclayton on board for the latter. if we can't do that, it seems there is a legitimate need for this feature (to handle values with commas) |
|
I've been looking at fixing this upstream and I think doing that would be doing the upstream a disservice (provided they'd accept it). They are using So I'd also vote for dropping the comma splitting altogether, however as it's probably not possible due to backwards compatibility I'll look into working this around in our code. What do you think about printing a warning whenever the comma syntax is used? |
|
@mmilata in other cases I think we've dropped comma support but printed a warning when commas appeared in the value, basically warning the user "this didn't do what you might have expected it to do previously". @smarterclayton is that an acceptable way to break compatibility here? @mmilata I didn't follow your point about upstream though, are you saying we can't get rid of the comma splitting w/o making an upstream change? |
|
@bparees, sorry for being unclear, we don't need to touch upstream to get rid of comma splitting, though rebase to version that includes spf13/pflag#89 is likely needed. I was trying to modify upstream to accept multi-line arguments (separated by commas) but no longer think it's a good idea. |
|
bumping pflag shouldn't be a problem. we'll have to see what @smarterclayton says about dropping support for/warning on comma separated values. |
|
I would say we should drop support and warn it changed if you try it. Also On Oct 11, 2016, at 5:05 AM, Ben Parees [email protected] wrote: bumping pflag shouldn't be a problem. we'll have to see what @smarterclayton — |
|
@smarterclayton what qualifies as public notification? mailing list and release note? |
|
Yes On Oct 11, 2016, at 6:25 PM, Ben Parees [email protected] wrote: @smarterclayton https://github.com/smarterclayton what qualifies as — |
|
Origin Action Required: Pull request cannot be automatically merged, please rebase your branch from latest HEAD and push again |
|
Created PR that drops support for comma-splitting: #11539. |
| os::cmd::expect_failure_and_text 'oc process template-name --value=key=value --value=key=value' 'provided more than once: key' | ||
| os::cmd::expect_failure_and_text 'oc process template-name key=value --value=key=value' 'provided more than once: key' | ||
| os::cmd::expect_failure_and_text 'oc process template-name key=value other=foo --value=key=value --value=other=baz' 'provided more than once: key, other' | ||
| os::cmd::expect_failure_and_text 'oc process template-name key=value other=foo --value=key=value --value=other=baz' 'provided more than once: key=value, other=foo' |
There was a problem hiding this comment.
Not sure the change in the error message makes sense here -- the keys are provided more than once
| @@ -0,0 +1 @@ | |||
| fileval No newline at end of file | |||
There was a problem hiding this comment.
If the purpose of this PR is to support multi-line argument values, shouldn't we test that?
|
Based on previous discussion it seems that this change is not desirable -> closing the PR, apologies for not doing it sooner. |
Fixes #10687.
Normal way of setting template parameters by passing the value on the command line:
To load the parameter value from file.txt instead: