-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(CustomResourceDefinition): Add support for CRDs (#149)
Adds `CustomResourceDefinition`, which replaces `ThirdPartyResources` starting Kubernetes 1.7.
- Loading branch information
1 parent
8e77449
commit 4261c2e
Showing
9 changed files
with
343 additions
and
1 deletion.
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,22 @@ | ||
'use strict'; | ||
|
||
const ApiGroup = require('./api-group'); | ||
const CustomResourceDefiniton = require('./custom-resource-definition'); | ||
|
||
class ApiExtensions extends ApiGroup { | ||
constructor(options) { | ||
options = Object.assign({}, options, { | ||
path: 'apis/apiextensions.k8s.io', | ||
version: options.version || 'v1beta1', | ||
groupResources: [ | ||
'customresourcedefinitions' | ||
], | ||
namespaceResources: [ | ||
{ name: 'customresourcedefinitions', Constructor: CustomResourceDefiniton } | ||
] | ||
}); | ||
super(options); | ||
} | ||
} | ||
|
||
module.exports = ApiExtensions; |
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,27 @@ | ||
'use strict'; | ||
|
||
const ApiGroup = require('./api-group'); | ||
|
||
class CustomResourceDefinition extends ApiGroup { | ||
constructor(options) { | ||
options = Object.assign({}, options, { | ||
path: `apis/${ options.group }`, | ||
version: options.version || 'v1', | ||
groupResources: [], | ||
namespaceResources: [] | ||
}); | ||
super(options); | ||
|
||
if (options.resources) { | ||
options.resources.forEach(resource => this.addResource(resource)); | ||
} | ||
} | ||
|
||
addResource(resourceName) { | ||
this.namespace.addResource(resourceName); | ||
super.addResource(resourceName); | ||
return this; | ||
} | ||
} | ||
|
||
module.exports = CustomResourceDefinition; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,58 @@ | ||
'use strict'; | ||
|
||
const assume = require('assume'); | ||
const async = require('async'); | ||
const nock = require('nock'); | ||
|
||
const common = require('./common'); | ||
const beforeTesting = common.beforeTesting; | ||
|
||
const testApiExtensions = { | ||
apiVersion: 'apiextensions.k8s.io/v1beta1', | ||
kind: 'CustomResourceDefinition', | ||
metadata: { | ||
name: 'test.example.com' | ||
}, | ||
spec: { | ||
group: 'example.com', | ||
version: 'v1', | ||
scope: 'Namespaced', | ||
names: { | ||
plural: 'tests', | ||
singular: 'test', | ||
kind: 'Test', | ||
shortNames: [ | ||
't' | ||
] | ||
} | ||
} | ||
}; | ||
|
||
describe('lib.apiextensions', () => { | ||
describe('.ApiExtensions', () => { | ||
const testCustomResourceName = testApiExtensions.metadata.name; | ||
|
||
beforeTesting('unit', () => { | ||
nock(common.apiExtensions.url) | ||
.post(`${ common.apiExtensions.path }/customresourcedefinitions`) | ||
.reply(201, testApiExtensions) | ||
.get(`${ common.apiExtensions.path }/customresourcedefinitions/${ testCustomResourceName }`) | ||
.reply(200, testApiExtensions); | ||
}); | ||
|
||
// NOTE: Running only unit tests. Setting up CRD 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.apiExtensions.customresourcedefinitions.post({ body: testApiExtensions }, next), | ||
next => common.apiExtensions.customresourcedefinitions.get(testCustomResourceName, next) | ||
], (err, results) => { | ||
assume(err).is.falsy(); | ||
const getResult = results[1]; | ||
assume(getResult.metadata.name).is.equal(testCustomResourceName); | ||
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
Oops, something went wrong.