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 typed parameter values #1376

Merged
merged 26 commits into from
Mar 6, 2020
Merged

Support typed parameter values #1376

merged 26 commits into from
Mar 6, 2020

Conversation

nfnt
Copy link
Member

@nfnt nfnt commented Mar 2, 2020

What this PR does / why we need it:
This introduces the 'string', 'array', and 'map' types for parameter values. By default, the 'string' type is used. This type is used for a simple value. The types 'array' and 'map' can be used to describe lists and dictonaries. Their values are input using YAML.

Fixes #1349

This introduces the 'string', 'list', and 'dict' types for parameter values. By default, the 'string' type is used. This type is used for a simple value. The types 'list' and 'dict' can be used to describe lists and dictonaries. Their values are input using YAML.

Signed-off-by: Jan Schlicht <jan@d2iq.com>
@nfnt nfnt added the kep/24 Map and array parameter types label Mar 2, 2020
@nfnt nfnt self-assigned this Mar 2, 2020
Jan Schlicht added 2 commits March 2, 2020 14:25
Signed-off-by: Jan Schlicht <jan@d2iq.com>
Signed-off-by: Jan Schlicht <jan@d2iq.com>
@nfnt
Copy link
Member Author

nfnt commented Mar 2, 2020

I don't really know what parse-param-operator-in-operator is actually testing, but it looks like my refactoring of paramsMap fixed a bug. This bug caused this test to pass, even though it shouldn't. I'm fixing the test.

Signed-off-by: Jan Schlicht <jan@d2iq.com>
@nfnt nfnt marked this pull request as ready for review March 2, 2020 15:08
@nfnt nfnt requested review from ANeumann82 and porridge March 2, 2020 15:09
@nfnt nfnt added the release/highlight This PR is a highlight for the next release label Mar 2, 2020
Copy link
Member

@kensipe kensipe left a comment

Choose a reason for hiding this comment

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

nice work so far... some nits

I strongly encourage that we move functions that are not "kudo" features out of kudo package. (I realize there is some examples that deviate)

Also... I'm assuming that maps and lists (our new types) are restricted to values which are strings. It should be great to have the documented... but also tests that show incorrect cases failing... such as a map of lists or a map of maps.

pkg/util/kudo/convert_types.go Outdated Show resolved Hide resolved
pkg/util/kudo/convert_types.go Outdated Show resolved Hide resolved

stringVal, ok := val.(string)
if !ok {
return task, fmt.Errorf("value of parameter %s isn't a string", tt.Parameter)
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't there be an error on the use of a toggle param that is NOT a string... which is technically a bool ?
It seems like we are missing that..

Copy link
Member

Choose a reason for hiding this comment

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

Isn't this what this check does? We try to cast to a string, if it's !ok we error out?

Copy link
Member Author

Choose a reason for hiding this comment

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

Isn't that done by the line below? If stringVal is neither "true" nor "false", strconv.ParseBool will return an error.

Copy link
Contributor

Choose a reason for hiding this comment

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

The error message is somewhat confusing, we expect a string/boolean there. Maybe smth. like:

Suggested change
return task, fmt.Errorf("value of parameter %s isn't a string", tt.Parameter)
return task, fmt.Errorf("value of parameter %s must be either 'true' or 'false'", tt.Parameter)

wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

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

I disagree, because this is checked in the line below when parsing the string to bool. This line is checking that typeof(interface) == string, not the content of the string.

Copy link
Contributor

Choose a reason for hiding this comment

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

If it's not a string it can't be true or false which is what we expect.

Copy link
Member Author

@nfnt nfnt Mar 6, 2020

Choose a reason for hiding this comment

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

Booleans can also be represented by a boolean or integer type. Also strconv.ParseBool accepts 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False.
At this point it's only clear whether the input is a string or not, the content of the input isn't known yet.

pkg/controller/instance/instance_controller.go Outdated Show resolved Hide resolved
pkg/apis/kudo/v1beta1/operatorversion_types.go Outdated Show resolved Hide resolved
pkg/apis/kudo/v1beta1/operatorversion_types.go Outdated Show resolved Hide resolved
pkg/controller/instance/instance_controller.go Outdated Show resolved Hide resolved
pkg/apis/kudo/v1beta1/operatorversion_types.go Outdated Show resolved Hide resolved
pkg/apis/kudo/v1beta1/operatorversion_types.go Outdated Show resolved Hide resolved
pkg/controller/instance/instance_controller.go Outdated Show resolved Hide resolved
Jan Schlicht added 5 commits March 3, 2020 13:04
* Moves type conversion functions to `convert` package
* Renames parameter types
* Different value type switch

Signed-off-by: Jan Schlicht <jan@d2iq.com>
Signed-off-by: Jan Schlicht <jan@d2iq.com>
Signed-off-by: Jan Schlicht <jan@d2iq.com>
Signed-off-by: Jan Schlicht <jan@d2iq.com>
Signed-off-by: Jan Schlicht <jan@d2iq.com>
Jan Schlicht added 5 commits March 4, 2020 09:53
Signed-off-by: Jan Schlicht <jan@d2iq.com>
Signed-off-by: Jan Schlicht <jan@d2iq.com>
Signed-off-by: Jan Schlicht <jan@d2iq.com>
Signed-off-by: Jan Schlicht <jan@d2iq.com>
Copy link
Member

@ANeumann82 ANeumann82 left a comment

Choose a reason for hiding this comment

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

Nice work! Some naming requests, and the integration test could be improved, but this is getting close!

pkg/util/convert/convert.go Outdated Show resolved Hide resolved
pkg/util/convert/convert.go Outdated Show resolved Hide resolved
Jan Schlicht added 2 commits March 4, 2020 16:02
Signed-off-by: Jan Schlicht <jan@d2iq.com>
Signed-off-by: Jan Schlicht <jan@d2iq.com>
Signed-off-by: Jan Schlicht <jan@d2iq.com>
Copy link
Member

@kensipe kensipe left a comment

Choose a reason for hiding this comment

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

man I love the single document params approach so much better!

A few minor nits... the only real blocker for me is around ToYAMLMap and ToYAMLArray

nice work!

pkg/apis/kudo/v1beta1/instance_types_helpers.go Outdated Show resolved Hide resolved
pkg/util/convert/convert.go Outdated Show resolved Hide resolved
pkg/util/convert/convert.go Outdated Show resolved Hide resolved
pkg/util/convert/convert.go Outdated Show resolved Hide resolved
pkg/util/convert/convert.go Outdated Show resolved Hide resolved
pkg/util/convert/convert.go Show resolved Hide resolved
pkg/util/convert/convert.go Outdated Show resolved Hide resolved
Jan Schlicht added 3 commits March 5, 2020 10:35
Signed-off-by: Jan Schlicht <jan@d2iq.com>
Signed-off-by: Jan Schlicht <jan@d2iq.com>
Signed-off-by: Jan Schlicht <jan@d2iq.com>
Copy link
Member

@kensipe kensipe left a comment

Choose a reason for hiding this comment

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

a couple of comments or nits... nothing blocking. nice work 👏

pkg/util/convert/convert.go Outdated Show resolved Hide resolved
pkg/kudoctl/packages/types.go Outdated Show resolved Hide resolved
Jan Schlicht and others added 2 commits March 5, 2020 15:38
Signed-off-by: Jan Schlicht <jan@d2iq.com>

Co-Authored-By: Ken Sipe <kensipe@gmail.com>
Signed-off-by: Jan Schlicht <jan@d2iq.com>
@kensipe kensipe dismissed porridge’s stale review March 5, 2020 19:08

The change request has been handled... feel free to reject again if appropriate

pkg/kudoctl/packages/types.go Show resolved Hide resolved
pkg/kudoctl/packages/types.go Outdated Show resolved Hide resolved
pkg/kudoctl/packages/types.go Outdated Show resolved Hide resolved
pkg/kudoctl/packages/verifier/template/verify_render.go Outdated Show resolved Hide resolved
pkg/util/convert/convert.go Show resolved Hide resolved
pkg/util/convert/convert_test.go Show resolved Hide resolved
Jan Schlicht added 2 commits March 6, 2020 12:15
Signed-off-by: Jan Schlicht <jan@d2iq.com>
Signed-off-by: Jan Schlicht <jan@d2iq.com>
@nfnt nfnt requested a review from porridge March 6, 2020 14:12
@nfnt nfnt merged commit 51bf78c into master Mar 6, 2020
@nfnt nfnt deleted the nfnt/typed-params branch March 6, 2020 14:44
runyontr pushed a commit that referenced this pull request Mar 11, 2020
This introduces the 'string', 'array', and 'masp' types for parameter values. By default, the 'string' type is used. This type is used for a simple value. The types 'array' and 'map' can be used to describe lists and dictionaries. Their values are input using YAML.

Co-Authored-By: Ken Sipe <kensipe@gmail.com>
Signed-off-by: Jan Schlicht <jan@d2iq.com>
Signed-off-by: Thomas Runyon <runyontr@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kep/24 Map and array parameter types release/highlight This PR is a highlight for the next release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide a template function to create dictionaries from YAML values
5 participants