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

support ${{KEY}} substitution syntax for non-string fields #11068

Closed
wants to merge 1 commit into from

Conversation

bparees
Copy link
Contributor

@bparees bparees commented Sep 23, 2016

fixes #3946

@bparees bparees force-pushed the int_parameter_support branch from 961491c to 2a62d7a Compare September 23, 2016 09:31
@bparees bparees changed the title upport ${{KEY}} substition syntax for non-string fields support ${{KEY}} substition syntax for non-string fields Sep 23, 2016
@bparees
Copy link
Contributor Author

bparees commented Sep 23, 2016

@csrwng @smarterclayton ptal. i'm hoping you don't completely hate this json/regex approach.

@bparees bparees force-pushed the int_parameter_support branch from 2a62d7a to 0b7b013 Compare September 23, 2016 09:33
@bparees bparees changed the title support ${{KEY}} substition syntax for non-string fields support ${{KEY}} substitution syntax for non-string fields Sep 23, 2016
@bparees bparees force-pushed the int_parameter_support branch 2 times, most recently from 139349f to 1493973 Compare September 23, 2016 09:36
@bparees
Copy link
Contributor Author

bparees commented Sep 23, 2016

[test]

@bparees
Copy link
Contributor Author

bparees commented Sep 23, 2016

[testextended][extended:core(images)]

@bparees
Copy link
Contributor Author

bparees commented Sep 23, 2016

[testextended][extended:core(builds)]

@bparees
Copy link
Contributor Author

bparees commented Sep 23, 2016

flake #11016
[test]

return templateErrors, errors.New("Could not load json serializer")
}

templateBytes, err := runtime.Encode(serializer, template)
Copy link
Contributor

@smarterclayton smarterclayton Sep 23, 2016

Choose a reason for hiding this comment

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

We can't use regex over json unfortunately, there are to many ways it can fail. Going to have to transform in place over the unstructured scheme.

Copy link
Contributor

Choose a reason for hiding this comment

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

For instance you can't transform keys correctly (you need to error).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what do you mean i can't transform keys correctly? my logic in this PR was "as a template author you now have the power to substitute anywhere in the json/yaml that you want(including keys), but with that power comes the responsibility that you ensure the result is sane" and if the result isn't sane, we'll get an error transforming it back and report that error to you so you can fix it.

Copy link
Contributor

@csrwng csrwng left a comment

Choose a reason for hiding this comment

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

Just a couple of comments, but will look more closely when you update based on Clayton's comment.

@@ -47,10 +47,15 @@ func (s *REST) Create(ctx kapi.Context, obj runtime.Object) (runtime.Object, err
"expression": generator.NewExpressionValueGenerator(rand.New(rand.NewSource(time.Now().UnixNano()))),
}
processor := template.NewProcessor(generators)
if errs := processor.Process(tpl); len(errs) > 0 {
errs, err := processor.Process(tpl)
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe use different var names to distinguish the types of error you're expecting returned? (templateErrors, err)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}
templateString := string(templateBytes)

// consider we start with a field like "${PARAM1}${{PARAM2}"
Copy link
Contributor

Choose a reason for hiding this comment

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

s/{{PARAM2}/{{PARAM2}}/ ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup, thanks.

@bparees bparees force-pushed the int_parameter_support branch from 1493973 to d84fa21 Compare October 10, 2016 03:22
@openshift-bot
Copy link
Contributor

Evaluated for origin test up to d84fa21

@openshift-bot
Copy link
Contributor

Evaluated for origin testextended up to d84fa21

@bparees
Copy link
Contributor Author

bparees commented Oct 10, 2016

@smarterclayton to do this with unstructured json object seems ugly at best. On deserialization we're going to end up with a collection of map[string]interface{} but in reality the type of every value is going to be a string. Then we do the substitution, but the value will still be a string and when it gets serialized back out, the quotes will be put back in place.

The only way to successfully strip the quotes if is we replace the value object in the struct with a non-string object, but that requires us understanding what type the new value is after substitution, when it could be an int, a string, a float, an unsigned float/int, a boolean, etc.

Furthermore i don't see the downside to supporting parameterization of keys. It's a generic solution for parameterizing template json/yaml. what is the downside other than the argument that it more closely approximates a generic templating language (except that it's still much less powerful)?

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/9791/)

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/testextended FAILURE (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin_extended/562/) (Extended Tests: core(builds), core(images))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot specify integer/bool/base64 types in templates
4 participants