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

Adding --set-string flag to force string values. #3599

Merged
merged 1 commit into from Mar 20, 2018

Conversation

arturo-c
Copy link

@arturo-c arturo-c commented Mar 2, 2018

This addresses the problem of not being able to pass a long int value via the --set flag, and helm converting it to float64 scientific notation, one can then manipulate the string as needed inside the helm templates:

Example usage:
helm install --set long_string_value=1234567890 results in value once in helm template of: 1.23456789e+09

with new flag:
helm install --set-string long_string_value=1234567890 -> value = "1234567890"

Addresses these github issues:
#1707
#1694
#3155
#3001
#3246

This is my first dive at go, so please be gentle if I'm doing something completely wrong :)

@k8s-ci-robot
Copy link

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Mar 2, 2018
@arturo-c arturo-c force-pushed the master branch 2 times, most recently from d6165af to 6bd587c Compare March 9, 2018 15:04
@thomastaylor312 thomastaylor312 self-requested a review March 10, 2018 00:24
@thomastaylor312
Copy link
Contributor

@arturo-c Thanks for the contribution! I will take a look at this on Monday. If for some reason I don't get around to it, feel free to ping me. Sorry for the delay on this

Copy link
Contributor

@thomastaylor312 thomastaylor312 left a comment

Choose a reason for hiding this comment

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

One change to make sure we don't break publicly exposed APIs, otherwise this looks pretty straightforward and you added unit tests 🎉

@@ -54,9 +54,9 @@ func Parse(s string) (map[string]interface{}, error) {
//
// If the strval string has a key that exists in dest, it overwrites the
// dest version.
func ParseInto(s string, dest map[string]interface{}) error {
func ParseInto(s string, dest map[string]interface{}, stringBoolean bool) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it may be clearer and won't break the current API if you add a new method called ParseIntoString. The other private methods can still use a bool, but for someone consuming this package, they won't need to change how they are calling the methods. There might even be a better idea from one of the other maintainers as well. ParseIntoString seems pretty simple though

@arturo-c
Copy link
Author

@thomastaylor312 thanks for the input, I had to add two public methods Parse and ParseIntoString, definitely will keep in mind not changing publicly exposed methods next time 👍

Copy link
Contributor

@thomastaylor312 thomastaylor312 left a comment

Choose a reason for hiding this comment

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

Sorry, one more thing I missed in initial review that I caught during some testing. After that, this should be good to go with one more review

@@ -96,6 +97,7 @@ func newTemplateCmd(out io.Writer) *cobra.Command {
f.VarP(&t.valueFiles, "values", "f", "specify values in a YAML file (can specify multiple)")
f.StringVar(&t.namespace, "namespace", "", "namespace to install the release into")
f.StringArrayVar(&t.values, "set", []string{}, "set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)")
f.StringArrayVar(&t.values, "set-string", []string{}, "set STRING values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)")
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like a copy/paste error. This should be t.stringValues.

Copy link
Author

Choose a reason for hiding this comment

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

Nice catch, updated 👍

@thomastaylor312
Copy link
Contributor

@arturo-c It looks like this should be rebased against master because it is overwriting changes on helm/master

@thomastaylor312 thomastaylor312 added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 14, 2018
@arturo-c arturo-c force-pushed the master branch 2 times, most recently from 769d05e to 18e27d2 Compare March 14, 2018 22:33
@arturo-c
Copy link
Author

@thomastaylor312 cool, not sure what happened there, but fixed the commit.

@thomastaylor312 thomastaylor312 removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 15, 2018
@thomastaylor312
Copy link
Contributor

@arturo-c So because this is labeled as a large, it will need 2 reviews before merge. We have the dev call tomorrow, so I will make sure someone reviews it. Great work on this!

Copy link
Member

@bacongobbler bacongobbler left a comment

Choose a reason for hiding this comment

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

this looks like a good approach. Thanks!

@babatundebusari
Copy link

babatundebusari commented Apr 20, 2018

@arturo-c
here is what i have when i have --set-string for my helm install command

Error: unknown flag: --set-string

not yet released i guess?

@bacongobbler
Copy link
Member

you can test it with either the canary releases or v2.9.0-rc4 :)

@OndraZizka
Copy link

While I consider this a workaround for the bug #1707 , it will be useful until the fix for it is released.

However. Will this be also applied to helm lint? See #4098

@OndraZizka
Copy link

OndraZizka commented May 21, 2018

Btw when is this supposed to be released? I checked with 2.9.1 and gett this:

+ helm install --replace --name h2dc6 --wait --timeout 600 ./... --set-string image.tag=2dc667a5
Error: unknown flag: --set-string

@ashahba
Copy link

ashahba commented May 24, 2018

@babatundebusari and @OndraZizka What is your: helm version output.
If you don't get:

$ helm version
Client: &version.Version{SemVer:"v2.9.0", GitCommit:"f6025bb9ee7daf9fee0026541c90a6f557a3e0bc", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.9.0", GitCommit:"f6025bb9ee7daf9fee0026541c90a6f557a3e0bc", GitTreeState:"clean"}

Then I recommend first updating your client version to v2.9.0 and then run helm init --upgrade so both client and server run matching versions.
Finally you can use --set-string option.

@OndraZizka
Copy link

I think both server and client were 2.9.1 in my case.

@OndraZizka
Copy link

OndraZizka commented Aug 14, 2018

Anyway - does the introduction of --set-string mean that --set sets other type? What type? Is it a generic number? Or can we expect more surprises, like, "516F" will be converted to Celsius? Wouldn't it be wiser to just have --set set a string?

kujenga added a commit to kujenga/helm-diff that referenced this pull request Aug 21, 2018
This resolves an issue where numeric values intended to be
used as strings could be interpreted as float64 values,
causing varius things to fail in unexpected ways.

This fix mirrors the changes in the following PR to Helm
itself: helm/helm#3599

Closes databus23#83
mgar added a commit to mgar/drone-helm that referenced this pull request Sep 3, 2018
rdgoite pushed a commit to HumanCellAtlas/ingest-kube-deployment that referenced this pull request Oct 17, 2018
splisson pushed a commit to splisson/helm that referenced this pull request Dec 6, 2018
Adding --set-string flag to force string values.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. feature in progress size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants