-
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(Support for more APIs): Apps, Batch, and RBAC (#78)
- Loading branch information
Showing
11 changed files
with
280 additions
and
2 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
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,21 @@ | ||
'use strict'; | ||
|
||
const ApiGroup = require('./api-group'); | ||
|
||
class Apps extends ApiGroup { | ||
constructor(options) { | ||
const genericTypes = [ | ||
// Deprecated name of statefulsets in kubernetes 1.4 | ||
'petsets', | ||
'statefulsets' | ||
]; | ||
options = Object.assign({}, options, { | ||
path: 'apis/apps', | ||
version: options.version || 'v1beta1', | ||
genericTypes: genericTypes | ||
}); | ||
super(options); | ||
} | ||
} | ||
|
||
module.exports = Apps; |
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,22 @@ | ||
'use strict'; | ||
|
||
const ApiGroup = require('./api-group'); | ||
|
||
class Batch extends ApiGroup { | ||
constructor(options) { | ||
const genericTypes = [ | ||
'cronjobs', | ||
'jobs', | ||
// Deprecated name for cronjobs in kubernetes 1.4 | ||
'scheduledjobs' | ||
]; | ||
options = Object.assign({}, options, { | ||
path: 'apis/batch', | ||
version: options.version || 'v1', | ||
genericTypes: genericTypes | ||
}); | ||
super(options); | ||
} | ||
} | ||
|
||
module.exports = Batch; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
|
||
const ApiGroup = require('./api-group'); | ||
|
||
class Rbac extends ApiGroup { | ||
constructor(options) { | ||
const genericTypes = [ | ||
'clusterroles', | ||
'clusterrolebindings', | ||
'roles', | ||
'rolebindings' | ||
]; | ||
options = Object.assign({}, options, { | ||
path: 'apis/rbac.authorization.k8s.io', | ||
version: options.version || 'v1alpha1', | ||
genericTypes: genericTypes | ||
}); | ||
super(options); | ||
} | ||
} | ||
|
||
module.exports = Rbac; |
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,62 @@ | ||
'use strict'; | ||
|
||
const assume = require('assume'); | ||
const async = require('async'); | ||
const nock = require('nock'); | ||
|
||
const common = require('./common'); | ||
const beforeTesting = common.beforeTesting; | ||
|
||
const testStatefulSet = { | ||
apiVersion: 'apps/v1beta1', | ||
kind: 'StatefulSet', | ||
metadata: { | ||
name: 'web' | ||
}, | ||
spec: { | ||
serviceName: 'nginx', | ||
template: { | ||
spec: { | ||
containers: [ | ||
{ | ||
image: 'fake-image-kubernetes-client', | ||
name: 'nginx' | ||
} | ||
] | ||
}, | ||
metadata: { | ||
labels: { | ||
app: 'nginx' | ||
} | ||
} | ||
}, | ||
replicas: 1 | ||
} | ||
}; | ||
|
||
describe('lib.apps', () => { | ||
describe('.statefulsets', () => { | ||
const testStatefuleSetName = testStatefulSet.metadata.name; | ||
|
||
beforeTesting('int', common.changeName); | ||
beforeTesting('unit', () => { | ||
nock(common.apps.url) | ||
.post(`${ common.apps.path }/namespaces/${ common.currentName }/statefulsets`) | ||
.reply(201, testStatefulSet) | ||
.get(`${ common.apps.path }/namespaces/${ common.currentName }/statefulsets/${ testStatefuleSetName }`) | ||
.reply(200, testStatefulSet); | ||
}); | ||
|
||
it('can POST and GET', done => { | ||
async.series([ | ||
next => common.apps.ns.statefulsets.post({ body: testStatefulSet }, next), | ||
next => common.apps.ns.statefulsets.get(testStatefuleSetName, next) | ||
], (err, results) => { | ||
assume(err).is.falsy(); | ||
const getResult = results[1]; | ||
assume(getResult.metadata.name).is.equal(testStatefuleSetName); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
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,60 @@ | ||
'use strict'; | ||
|
||
const assume = require('assume'); | ||
const async = require('async'); | ||
const nock = require('nock'); | ||
|
||
const common = require('./common'); | ||
const beforeTesting = common.beforeTesting; | ||
|
||
const testJob = { | ||
apiVersion: 'batch/v1', | ||
kind: 'Job', | ||
metadata: { | ||
name: 'pi' | ||
}, | ||
spec: { | ||
template: { | ||
spec: { | ||
restartPolicy: 'Never', | ||
containers: [ | ||
{ | ||
image: 'perl', | ||
command: ['perl', '-Mbignum=bpi', '-wle', 'print bpi(2000)'], | ||
name: 'pi' | ||
} | ||
] | ||
}, | ||
metadata: { | ||
name: 'pi' | ||
} | ||
} | ||
} | ||
}; | ||
|
||
describe('lib.batch', () => { | ||
describe('.jobs', () => { | ||
const testJobName = testJob.metadata.name; | ||
|
||
beforeTesting('int', common.changeName); | ||
beforeTesting('unit', () => { | ||
nock(common.batch.url) | ||
.post(`${ common.batch.path }/namespaces/${ common.currentName }/jobs`) | ||
.reply(201, testJob) | ||
.get(`${ common.batch.path }/namespaces/${ common.currentName }/jobs/${ testJobName }`) | ||
.reply(200, testJob); | ||
}); | ||
|
||
it('can POST and GET', done => { | ||
async.series([ | ||
next => common.batch.ns.jobs.post({ body: testJob }, next), | ||
next => common.batch.ns.jobs.get(testJobName, next) | ||
], (err, results) => { | ||
assume(err).is.falsy(); | ||
const getResult = results[1]; | ||
assume(getResult.metadata.name).is.equal(testJobName); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
'use strict'; | ||
|
||
const assume = require('assume'); | ||
const async = require('async'); | ||
const nock = require('nock'); | ||
|
||
const common = require('./common'); | ||
const beforeTesting = common.beforeTesting; | ||
|
||
const testRbac = { | ||
kind: 'Role', | ||
apiVersion: 'rbac.authorization.k8s.io/v1alpha1', | ||
metadata: { | ||
name: 'pod-reader' | ||
}, | ||
rules: [{ | ||
apiGroups: [''], | ||
resources: ['pods'], | ||
verbs: ['get', 'watch', 'list'] | ||
}] | ||
}; | ||
|
||
describe('lib.rbac', () => { | ||
describe('.Rbac', () => { | ||
const testRbacName = testRbac.metadata.name; | ||
|
||
beforeTesting('unit', () => { | ||
nock(common.rbac.url) | ||
.post(`${ common.rbac.path }/namespaces/${ common.currentName }/roles`) | ||
.reply(201, testRbac) | ||
.get(`${ common.rbac.path }/namespaces/${ common.currentName }/roles/${ testRbacName }`) | ||
.reply(200, testRbac); | ||
}); | ||
|
||
// NOTE: Running only unit tests. Setting up RBAC is more involved, and it | ||
// makes it cumbersome to run the other integration tests. We need | ||
// improvements to our integration test harness to make this work well. | ||
common.only('unit', 'can POST and GET', done => { | ||
async.series([ | ||
next => common.rbac.ns.roles.post({ body: testRbac }, next), | ||
next => common.rbac.ns.roles.get(testRbacName, next) | ||
], (err, results) => { | ||
assume(err).is.falsy(); | ||
const getResult = results[1]; | ||
assume(getResult.metadata.name).is.equal(testRbacName); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |