diff --git a/examples/patch-example.js b/examples/patch-example.js new file mode 100644 index 00000000000..d5c0504b11f --- /dev/null +++ b/examples/patch-example.js @@ -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)}); + }); diff --git a/src/index.ts b/src/index.ts index edcc760d677..d470ac8fd68 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,3 +12,4 @@ export * from './informer'; export * from './top'; export * from './object'; export * from './cp'; +export * from './patch'; diff --git a/src/patch.ts b/src/patch.ts new file mode 100644 index 00000000000..9a5a4d49fcf --- /dev/null +++ b/src/patch.ts @@ -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'; +}