doc-exports/docs/cce/api-ref/cce_02_0086.html
Dong, Qiu Jian 3336ba8df7 CCE API for v1.23
Reviewed-by: gtema <artem.goncharov@gmail.com>
Co-authored-by: Dong, Qiu Jian <qiujiandong1@huawei.com>
Co-committed-by: Dong, Qiu Jian <qiujiandong1@huawei.com>
2022-11-10 12:48:59 +00:00

252 lines
9.5 KiB
HTML

<a name="cce_02_0086"></a><a name="cce_02_0086"></a>
<h1 class="topictitle1">Patch Request Method Operation Example</h1>
<div id="body1498621882382"><p id="cce_02_0086__p3027878218146">This section provides examples of <span class="parmname" id="cce_02_0086__parmname11751077153812"><b>Merge Patch</b></span> and <span class="parmname" id="cce_02_0086__parmname48547041153817"><b>Strategic Merge Patch</b></span> method operations.</p>
<div class="section" id="cce_02_0086__section34671706181610"><h4 class="sectiontitle">Operation Example</h4><p id="cce_02_0086__p19773278181621">By way of example, <span class="parmname" id="cce_02_0086__parmname14049641155250"><b>Merge Patch</b></span> and <span class="parmname" id="cce_02_0086__parmname20715914155250"><b>Strategic Merge Patch</b></span> method operations are performed at the time of creating a ReplicationController resource object.</p>
</div>
<p id="cce_02_0086__p21990042153356"><strong id="cce_02_0086__b18021257153943">Sample request</strong></p>
<pre class="screen" id="cce_02_0086__screen7077281153415">{
"apiVersion": "v1",
"kind": "ReplicationController",
"metadata": {
"name": "frontend-controller"
},
"spec": {
"replicas": 2,
"selector": {
"app": "nginx"
},
"template": {
"metadata": {
"labels": {
"app": "nginx"
}
},
"spec": {
"containers": [
{
"name": "redis",
"image": "redis:latest",
"ports": [
{
"containerPort": 80
}
]
}
]
}
}
}
}</pre>
<p id="cce_02_0086__p44122606153356"><strong id="cce_02_0086__b6501985154257">Sample response</strong></p>
<pre class="screen" id="cce_02_0086__screen52775737153434">{
"kind": "ReplicationController",
"apiVersion": "v1",
"metadata": {
"name": "frontend-controller",
"namespace": "default",
"selfLink": "/api/v1/namespaces/default/replicationcontrollers/nginx-controller",
"uid": "549b2234-5d46-11e6-aeb9-286ed488fafe",
"resourceVersion": "4110",
"generation": 1,
"creationTimestamp": "2016-08-08T08:58:52Z",
"labels": {
"app": "nginx"
}
},
"spec": {
"replicas": 2,
"selector": {
"app": "nginx"
},
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"app": "nginx"
}
},
"spec": {
"containers": [
{
"name": "redis",
"image": "redis:latest",
"ports": [
{
"containerPort": 80,
"protocol": "TCP"
}
],
"resources": {},
"terminationMessagePath": "/dev/termination-log",
"imagePullPolicy": "Always"
}
],
"restartPolicy": "Always",
"terminationGracePeriodSeconds": 30,
"dnsPolicy": "ClusterFirst",
"securityContext": {}
}
}
},
"status": {
"replicas": 0
}
}</pre>
<ul id="cce_02_0086__ul64354836183113"><li id="cce_02_0086__li59802418183113">If you use <span class="parmname" id="cce_02_0086__parmname60465773155414"><b>Merge Patch</b></span> to add a container to the <span class="parmname" id="cce_02_0086__parmname1624745415563"><b>template</b></span> field of a specified ReplicationController, the list of existing containers is then replaced by the newly added container.<p id="cce_02_0086__p13357521153356"><strong id="cce_02_0086__b57139887155348">Merge Patch request</strong></p>
<pre class="screen" id="cce_02_0086__screen19911977153441">{
"spec": {
"template": {
"spec": {
"containers": [
{
"name": "hello-world",
"image": "busybox:latest"
}
]
}
}
}
}</pre>
<p id="cce_02_0086__p2392383153356"><strong id="cce_02_0086__b48478444155811">Merge Patch response</strong></p>
<pre class="screen" id="cce_02_0086__screen11961975153454">{
"kind": "ReplicationController",
"apiVersion": "v1",
"metadata": {
"name": "frontend-controller",
"namespace": "default",
"selfLink": "/api/v1/namespaces/default/replicationcontrollers/nginx-controller",
"uid": "549b2234-5d46-11e6-aeb9-286ed488fafe",
"resourceVersion": "4159",
"generation": 2,
"creationTimestamp": "2016-08-08T08:58:52Z",
"labels": {
"app": "nginx"
}
},
"spec": {
"replicas": 2,
"selector": {
"app": "nginx"
},
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"app": "nginx"
}
},
"spec": {
"containers": [
{
"name": "hello-world",
"image": "busybox:latest",
"resources": {},
"terminationMessagePath": "/dev/termination-log",
"imagePullPolicy": "Always"
}
],
"restartPolicy": "Always",
"terminationGracePeriodSeconds": 30,
"dnsPolicy": "ClusterFirst",
"securityContext": {}
}
}
},
"status": {
"replicas": 2,
"fullyLabeledReplicas": 2,
"observedGeneration": 1
}
}</pre>
<p id="cce_02_0086__p21848696153356">The <span class="parmname" id="cce_02_0086__parmname4569168815591"><b>containers</b></span> are replaced by the newly added container.</p>
</li></ul>
<ul id="cce_02_0086__ul25131212183119"><li id="cce_02_0086__li33085774183119">If you use <span class="parmname" id="cce_02_0086__parmname5304212716115"><b>Strategic Merge Patch</b></span> to add metadata to a resource object, the new metadata then determines which list should b merged and which should not.<p id="cce_02_0086__p24913912153356"><strong id="cce_02_0086__b4594288016155">Strategic Merge Patch request</strong></p>
<pre class="screen" id="cce_02_0086__screen4384100815352">{
"spec": {
"template": {
"spec": {
"containers": [
{
"name": "hello-world",
"image": "busybox:latest"
}
]
}
}
}
}'</pre>
<p id="cce_02_0086__p3400630153356"><strong id="cce_02_0086__b2227000816159">Strategic Merge Patch response</strong></p>
<pre class="screen" id="cce_02_0086__screen58475964153512">{
"kind": "ReplicationController",
"apiVersion": "v1",
"metadata": {
"name": "frontend-controller",
"namespace": "default",
"selfLink": "/api/v1/namespaces/default/replicationcontrollers/nginx-controller",
"uid": "f2e048bb-5d46-11e6-aeb9-286ed488fafe",
"resourceVersion": "4250",
"generation": 2,
"creationTimestamp": "2016-08-08T09:03:18Z",
"labels": {
"app": "nginx"
}
},
"spec": {
"replicas": 2,
"selector": {
"app": "nginx"
},
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"app": "nginx"
}
},
"spec": {
"containers": [
{
"name": "redis",
"image": "redis:latest",
"ports": [
{
"containerPort": 80,
"protocol": "TCP"
}
],
"resources": {},
"terminationMessagePath": "/dev/termination-log",
"imagePullPolicy": "Always"
},
{
"name": "hello-world",
"image": "busybox:latest",
"resources": {},
"terminationMessagePath": "/dev/termination-log",
"imagePullPolicy": "Always"
}
],
"restartPolicy": "Always",
"terminationGracePeriodSeconds": 30,
"dnsPolicy": "ClusterFirst",
"securityContext": {}
}
}
},
"status": {
"replicas": 2,
"fullyLabeledReplicas": 2,
"observedGeneration": 1
}
}</pre>
<p id="cce_02_0086__p7742537153356">The <span class="parmname" id="cce_02_0086__parmname1911332416210"><b>containers</b></span> merge with the new content according to the value of the <span class="parmname" id="cce_02_0086__parmname175812616249"><b>name</b></span> field.</p>
</li></ul>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="cce_02_0083.html">Appendix</a></div>
</div>
</div>