Skip to content

Commit 28ad044

Browse files
authored
Merge pull request #38 from kube-HPC/add_crd_support
client now support CRDs
2 parents d545007 + b16031f commit 28ad044

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

lib/client.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const ResourceQuotas = require('./resourceQuotas');
1313
const Secrets = require('./secrets');
1414
const SideCars = require('./sidecars');
1515
const PVC = require('./pvc');
16+
const CRDs = require('./crds');
1617

1718
class Client {
1819
async init(options) {
@@ -39,6 +40,7 @@ class Client {
3940
this.secrets = new Secrets(client, namespace, this.kubeVersion);
4041
this.sidecars = new SideCars(client, namespace, this.kubeVersion, this.configMaps);
4142
this.pvc = new PVC(client, namespace, this.kubeVersion);
43+
this.crds = new CRDs(client, namespace, this.kubeVersion);
4244
}
4345
}
4446

lib/crds.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const Client = require('./client-base');
2+
3+
/**
4+
* Client for interacting with arbitrary Custom Resource Definitions (CRDs).
5+
* Allows fetching individual or all resources by manually constructing the API path.
6+
*/
7+
class CRDs extends Client {
8+
/**
9+
* Fetches a single custom resource or a list of custom resources.
10+
*
11+
* @param {Object} params - Parameters for the request.
12+
* @param {string} params.group - API group of the CRD.
13+
* @param {string} params.version - API version of the CRD.
14+
* @param {string} params.resource - Resource type (e.g., 'queues').
15+
* @param {string} [params.name] - Optional resource name for fetching a specific resource.
16+
* @param {string} [params.labelSelector] - Optional label selector for filtering.
17+
* @returns {Promise<Object>} The API response containing the requested resource(s).
18+
*/
19+
async get({ name, group, version, resource, labelSelector } = {}) {
20+
const basePath = name
21+
? `/apis/${group}/${version}/${resource}/${name}`
22+
: `/apis/${group}/${version}/${resource}`;
23+
24+
const qs = labelSelector ? { labelSelector } : undefined;
25+
26+
return this._client.backend.http({
27+
method: 'GET',
28+
pathname: basePath,
29+
qs
30+
});
31+
}
32+
33+
/**
34+
* Fetches all custom resources of the specified type.
35+
*
36+
* @param {Object} params - Parameters for the request.
37+
* @param {string} params.group - API group of the CRD.
38+
* @param {string} params.version - API version of the CRD.
39+
* @param {string} params.resource - Resource type (e.g., 'queues').
40+
* @param {string} [params.labelSelector] - Optional label selector for filtering.
41+
* @returns {Promise<Object>} The API response containing the list of resources.
42+
*/
43+
all(params = {}) {
44+
return this.get(params);
45+
}
46+
}
47+
48+
module.exports = CRDs;

0 commit comments

Comments
 (0)