Skip to content

Commit

Permalink
feat(Send body in DELETE requests): (#142)
Browse files Browse the repository at this point in the history
Some Kubernetes APIs optionally send body with the DELETE request.  E.g., https://kubernetes.io/docs/api-reference/v1.7/#delete-58

Changes in this commit extends `.delete` calls to be similar to `.post` calls:

```js
const K8s = require('kubernetes-client');
const batch = new K8s.Batch({/*add configuration*/});
batch.namespaces('default').jobs.delete({
    name: 'some-job',
    body: {
        kind: 'DeleteOptions',
        apiVersion: 'batch/v1',
        propagationPolicy: 'Foreground'
    }
}, (err, data) => console.log(err, data))
```
  • Loading branch information
anton-kotenko authored and silasbw committed Aug 29, 2017
1 parent b4d3395 commit 10e4018
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class BaseObject extends CallableObject {
} else if (typeof options === 'string') {
options = { name: options };
}
this.api.delete({ path: this._path(options), qs: options.qs },
this.api.delete({ path: this._path(options), qs: options.qs, body: options.body },
cb200(cb));
}

Expand Down
40 changes: 40 additions & 0 deletions test/base.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,46 @@ describe('lib.base', () => {
});
});

describe('.delete', () => {
const podName = 'pod-name';
const query = { pretty: true };
const body = {
apiVersion: 'v1',
kind: 'DeleteOptions',
propagationPolicy: 'Foreground'
};
beforeTesting('unit', () => {
nock(common.api.url)
.delete(`/api/v1/namespaces/${ common.currentName }/pods/${ podName }`, body)
.query(query)
.reply(200, {
kind: 'Pod',
metadata: {
name: podName,
finalizers: ['foregroundDeletion']
},
spec: {

}
});
});
beforeTesting('int', done => {
common.api.ns.po.post({ body: pod(podName) }, done);
});

it('should bypass query string and body from arguments into request', done => {
common.api.ns.po.delete({ name: podName, qs: query, body: body }, (err, result) => {
assume(err).is.falsy();
assume(result.kind).is.eql('Pod');
assume(result.metadata).is.truthy();
assume(result.spec).is.truthy();
assume(result.metadata.name).is.eql(podName);
assume(result.metadata.finalizers).is.eql(['foregroundDeletion']);
done();
});
});
});

describe('.po.matchLabels', () => {
beforeTesting('int', done => {
common.changeName(err => {
Expand Down

0 comments on commit 10e4018

Please sign in to comment.