Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions examples/patch-example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const k8s = require('@kubernetes/client-node');

const kc = new k8s.KubeConfig();
kc.loadFromDefault();

const k8sApi = kc.makeApiClient(k8s.CoreV1Api);

k8sApi.listNamespacedPod('default')
.then((res) => {
const patch = [
{
"op": "replace",
"path":"/metadata/labels",
"value": {
"foo": "bar"
}
}
];
const options = { "headers": { "Content-type": k8s.PatchUtils.PATCH_FORMAT_JSON_PATCH}};
k8sApi.patchNamespacedPod(res.body.items[0].metadata.name, 'default', patch, undefined, undefined, undefined, undefined, options)
.then(() => { console.log("Patched.")})
.catch((err) => { console.log("Error: "); console.log(err)});
});
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export * from './informer';
export * from './top';
export * from './object';
export * from './cp';
export * from './patch';
6 changes: 6 additions & 0 deletions src/patch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export class PatchUtils {
public static PATCH_FORMAT_JSON_PATCH = 'application/json-patch+json';
public static PATCH_FORMAT_JSON_MERGE_PATCH = 'application/merge-patch+json';
public static PATCH_FORMAT_STRATEGIC_MERGE_PATCH = 'application/strategic-merge-patch+json';
public static PATCH_FORMAT_APPLY_YAML = 'application/apply-patch+yaml';
}