Bug 1304251 - "--overwrite=false" does not work for `oc env`
"--overwrite=false" does not work for `oc env`
Status: CLOSED CURRENTRELEASE
Product: OpenShift Origin
Classification: Red Hat
Component: Command Line Interface (Show other bugs)
3.x
Unspecified Unspecified
medium Severity medium
: ---
: ---
Assigned To: Fabiano Franz
Xingxing Xia
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2016-02-03 01:58 EST by Xingxing Xia
Modified: 2016-09-19 09:50 EDT (History)
4 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2016-09-19 09:50:31 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Xingxing Xia 2016-02-03 01:58:42 EST
Description of problem:
`oc env -h` shows "--overwrite=true: If true, allow environment to be overwritten, otherwise reject updates that overwrite existing environment". But "--overwrite=false" does not work in fact.

Version-Release number of selected component (if applicable):
oc v1.1.1-361-g6408278
kubernetes v1.2.0-alpha.4-851-g4a65fa1

How reproducible:
Always

Steps to Reproduce:
1. oc login, create a project
2. Create a rc
$ oc run hello-rc --image=openshift/hello-openshift --generator=run-controller/v1

3. Set an env variable into rc pod template
1> $ oc env rc/hello-rc -e MY_ENV=VALUE
replicationcontroller "hello-rc" updated
2> $ oc env rc/hello-rc --list
# replicationcontrollers hello-rc, container hello-rc
MY_ENV=VALUE

4. Use "--overwrite=false" when using "oc env -e"
1> $ oc env rc/hello-rc -e MY_ENV=VALUE-2 --overwrite=false
replicationcontroller "hello-rc" updated
2> $ oc env rc/hello-rc --list
# replicationcontrollers hello-rc, container hello-rc
MY_ENV=VALUE-2

5. Use "--overwrite=false" when not using "-e" flag
1> $ oc env rc/hello-rc MY_ENV=VALUE-3 --overwrite=false
replicationcontroller "hello-rc" updated
2> $ oc env rc/hello-rc --list
# replicationcontrollers hello-rc, container hello-rc
MY_ENV=VALUE-3

Actual results:
In steps 4 and 5, "--overwrite=false" does not work

Expected results:
In steps 4 and 5, "--overwrite=false" should reject updates that overwrite existing environment

Additional info:
Comment 1 Fabiano Franz 2016-06-23 13:09:07 EDT
Fixed in https://github.com/openshift/origin/pull/9495
Comment 2 Xingxing Xia 2016-06-24 05:51:53 EDT
Tested with:
oc v1.3.0-alpha.2-194-g82718a8
kubernetes v1.3.0-alpha.3-599-g2746284

The problem is fixed. --overwrite=false takes effect now. The results of step 4.1 and 5.1 give message:
error: replicationcontrollers/hello-rc 'MY_ENV' already has a value (VALUE), and --overwrite is false
error: no environment variable has been set

But when used for multiple resources, in which some resource already has defined the var but some other resource does not yet defined that var, it will do additional PATCH on the former resource:
# Prepare steps
oc run hello-rc --image=openshift/hello-openshift --generator=run-controller/v1
oc run world-rc --image=openshift/hello-openshift --generator=run-controller/v1
oc set env rc/hello-rc -e MY_ENV=VALUE
oc set env rc hello-rc world-rc --list
# replicationcontrollers hello-rc, container hello-rc
MY_ENV=VALUE
# replicationcontrollers world-rc, container world-rc

# Now check the issue
oc set env rc hello-rc world-rc -e MY_ENV=newvalue --overwrite=false
error: replicationcontrollers/hello-rc 'MY_ENV' already has a value (VALUE), and --overwrite is false
replicationcontroller "hello-rc" updated   <-- ** Note this message (the additional PATCH does not take effect, though)
replicationcontroller "world-rc" updated

# see with --loglevel
oc set env rc hello-rc world-rc -e MY_ENV=newvalue --overwrite=false --loglevel 6
... GET https://<master>:8443/api/v1/namespaces/xxia-proj/replicationcontrollers/world-rc 200 OK in 258 milliseconds
error: replicationcontrollers/hello-rc 'MY_ENV' already has a value (VALUE), and --overwrite is false
... PATCH https://<master>:8443/api/v1/namespaces/xxia-proj/replicationcontrollers/hello-rc 200 OK in 256 milliseconds
replicationcontroller "hello-rc" updated
...

# for single resource, does not do the additional PATCH
oc set env rc hello-rc -e MY_ENV=newvalue --overwrite=false --loglevel 6
... GET https://<master>:8443/api/v1/namespaces/xxia-proj/replicationcontrollers/hello-rc 200 OK in 255 milliseconds
error: replicationcontrollers/hello-rc 'MY_ENV' already has a value (VALUE), and --overwrite is false
F0624 17:33:21.523285   18414 helpers.go:107] error: no environment variable has been set

^ ** No additional PATCH after error message

So need fix the issue? If necessary, could use a new bug to track it.
Comment 3 Fabiano Franz 2016-06-24 13:36:31 EDT
Fixed in https://github.com/openshift/origin/pull/9552, we also removed the "no environment variable has been set" message.
Comment 4 Xingxing Xia 2016-06-26 23:14:59 EDT
Thanks! Checked the issue in comment 2 is fixed in oc v1.3.0-alpha.2-250-g61eba05

Note You need to log in before you can comment on or make changes to this bug.