-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(CRDs): add basic CRD support to the dynamic client (#214)
- Loading branch information
Showing
4 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"kind": "CustomResourceDefinition", | ||
"spec": { | ||
"scope": "Namespaced", | ||
"version": "v1", | ||
"group": "stable.example.com", | ||
"names": { | ||
"shortNames": [ | ||
"ct" | ||
], | ||
"kind": "CronTab", | ||
"plural": "crontabs", | ||
"singular": "crontab" | ||
} | ||
}, | ||
"apiVersion": "apiextensions.k8s.io/v1beta1", | ||
"metadata": { | ||
"name": "crontabs.stable.example.com" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// Use a Custom Resource Definition to extend the Kubernetes API and the client. | ||
// | ||
const { Client,config } = require('kubernetes-client'); | ||
|
||
const crd = require('./crontabs-crd.json'); | ||
|
||
async function main() { | ||
try { | ||
const client = new Client({ config: config.fromKubeconfig(), version: '1.9' }); | ||
|
||
// | ||
// Create the CRD with the Kubernetes API | ||
// | ||
const create = await client.apis['apiextensions.k8s.io'].v1beta1.customresourcedefinitions.post({ body: crd }); | ||
console.log('Create: ', create); | ||
|
||
// | ||
// Add endpoints to our client | ||
// | ||
client.addCustomResourceDefinition(crd); | ||
|
||
// | ||
// List all the resources of the new type | ||
// | ||
const all = await client.apis['stable.example.com'].v1.namespaces('default').crontabs.get(); | ||
console.log('All: ', all); | ||
|
||
// | ||
// Get a specific resources. | ||
// | ||
const one = await client.apis['stable.example.com'].v1.namespaces('default').crontabs('foo').get(); | ||
console.log('One: ', one); | ||
} catch (err) { | ||
console.error('Error: ', err); | ||
} | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters