forked from kubernetes-client/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch-example.js
More file actions
30 lines (25 loc) · 732 Bytes
/
patch-example.js
File metadata and controls
30 lines (25 loc) · 732 Bytes
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
import * as k8s from '@kubernetes/client-node';
const kc = new k8s.KubeConfig();
kc.loadFromDefault();
const k8sApi = kc.makeApiClient(k8s.CoreV1Api);
const namespace = 'default';
try {
const res = await k8sApi.listNamespacedPod({ namespace });
const patch = [
{
op: 'replace',
path: '/metadata/labels',
value: {
foo: 'bar',
},
},
];
await k8sApi.patchNamespacedPod(
{ name: res?.items?.[0]?.metadata?.name ?? '', namespace, body: patch },
k8s.setHeaderOptions('Content-Type', k8s.PatchStrategy.JsonPatch),
);
console.log('Patched.');
} catch (err) {
console.error('Error: ');
console.error(err);
}