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

Supports setting comma separated env vars #347

Closed
wants to merge 2 commits into from

Conversation

navidshaikh
Copy link
Collaborator

/lint

Proposed Changes

--env ENV1=VAL1 --env ENV2=VAL2,ENV3=VAL3

should work specifying by separate --env or specifying comma separated
values to --env or combination of both.

Release Note

Supports specifying comma separated environment variables as `--env KEY1=VAL1,KEY2=VAL2`

 `--env ENV1=VAL1 --env ENV2=VAL2,ENV3=VAL3`

 should work specifying by separate `--env` or specifying comma separated
 values to `--env` or combination of both.
@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Aug 8, 2019
@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: navidshaikh

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 8, 2019
Copy link
Contributor

@knative-prow-robot knative-prow-robot left a comment

Choose a reason for hiding this comment

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

@navidshaikh: 0 warnings.

In response to this:

/lint

Proposed Changes

--env ENV1=VAL1 --env ENV2=VAL2,ENV3=VAL3

should work specifying by separate --env or specifying comma separated
values to --env or combination of both.

Release Note

Supports specifying comma separated environment variables as `--env KEY1=VAL1,KEY2=VAL2`

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.

@knative-prow-robot knative-prow-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Aug 8, 2019
@rhuss
Copy link
Contributor

rhuss commented Aug 8, 2019

Fine with me, but please note that this might conflict with #342 which also has some minor tweaks on env vars. Maybe we can hold off with this one until #342 is merged ? (its soonish)

@rhuss
Copy link
Contributor

rhuss commented Aug 8, 2019

@navidshaikh don't forget to add to CHANGELOG.adoc, too

@navidshaikh
Copy link
Collaborator Author

this might conflict with #342

@rhuss : I thought about that, separating the values by comma for --env should be handled by cobra and we receive the values in list before we interpret the values as mentioned #342.

Without comma

--env KEY=value sets EnvVar{Name: "KEY", Value: "value"} (current behavior)
--env KEY= sets EnvVar{Name: "KEY"} (current behavior)
--env KEY
--env KEY- removes the env var matching EnvVar{Name: "KEY", ...}

With comma

--env KEY=value,KEY2=value2
--env KEY=,KEY2=
--env KEY,KEY2
--env KEY-,KEY2-

I think this should just work fine without any additional processing.

@duglin
Copy link
Contributor

duglin commented Aug 8, 2019

No strong opinion either way, but do people have a guess as to how often someone may use a comma in an env var? Is there a way to escape it via cobra?

@knative-prow-robot
Copy link
Contributor

knative-prow-robot commented Aug 8, 2019

@navidshaikh: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
pull-knative-client-integration-tests b059f4d link /test pull-knative-client-integration-tests

Full PR test history. Your PR dashboard.

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.

@navidshaikh
Copy link
Collaborator Author

but do people have a guess as to how often someone may use a comma in an env var? Is there a way to escape it via cobra?

Supporting this would disallow users from setting commas in env var values, need to check about escaping but single/double quotes on only values or even whole pair, back/forward slash didnt work.

➜  client git:(pr/multiple-envs)  ./kn service update svc --env TARGET="hello2,"
--env argument requires a value that contains the '=' character; got 

➜  client git:(pr/multiple-envs)  ./kn service update svc --env TARGET='hello2,'
--env argument requires a value that contains the '=' character; got 

➜  client git:(pr/multiple-envs)  ./kn service update svc --env TARGET=hello2\,  
--env argument requires a value that contains the '=' character; got 

➜  client git:(pr/multiple-envs)  ./kn service update svc --env TARGET=hello2/,
--env argument requires a value that contains the '=' character; got 

➜  client git:(pr/multiple-envs)  ./kn service update svc --env "TARGET=hello2,"
--env argument requires a value that contains the '=' character; got 

# the current behavior allows commas
➜  client git:(pr/multiple-envs)  git checkout master                           
➜  client git:(master)  go run ./cmd/kn/main.go service update svc --env TARGET=hello, 
Waiting for service 'svc' to become ready ... OK
Service 'svc' updated in namespace 'default'.

➜  client git:(master)  curl http://svc.default.apps-crc.testing                      
Hello hello,!

The current forma though support it (check last service update command above).

@duglin
Copy link
Contributor

duglin commented Aug 8, 2019

I did some digging and found this:
https://github.com/spf13/pflag/pull/59/files

And this does seem to work:

./kn service update echo --env=\"abc=def,def=qwe\"

So if we document this then I think we're good

@duglin
Copy link
Contributor

duglin commented Aug 8, 2019

We should add a test for it too :-)

@navidshaikh
Copy link
Collaborator Author

@duglin : Nice! I can do this as well

kn service update svc --env \"TARGET=hello,=\",TARGET=overwrite


servinglib.UpdateImage(template, "gcr.io/foo/bar:baz")

action, updated, _, err := fakeServiceUpdate(orig, []string{
Copy link
Contributor

Choose a reason for hiding this comment

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

Add test for quoting (to have a comma in an env var), and for repeating the flag, to make sure we cover all the bases.

@jimcurtis
Copy link

LGTM

@navidshaikh
Copy link
Collaborator Author

repeat --env flag to specify multiple env vars, escaping might create more confusion.

@navidshaikh navidshaikh deleted the pr/multiple-envs branch August 20, 2019 17:47
navidshaikh added a commit to navidshaikh/client that referenced this pull request Apr 23, 2020
images job might run on OCP 3.11 (api.ci) and we'd need to create
 dir before referncing it via WORKDIR. (issue with imagebuilder on OCP 3.11)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cla: yes Indicates the PR's author has signed the CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants