-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add StatefulSet resource #93
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,147 @@ | ||
'use strict'; | ||
|
||
/* | ||
* | ||
* Copyright 2016-2017 Red Hat, Inc, and individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
const request = require('./common-request'); | ||
const privates = require('./private-map'); | ||
|
||
function findAll (client) { | ||
return function findAll (options = {}) { | ||
const clientConfig = privates.get(client).config; | ||
const url = `${clientConfig.cluster}${client.apis.v1beta1.endpoints().apps}/namespaces/${clientConfig | ||
.context.namespace}/statefulsets`; | ||
|
||
const req = { | ||
method: 'GET', | ||
url, | ||
qs: options.qs | ||
}; | ||
|
||
return request(client, req); | ||
}; | ||
} | ||
|
||
function find (client) { | ||
return function find (statefulSetName, options = {}) { | ||
const clientConfig = privates.get(client).config; | ||
|
||
if (!statefulSetName) { | ||
return Promise.reject(new Error('Stateful Set Name is required')); | ||
} | ||
const url = `${clientConfig.cluster}${client.apis.v1beta1.endpoints().apps}/namespaces/${clientConfig | ||
.context.namespace}/statefulsets/${statefulSetName}`; | ||
|
||
const req = { | ||
method: 'GET', | ||
url | ||
}; | ||
|
||
return request(client, req); | ||
}; | ||
} | ||
|
||
function create (client) { | ||
return function create (statefulSet, options = {}) { | ||
const clientConfig = privates.get(client).config; | ||
const url = `${clientConfig.cluster}${client.apis.v1beta1.endpoints().apps}/namespaces/${clientConfig | ||
.context.namespace}/statefulsets`; | ||
|
||
const req = { | ||
method: 'POST', | ||
url, | ||
json: false, | ||
body: JSON.stringify(statefulSet) | ||
}; | ||
|
||
return request(client, req).then((body) => { | ||
return JSON.parse(body); | ||
}); | ||
}; | ||
} | ||
|
||
function update (client) { | ||
return function create (statefulSetName, statefulSet, options = {}) { | ||
if (!statefulSetName) { | ||
return Promise.reject(new Error('Stateful Set Name is required')); | ||
} | ||
|
||
const clientConfig = privates.get(client).config; | ||
const url = | ||
`${clientConfig.cluster}${client.apis.v1beta1.endpoints() | ||
.apps}/namespaces/${clientConfig.context.namespace}/statefulsets/${statefulSetName}`; | ||
|
||
const req = { | ||
method: 'PUT', | ||
json: false, | ||
url, | ||
body: JSON.stringify(statefulSet) | ||
}; | ||
|
||
return request(client, req).then(body => { | ||
return JSON.parse(body); | ||
}); | ||
}; | ||
} | ||
|
||
function remove (client) { | ||
return function remove (statefulSetName, options = {}) { | ||
if (!statefulSetName) { | ||
return Promise.reject(new Error('Stateful Set Name is required')); | ||
} | ||
const clientConfig = privates.get(client).config; | ||
const url = | ||
`${clientConfig.cluster}${client.apis.v1beta1.endpoints() | ||
.apps}/namespaces/${clientConfig.context.namespace}/statefulsets/${statefulSetName}`; | ||
|
||
const req = { | ||
method: 'DELETE', | ||
url, | ||
body: options.body, | ||
qs: options.qs | ||
}; | ||
|
||
return request(client, req); | ||
}; | ||
} | ||
|
||
function removeAll (client) { | ||
return function removeAll (options = {}) { | ||
const clientConfig = privates.get(client).config; | ||
const url = | ||
`${clientConfig.cluster}${client.apis.v1beta1.endpoints() | ||
.apps}/namespaces/${clientConfig.context.namespace}/statefulsets`; | ||
|
||
const req = { | ||
method: 'DELETE', | ||
url, | ||
qs: options.qs | ||
}; | ||
|
||
return request(client, req); | ||
}; | ||
} | ||
|
||
module.exports = { | ||
findAll: findAll, | ||
find: find, | ||
create: create, | ||
update: update, | ||
remove: remove, | ||
removeAll: removeAll | ||
}; |
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,179 @@ | ||
'use strict'; | ||
|
||
const test = require('tape'); | ||
const nock = require('nock'); | ||
|
||
const openshiftRestClient = require('../'); | ||
const privates = require('../lib/private-map'); | ||
|
||
const settings = { | ||
config: { | ||
apiVersion: 'v1beta1', | ||
context: | ||
{ cluster: '192-168-99-100:8443', | ||
namespace: 'for-node-client-testing', | ||
user: 'developer/192-168-99-100:8443' }, | ||
user: { token: 'zVBd1ZFeJqEAILJgimm4-gZJauaw3PW4EVqV_peEZ3U' }, | ||
cluster: 'https://192.168.99.100:8443' } | ||
}; | ||
|
||
test('find - statefulsets - basic findAll', (t) => { | ||
openshiftRestClient(settings).then((client) => { | ||
t.equal(typeof client.statefulsets.findAll, 'function', 'There is a findAll method on the statefulsets object'); | ||
|
||
const clientConfig = privates.get(client).config; | ||
|
||
nock(clientConfig.cluster) | ||
.matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config | ||
.get(`/apis/apps/v1beta1/namespaces/${clientConfig.context.namespace}/statefulsets`) | ||
.reply(200, {kind: 'StatefulSetList'}); | ||
|
||
const findResult = client.statefulsets.findAll().then((statefulSetList) => { | ||
t.equal(statefulSetList.kind, 'StatefulSetList', 'returns an object with StatefulSetList'); | ||
t.end(); | ||
}); | ||
|
||
t.equal(findResult instanceof Promise, true, 'should return a Promise'); | ||
}); | ||
}); | ||
|
||
test('find - statefulsets - basic find', (t) => { | ||
openshiftRestClient(settings).then((client) => { | ||
t.equal(typeof client.statefulsets.find, 'function', 'There is a find method on the statefulsets object'); | ||
|
||
const clientConfig = privates.get(client).config; | ||
const statefulSetName = 'cool-statefulset-name-1'; | ||
|
||
nock(clientConfig.cluster) | ||
.matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config | ||
.get(`/apis/apps/v1beta1/namespaces/${clientConfig.context.namespace}/statefulsets/${statefulSetName}`) | ||
.reply(200, {kind: 'StatefulSet'}); | ||
|
||
const findResult = client.statefulsets.find(statefulSetName).then((statefulset) => { | ||
t.equal(statefulset.kind, 'StatefulSet', 'returns an object with StatefulSet'); | ||
t.end(); | ||
}).catch(e => { | ||
console.log(e); | ||
}); | ||
|
||
t.equal(findResult instanceof Promise, true, 'should return a Promise'); | ||
}); | ||
}); | ||
|
||
test('find - statefulsets - find - no statefulset name', (t) => { | ||
openshiftRestClient(settings).then((client) => { | ||
client.statefulsets.find().catch((err) => { | ||
t.equal(err.message, 'Stateful Set Name is required', 'error message should return'); | ||
t.end(); | ||
}); | ||
}); | ||
}); | ||
|
||
test('create - statefulset', (t) => { | ||
openshiftRestClient(settings).then((client) => { | ||
t.equal(typeof client.statefulsets.create, 'function', 'There is a create method on the statefulsets object'); | ||
|
||
const clientConfig = privates.get(client).config; | ||
const statefulset = { | ||
kind: 'StatefulSet' | ||
}; | ||
|
||
nock(clientConfig.cluster) | ||
.matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config | ||
.post(`/apis/apps/v1beta1/namespaces/${clientConfig.context.namespace}/statefulsets`) | ||
.reply(200, {kind: 'StatefulSet'}); | ||
|
||
const createResult = client.statefulsets.create(statefulset).then((statefulset) => { | ||
t.equal(statefulset.kind, 'StatefulSet', 'returns an object with StatefulSet'); | ||
t.end(); | ||
}); | ||
|
||
t.equal(createResult instanceof Promise, true, 'should return a Promise'); | ||
}); | ||
}); | ||
|
||
test('update - statefulset', (t) => { | ||
openshiftRestClient(settings).then(client => { | ||
t.equal(typeof client.statefulsets.create, 'function', 'There is a create method on the statefulsets object'); | ||
|
||
const clientConfig = privates.get(client).config; | ||
const statefulSet = { | ||
kind: 'StatefulSet' | ||
}; | ||
const statefulSetName = 'cool-statefulset-name-1'; | ||
const url = `${client.apis.v1beta1.endpoints().apps}/namespaces/${clientConfig.context.namespace}/statefulsets/${statefulSetName}`; | ||
|
||
nock(clientConfig.cluster) | ||
.matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config | ||
.put(url) | ||
.reply(200, {kind: 'StatefulSet'}); | ||
|
||
const createResult = client.statefulsets.update(statefulSetName, statefulSet).then(updated => { | ||
t.equal(updated.kind, 'StatefulSet', 'returns an object with StatefulSet'); | ||
t.end(); | ||
}); | ||
|
||
t.equal(createResult instanceof Promise, true, 'should return a Promise'); | ||
}); | ||
}); | ||
|
||
test('update - statefulset with no statefulset name', (t) => { | ||
openshiftRestClient(settings).then((client) => { | ||
client.statefulsets.update().catch((err) => { | ||
t.equal(err.message, 'Stateful Set Name is required', 'error message should return'); | ||
t.end(); | ||
}); | ||
}); | ||
}); | ||
|
||
test('remove - statefulsets - basic removeAll', (t) => { | ||
openshiftRestClient(settings).then((client) => { | ||
t.equal(typeof client.statefulsets.removeAll, 'function', 'There is a removeAll method on the statefulsets object'); | ||
|
||
const clientConfig = privates.get(client).config; | ||
const url = `${client.apis.v1beta1.endpoints().apps}/namespaces/${clientConfig.context.namespace}/statefulsets`; | ||
|
||
nock(clientConfig.cluster) | ||
.matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config | ||
.delete(url) | ||
.reply(200, {kind: 'Status'}); | ||
|
||
const removeResult = client.statefulsets.removeAll().then(statefulSetList => { | ||
t.equal(statefulSetList.kind, 'Status', 'returns an object with Status'); | ||
t.end(); | ||
}); | ||
|
||
t.equal(removeResult instanceof Promise, true, 'should return a Promise'); | ||
}); | ||
}); | ||
|
||
test('remove - statefulsets - basic remove', (t) => { | ||
openshiftRestClient(settings).then((client) => { | ||
t.equal(typeof client.statefulsets.remove, 'function', 'There is a remove method on the statefulsets object'); | ||
|
||
const clientConfig = privates.get(client).config; | ||
const statefulSetName = 'cool-statefulset-name-1'; | ||
const url = `${client.apis.v1beta1.endpoints().apps}/namespaces/${clientConfig.context.namespace}/statefulsets/${statefulSetName}`; | ||
|
||
nock(clientConfig.cluster) | ||
.matchHeader('authorization', `Bearer ${clientConfig.user.token}`) // taken from the config | ||
.delete(url) | ||
.reply(200, {kind: 'Status'}); | ||
|
||
const removeResult = client.statefulsets.remove(statefulSetName).then(status => { | ||
t.equal(status.kind, 'Status', 'returns an object with Status'); | ||
t.end(); | ||
}); | ||
|
||
t.equal(removeResult instanceof Promise, true, 'should return a Promise'); | ||
}); | ||
}); | ||
|
||
test('remove - statefulset - no statefulset name', (t) => { | ||
openshiftRestClient(settings).then((client) => { | ||
client.statefulsets.remove().catch((err) => { | ||
t.equal(err.message, 'Stateful Set Name is required', 'error message should return'); | ||
t.end(); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can remove this catch once the tests will be passing