-
Notifications
You must be signed in to change notification settings - Fork 544
/
Copy pathpatch-example.js
41 lines (35 loc) · 1020 Bytes
/
patch-example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const k8s = require('@kubernetes/client-node');
const namespace = 'default';
const kc = new k8s.KubeConfig();
kc.loadFromDefault();
const k8sApi = kc.makeApiClient(k8s.CoreV1Api);
const main = async () => {
try {
const podsRes = await k8sApi.listNamespacedPod(namespace);
const patch = [
{
op: 'replace',
path: '/metadata/labels',
value: {
foo: 'bar',
},
},
];
const options = { headers: { 'Content-type': k8s.PatchUtils.PATCH_FORMAT_JSON_PATCH } };
const podPatchRes = await k8sApi.patchNamespacedPod(
podsRes.body.items[0].metadata.name,
namespace,
patch,
undefined,
undefined,
undefined,
undefined,
undefined,
options,
);
console.log('Pod patched: ', podPatchRes.body);
} catch (err) {
console.error(err);
}
};
main();