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
12 changes: 4 additions & 8 deletions lib/pods.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@ const Client = require('./client-base');

class Pods extends Client {
get({ podName, labelSelector, useNamespace = true } = {}) {
const namespace = useNamespace ? this._namespace : undefined;
return this._client.api.v1
.namespaces(namespace)
.pods(podName)
.get({ qs: { labelSelector } });
const prefix = useNamespace ? this._client.api.v1.namespaces(this._namespace).pods(podName) : this._client.api.v1.pods;
return prefix.get({ qs: { labelSelector } });
}

delete({ podName, useNamespace = true }) {
const namespace = useNamespace ? this._namespace : undefined;
delete({ podName }) {
return this._client.api.v1
.namespaces(namespace)
.namespaces(this._namespace)
.pods(podName)
.delete();
}
Expand Down
4 changes: 2 additions & 2 deletions lib/resourceQuotas.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ const Client = require('./client-base');

class ResourceQuotas extends Client {
async get({ name, labelSelector, useNamespace = true } = {}) {
const namespace = useNamespace ? this._namespace : undefined;
return this._client.api.v1.namespaces(namespace).resourcequotas(name).get({ qs: { labelSelector } });
const prefix = useNamespace ? this._client.api.v1.namespaces(this._namespace).resourcequotas(name) : this._client.api.v1.resourcequotas;
return prefix.get({ qs: { labelSelector } });
}
}

Expand Down
9 changes: 7 additions & 2 deletions tests/mocks/kubernetes-server.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const configmaps = require('../stubs/configmaps.json');

const map = {
'/api/kube/api/v1/namespaces/default/pods/worker': pod,
'/api/kube/api/v1/namespaces/default/configmaps/hkube-versions': configmaps
'/api/kube/api/v1/namespaces/default/configmaps/hkube-versions': configmaps,
'/api/kube/api/v1/namespaces/default/resourcequotas/foo': {body: {name: 'foo'}}
}

class MockClient {
Expand All @@ -18,7 +19,11 @@ class MockClient {
app.use(bodyParser.json());
app.use('/', (req, res) => {
const p = map[req.path];
res.json((p && p.body) || ({ status: 'ok' }));
const reply = (p && p.body) || ({ status: 'ok' });
if (this.addPath) {
reply.path = req.path;
}
res.json(reply);
});

this._server.listen(options.port, (err) => {
Expand Down
27 changes: 22 additions & 5 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,28 +155,39 @@ describe('KubernetesClient', () => {
});
});
describe('Pods', () => {
before(() => {
kubernetesServerMock.addPath=true;
});
after(() => {
kubernetesServerMock.addPath=false;
});
it('should get', async () => {
const res = await client.pods.get({ podName, labelSelector });
expect(res.body.path).to.eql('/api/kube/api/v1/namespaces/default/pods/worker')
expect(res).to.have.property('statusCode');
expect(res).to.have.property('body');
expect(res).to.have.property('body');
});
it('should get all', async () => {
const res = await client.pods.get({ useNamespace: false });
expect(res.body.path).to.eql('/api/kube/api/v1/pods')
expect(res).to.have.property('statusCode');
expect(res).to.have.property('body');
});
it('should get all in namespace', async () => {
const res = await client.pods.get();
expect(res.body.path).to.eql('/api/kube/api/v1/namespaces/default/pods/')
expect(res).to.have.property('statusCode');
expect(res).to.have.property('body');
});
it('should get all backward compatibility', async () => {
const res = await client.pods.all();
expect(res.body.path).to.eql('/api/kube/api/v1/pods')
expect(res).to.have.property('statusCode');
expect(res).to.have.property('body');
});
it('should get all in namespace backward compatibility', async () => {
const res = await client.pods.all(true);
expect(res.body.path).to.eql('/api/kube/api/v1/namespaces/default/pods/')
expect(res).to.have.property('statusCode');
expect(res).to.have.property('body');
});
Expand All @@ -186,21 +197,27 @@ describe('KubernetesClient', () => {
});
});
describe('ResourceQuotas', () => {
before(() => {
kubernetesServerMock.addPath=true;
});
after(() => {
kubernetesServerMock.addPath=false;
});
it('should get', async () => {
const res = await client.resourcequotas.get({ name: 'foo', labelSelector });
expect(res).to.eql(response);
expect(res.body.path).to.eql('/api/kube/api/v1/namespaces/default/resourcequotas/foo')
});
it('should get all', async () => {
const res = await client.resourcequotas.get({ useNamespace: false });
expect(res).to.eql(response);
expect(res.body.path).to.eql('/api/kube/api/v1/resourcequotas')
});
it('should get all in namespace', async () => {
const res = await client.resourcequotas.get({});
expect(res).to.eql(response);
expect(res.body.path).to.eql('/api/kube/api/v1/namespaces/default/resourcequotas/')
});
it('should get all in namespace no args', async () => {
const res = await client.resourcequotas.get();
expect(res).to.eql(response);
expect(res.body.path).to.eql('/api/kube/api/v1/namespaces/default/resourcequotas/')
});
});
describe('Services', () => {
Expand Down