Bug 1304251

Summary: "--overwrite=false" does not work for `oc env`
Product: OKD Reporter: Xingxing Xia <xxia>
Component: ocAssignee: Fabiano Franz <ffranz>
Status: CLOSED CURRENTRELEASE QA Contact: Xingxing Xia <xxia>
Severity: medium Docs Contact:
Priority: medium    
Version: 3.xCC: aos-bugs, ffranz, mmccomas, wewang
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-09-19 13:50:31 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Xingxing Xia 2016-02-03 06:58:42 UTC
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 17:09:07 UTC
Fixed in https://github.com/openshift/origin/pull/9495

Comment 2 Xingxing Xia 2016-06-24 09:51:53 UTC
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 17:36:31 UTC
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-27 03:14:59 UTC
Thanks! Checked the issue in comment 2 is fixed in oc v1.3.0-alpha.2-250-g61eba05