Bug 1372653

Summary: oc scale/patch with record True does not add the change-cause annotation
Product: OpenShift Container Platform Reporter: XiaochuanWang <xiaocwan>
Component: openshift-controller-managerAssignee: Michal Fojtik <mfojtik>
Status: CLOSED EOL QA Contact: zhou ying <yinzhou>
Severity: low Docs Contact:
Priority: low    
Version: unspecifiedCC: aos-bugs, mfojtik, mmccomas, pweil
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-08-23 12:49:05 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:

Description XiaochuanWang 2016-09-02 09:49:51 UTC
Description of problem:
oc scale dc with --record=true should add annotation in dc for record

Version-Release number of selected component (if applicable):
oc/openshift v1.3.0-alpha.3+d4c5c31

How reproducible:
Always

Steps to Reproduce:
create a new project 
1. oc run ho --image=aosqe/hello-openshift
2. oc get dc/ho -o yaml => there is no annotation
3. oc scale dc/ho --replicas=2 --record=true --loglevel=8

I0902 05:17:48.219597   21954 round_trippers.go:296] PUT https://172.18.13.152:8443/oapi/v1/namespaces/xiaocwan-sca/deploymentconfigs/ho/scale
I0902 05:17:48.219603   21954 round_trippers.go:303] Request Headers:
I0902 05:17:48.219607   21954 round_trippers.go:306]     Accept: application/json, */*
I0902 05:17:48.219611   21954 round_trippers.go:306]     User-Agent: oc/v1.3.0 (linux/amd64) openshift/d4c5c31
I0902 05:17:48.222757   21954 round_trippers.go:321] Response Status: 200 OK in 3 milliseconds
I0902 05:17:48.222770   21954 round_trippers.go:324] Response Headers:
I0902 05:17:48.222775   21954 round_trippers.go:327]     Content-Type: application/json
I0902 05:17:48.222780   21954 round_trippers.go:327]     Date: Fri, 02 Sep 2016 09:17:48 GMT
I0902 05:17:48.222784   21954 round_trippers.go:327]     Content-Length: 385
I0902 05:17:48.222788   21954 round_trippers.go:327]     Cache-Control: no-store
I0902 05:17:48.222825   21954 request.go:901] Response Body: {"kind":"Scale","apiVersion":"extensions/v1beta1","metadata":{"name":"ho","namespace":"xiaocwan-sca","selfLink":"/oapi/v1/namespaces/xiaocwan-sca/deploymentconfigs/ho/scale","uid":"0b44e07b-70ee-11e6-849c-0ed2353df9c1","resourceVersion":"3026","creationTimestamp":"2016-09-02T09:17:17Z"},"spec":{"replicas":2},"status":{"replicas":1,"selector":{"run":"ho"},"targetSelector":"run=ho"}}
I0902 05:17:48.224424   21954 request.go:548] Request Body: {"annotations":{"kubernetes.io/change-cause":"oc scale dc/ho --replicas=2 --record=true --loglevel=8"}}
I0902 05:17:48.224456   21954 round_trippers.go:296] PATCH https://172.18.13.152:8443/oapi/v1/namespaces/xiaocwan-sca/deploymentconfigs/ho
I0902 05:17:48.224462   21954 round_trippers.go:303] Request Headers:
I0902 05:17:48.224466   21954 round_trippers.go:306]     Accept: application/json, */*
I0902 05:17:48.224470   21954 round_trippers.go:306]     Content-Type: application/strategic-merge-patch+json
I0902 05:17:48.224474   21954 round_trippers.go:306]     User-Agent: oc/v1.3.0 (linux/amd64) openshift/d4c5c31
I0902 05:17:48.227280   21954 round_trippers.go:321] Response Status: 200 OK in 2 milliseconds
I0902 05:17:48.227293   21954 round_trippers.go:324] Response Headers:
I0902 05:17:48.227298   21954 round_trippers.go:327]     Cache-Control: no-store
I0902 05:17:48.227302   21954 round_trippers.go:327]     Content-Type: application/json
I0902 05:17:48.227306   21954 round_trippers.go:327]     Date: Fri, 02 Sep 2016 09:17:48 GMT
I0902 05:17:48.227311   21954 round_trippers.go:327]     Content-Length: 1112
I0902 05:17:48.227356   21954 request.go:901] Response Body: {"kind":"DeploymentConfig","apiVersion":"v1","metadata":{"name":"ho","namespace":"xiaocwan-sca","selfLink":"/oapi/v1/namespaces/xiaocwan-sca/deploymentconfigs/ho","uid":"0b44e07b-70ee-11e6-849c-0ed2353df9c1","resourceVersion":"3057","generation":2,"creationTimestamp":"2016-09-02T09:17:17Z","labels":{"run":"ho"}},"spec":{"strategy":{"type":"Rolling","rollingParams":{"updatePeriodSeconds":1,"intervalSeconds":1,"timeoutSeconds":600,"maxUnavailable":"25%","maxSurge":"25%"},"resources":{}},"triggers":[{"type":"ConfigChange"}],"replicas":2,"test":false,"selector":{"run":"ho"},"template":{"metadata":{"creationTimestamp":null,"labels":{"run":"ho"}},"spec":{"containers":[{"name":"ho","image":"aosqe/hello-openshift","resources":{},"terminationMessagePath":"/dev/termination-log","imagePullPolicy":"Always"}],"restartPolicy":"Always","terminationGracePeriodSeconds":30,"dnsPolicy":"ClusterFirst","securityContext":{}}}},"status":{"latestVersion":1,"observedGeneration":1,"replicas":1,"updatedReplicas":1,"availableReplicas":1,"details":{"message":"caused by a config change","causes":[{"type":"ConfigChange"}]}}}
deploymentconfig "ho" scaled

Actual results:
# oc get dc ho -o yaml|grep change-cause 
There is nothing recorded.

Expected results:
# oc get dc ho -o yaml|grep change-cause
kubernetes.io/change-cause: oc patch dc/ho -p {"spec":{"replicas":2}} --record=true

Additional info:
oc scale -h 
--record=false: Record current kubectl command in the resource annotation. If set to false, do not record the command. If set to true, record the command. If not set, default to updating the existing annotation value only if one already exists.

oc patch works for adding the annotation "kubernetes.io/change-cause"

Comment 2 Fabiano Franz 2016-09-02 19:47:02 UTC
Reassigning since the issue seems to be server-side when patching the deployment config. In the request body of the patch request in logs, it looks like the 'metadata' field is missing

{"annotations":{"kubernetes.io/change-cause":"oc scale dc/ho --replicas=2 --record=true --loglevel=8"}}

should be

'{"metadata":{"annotations":{"kubernetes.io/change-cause":"oc scale dc/ho --replicas=2 --record=true --loglevel=10"}}}'

Patching via 'oc patch' or 'curl' with the version with 'metadata' works fine.

Scaling the rc directly in kubectl with --record=true also adds the annotation correctly:

kubectl scale rc ho-1 --replicas=3 --record=true ; kubectl get rc ho-1 -o yaml | grep change-cause

Comment 3 Juan Vallejo 2016-09-02 20:10:15 UTC
Can confirm @ffranz's comment. I tested `oc scale` by adding the following line:

> patchBytes = []byte(fmt.Sprintf("{\"metadata\":%v}", string(patchBytes)))

in this location: https://github.com/openshift/origin/blob/master/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/scale.go#L165

recompiled, and the patch now worked as expected.

Comment 4 XiaochuanWang 2016-09-22 07:44:29 UTC
`oc patch --record=true` lost the record on Origin but not reproduced on OCP:

oc v1.4.0-alpha.0+6e155d0
# oc patch dc/ho -p '{"metadata":{"labels":{"run":"hotrue"}}}' --record=true
# oc get dc -o yaml | grep change-cause
Here is nothing output.

oc v3.3.0.31
# oc get dc -o yaml | grep -A1 change-cause
      kubernetes.io/change-cause: oc patch dc/ho -p {"metadata":{"labels":{"run":"hotrue"}}}
        --record=true

Comment 5 Michal Fojtik 2016-11-02 14:08:22 UTC
Fixed here: https://github.com/openshift/origin/pull/11727