Skip to content

Commit 906d227

Browse files
authored
Merge pull request #508 from brendandburns/patch
Add some constants and an example of patching resources.
2 parents 182b886 + 592ea49 commit 906d227

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

examples/patch-example.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const k8s = require('@kubernetes/client-node');
2+
3+
const kc = new k8s.KubeConfig();
4+
kc.loadFromDefault();
5+
6+
const k8sApi = kc.makeApiClient(k8s.CoreV1Api);
7+
8+
k8sApi.listNamespacedPod('default')
9+
.then((res) => {
10+
const patch = [
11+
{
12+
"op": "replace",
13+
"path":"/metadata/labels",
14+
"value": {
15+
"foo": "bar"
16+
}
17+
}
18+
];
19+
const options = { "headers": { "Content-type": k8s.PatchUtils.PATCH_FORMAT_JSON_PATCH}};
20+
k8sApi.patchNamespacedPod(res.body.items[0].metadata.name, 'default', patch, undefined, undefined, undefined, undefined, options)
21+
.then(() => { console.log("Patched.")})
22+
.catch((err) => { console.log("Error: "); console.log(err)});
23+
});

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ export * from './informer';
1212
export * from './top';
1313
export * from './object';
1414
export * from './cp';
15+
export * from './patch';

src/patch.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export class PatchUtils {
2+
public static PATCH_FORMAT_JSON_PATCH = 'application/json-patch+json';
3+
public static PATCH_FORMAT_JSON_MERGE_PATCH = 'application/merge-patch+json';
4+
public static PATCH_FORMAT_STRATEGIC_MERGE_PATCH = 'application/strategic-merge-patch+json';
5+
public static PATCH_FORMAT_APPLY_YAML = 'application/apply-patch+yaml';
6+
}

0 commit comments

Comments
 (0)