forked from kubernetes-client/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kubernetes-client#1 from brendandburns/master
Switch to the typescript generated client.
- Loading branch information
Showing
1,105 changed files
with
66,011 additions
and
185,143 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 |
---|---|---|
@@ -1,12 +1,80 @@ | ||
# javascript | ||
# Javascript Kubernetes Client information | ||
|
||
Javascript client. Work in progress. | ||
The Javascript clients for Kubernetes is implemented in | ||
[typescript](https://typescriptlang.org), but can be called from either | ||
Javascript or Typescript. | ||
|
||
For now, the client is implemented for server-side use with node | ||
using the `request` library. | ||
|
||
# Update client | ||
There are future plans to also build a jQuery compatible library but | ||
for now, all of the examples and instructions assume the node client. | ||
|
||
to update the client clone `gen` repo and run this command: | ||
# Installation | ||
```sh | ||
$ npm install @kubernetes/client-node | ||
``` | ||
|
||
# Example code | ||
|
||
## List all pods | ||
```javascript | ||
const k8s = require('@kubernetes/typescript-node'); | ||
|
||
var k8sApi = k8s.Config.defaultClient(); | ||
k8sApi.listNamespacedPod('default') | ||
.then((res) => { | ||
console.log(res.body); | ||
}); | ||
``` | ||
|
||
## Create a new namespace | ||
```javascript | ||
const k8s = require('@kubernetes/typescript-node'); | ||
|
||
var k8sApi = k8s.Config.defaultClient(); | ||
|
||
var namespace = { | ||
metadata: { | ||
name: 'test' | ||
} | ||
}; | ||
|
||
k8sApi.createNamespace(namespace).then( | ||
(response) => { | ||
console.log('Created namespace'); | ||
console.log(response); | ||
k8sApi.readNamespace(namespace.metadata.name).then( | ||
(response) => { | ||
console.log(response); | ||
k8sApi.deleteNamespace( | ||
namespace.metadata.name, {} /* delete options */); | ||
}); | ||
}, | ||
(err) => { | ||
console.log('Error!: ' + err); | ||
} | ||
); | ||
``` | ||
|
||
# Development | ||
|
||
All dependencies of this project are expressed in its | ||
[`package.json` file](./package.json). Before you start developing, ensure | ||
that you have [NPM](https://www.npmjs.com/) installed, then run: | ||
|
||
```bash | ||
${GEN_REPO_BASE}/openapi/javascript.sh ${CLIENT_ROOT}/kubernetes ./settings | ||
```console | ||
npm install | ||
``` | ||
|
||
# Testing | ||
|
||
Tests are written using the [Chai](http://chaijs.com/) library. See | ||
[`config_test.ts`](./config_test.ts) for an example. | ||
|
||
To run tests, execute the following: | ||
|
||
```console | ||
npm test | ||
``` | ||
|
This file was deleted.
Oops, something went wrong.
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,8 @@ | ||
const k8s = require('@kubernetes/client-node'); | ||
|
||
let k8sApi = k8s.Config.defaultClient(); | ||
k8sApi.listNamespacedPod('default') | ||
.then((res) => { | ||
console.log(res.body); | ||
}); | ||
|
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,25 @@ | ||
const k8s = require('@kubernetes/client-node'); | ||
|
||
var k8sApi = k8s.Config.defaultClient(); | ||
|
||
var namespace = { | ||
metadata: { | ||
name: 'test' | ||
} | ||
}; | ||
|
||
k8sApi.createNamespace(namespace).then( | ||
(response) => { | ||
console.log('Created namespace'); | ||
console.log(response); | ||
k8sApi.readNamespace(namespace.metadata.name).then( | ||
(response) => { | ||
console.log(response); | ||
k8sApi.deleteNamespace( | ||
namespace.metadata.name, {} /* delete options */); | ||
}); | ||
}, | ||
(err) => { | ||
console.log('Error!: ' + err); | ||
} | ||
); |
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,7 @@ | ||
import k8s = require('@kubernetes/client-node'); | ||
|
||
let kc = new k8s.KubeConfig(); | ||
kc.loadFromFile(process.env['HOME'] + '/.kube/config'); | ||
|
||
let attach = new k8s.Attach(kc); | ||
attach.attach('default', 'nginx-4217019353-9gl4s', 'nginx', process.stdout, process.stderr, null /* stdin */, false /* tty */); |
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,9 @@ | ||
import k8s = require('@kubernetes/client-node'); | ||
|
||
let command = process.argv[2]; | ||
|
||
let kc = new k8s.KubeConfig(); | ||
kc.loadFromFile(process.env['HOME'] + '/.kube/config'); | ||
|
||
let exec = new k8s.Exec(kc); | ||
exec.exec('default', 'nginx-4217019353-9gl4s', 'nginx', command, process.stdout, process.stderr, process.stdin, true /* tty */); |
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,12 @@ | ||
import k8s = require('@kubernetes/client-node'); | ||
|
||
let k8sApi = k8s.Config.defaultClient(); | ||
|
||
k8sApi.listNamespacedPod('default') | ||
.then((res) => { | ||
console.log(res.body); | ||
}); | ||
|
||
// Example of instantiating a Pod object. | ||
let pod = { | ||
} as k8s.V1Pod; |
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,31 @@ | ||
import k8s = require('@kubernetes/client-node'); | ||
|
||
let kc = new k8s.KubeConfig(); | ||
kc.loadFromFile(process.env['HOME'] + '/.kube/config'); | ||
|
||
let watch = new k8s.Watch(kc); | ||
let req = watch.watch('/api/v1/namespaces', | ||
// optional query parameters can go here. | ||
{}, | ||
// callback is called for each received object. | ||
(type, obj) => { | ||
if (type == 'ADDED') { | ||
console.log('new object:'); | ||
} else if (type == 'MODIFIED') { | ||
console.log('changed object:') | ||
} else if (type == 'DELETED') { | ||
console.log('deleted object:'); | ||
} else { | ||
console.log('unknown type: ' + type); | ||
} | ||
console.log(obj); | ||
}, | ||
// done callback is called if the watch terminates normally | ||
(err) => { | ||
if (err) { | ||
console.log(err); | ||
} | ||
}); | ||
|
||
// watch returns a request object which you can use to abort the watch. | ||
setTimeout(() => { req.abort(); }, 10 * 1000); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.