Skip to content

Commit

Permalink
add pvc support
Browse files Browse the repository at this point in the history
  • Loading branch information
yehiyam committed Nov 22, 2021
1 parent 30c94af commit 2cc665c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const Versions = require('./versions');
const ResourceQuotas = require('./resourceQuotas');
const Secrets = require('./secrets');
const SideCars = require('./sidecars');
const PVC = require('./pvc');

class Client {
async init(options) {
Expand All @@ -37,6 +38,7 @@ class Client {
this.resourcequotas = new ResourceQuotas(client, namespace, this.kubeVersion);
this.secrets = new Secrets(client, namespace, this.kubeVersion);
this.sidecars = new SideCars(client, namespace, this.kubeVersion, this.configMaps);
this.pvc = new PVC(client, namespace, this.kubeVersion);
}
}

Expand Down
21 changes: 21 additions & 0 deletions lib/pvc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const Client = require('./client-base');

class PVC extends Client {
get({ name, labelSelector, useNamespace = true } = {}) {
const prefix = useNamespace ? this._prefix.namespaces(this._namespace).persistentvolumeclaims(name) : this._client.api.v1.persistentvolumeclaims;
return prefix.get({ qs: { labelSelector } });
}

delete({ name }) {
return this._prefix
.namespaces(this._namespace)
.persistentvolumeclaims(name)
.delete();
}

all(useNamespace = false) {
return this.get({ useNamespace });
}
}

module.exports = PVC;
37 changes: 37 additions & 0 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const containerName = 'worker';
const secretName = 'worker';
const configMapName = 'hkube-versions';
const sidecarName = 'my-sidecar'

let client, Client, utils;
let client_v1_22;
const response = { statusCode: 200, body: { status: 'ok' } };
Expand Down Expand Up @@ -265,6 +266,42 @@ describe('KubernetesClient', () => {
expect(res.statusCode).to.eql(200);
});
});
describe.only('PVC', () => {
it('should get', async () => {
const res = await client.pvc.get({ name: 'mypvc', labelSelector });
expect(res.body.path).to.eql('/api/kube/api/v1/namespaces/default/persistentvolumeclaims/mypvc')
expect(res).to.have.property('statusCode');
expect(res).to.have.property('body');
});
it('should get all', async () => {
const res = await client.pvc.get({ useNamespace: false });
expect(res.body.path).to.eql('/api/kube/api/v1/persistentvolumeclaims')
expect(res).to.have.property('statusCode');
expect(res).to.have.property('body');
});
it('should get all in namespace', async () => {
const res = await client.pvc.get();
expect(res.body.path).to.eql('/api/kube/api/v1/namespaces/default/persistentvolumeclaims/')
expect(res).to.have.property('statusCode');
expect(res).to.have.property('body');
});
it('should get all backward compatibility', async () => {
const res = await client.pvc.all();
expect(res.body.path).to.eql('/api/kube/api/v1/persistentvolumeclaims')
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.pvc.all(true);
expect(res.body.path).to.eql('/api/kube/api/v1/namespaces/default/persistentvolumeclaims/')
expect(res).to.have.property('statusCode');
expect(res).to.have.property('body');
});
it('should delete', async () => {
const res = await client.pvc.delete({ name: 'mypvc' });
expect(res.statusCode).to.eql(200);
});
});
describe('ResourceQuotas', () => {
it('should get', async () => {
const res = await client.resourcequotas.get({ name: 'foo', labelSelector });
Expand Down

0 comments on commit 2cc665c

Please sign in to comment.