Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
Namespace not used when getting services and pods (#159)
Browse files Browse the repository at this point in the history
* Scope to namespaces

* 0.6.1
  • Loading branch information
pstreule authored and andresmgot committed Nov 30, 2018
1 parent dfb6bc3 commit f2aedb3
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 41 deletions.
2 changes: 1 addition & 1 deletion lib/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function waitForDeployment(funcName, requestMoment, namespace, options) {
reject(`Unable to retrieve the status of the ${funcName} deployment`);
}
let runningPods = 0;
core.pods.get((err, podsInfo) => {
core.ns.pods.get((err, podsInfo) => {
if (err) {
if (err.message.match(/request timed out/)) {
opts.log('Request timed out. Retrying...');
Expand Down
2 changes: 1 addition & 1 deletion lib/get-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function info(functions, service, options) {
const core = new Api.Core(connectionOptions);
const functionsApi = new CRD('apis/kubeless.io', 'v1beta1', namespace, 'functions');
const extensions = new Api.Extensions(connectionOptions);
core.services.get((err, servicesInfo) => {
core.ns.services.get((err, servicesInfo) => {
if (err) reject(new Error(err));
functionsApi.getItem(f).catch((ferr) => reject(ferr)).then(fDesc => {
extensions.ns.ingress(service).get((ierr, fIngress) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/invoke.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function invoke(func, data, funcsDesc, options) {
resolve(response);
}
};
core.services.get((err, servicesInfo) => {
core.ns.services.get((err, servicesInfo) => {
if (err) {
reject(err);
} else {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "serverless-kubeless",
"version": "0.6.0",
"version": "0.6.1",
"description": "This plugin enables support for Kubeless within the [Serverless Framework](https://github.com/serverless).",
"main": "index.js",
"directories": {
Expand Down
12 changes: 6 additions & 6 deletions test/kubelessDeploy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ describe('KubelessDeploy', () => {
const funcSpec = defaultFuncSpec();
// First call, still deploying:
nock(config.clusters[0].cluster.server)
.get('/api/v1/pods')
.get('/api/v1/namespaces/default/pods')
.reply(200, {
items: [{
metadata: {
Expand All @@ -372,7 +372,7 @@ describe('KubelessDeploy', () => {
const funcSpec = defaultFuncSpec();
// First call, still deploying:
nock(config.clusters[0].cluster.server)
.get('/api/v1/pods')
.get('/api/v1/namespaces/default/pods')
.reply(200, {
items: [{
metadata: {
Expand All @@ -395,7 +395,7 @@ describe('KubelessDeploy', () => {
it('should throw an error if the pod failed to start', () => {
const funcSpec = defaultFuncSpec();
nock(config.clusters[0].cluster.server)
.get('/api/v1/pods')
.get('/api/v1/namespaces/default/pods')
.times(10)
.reply(200, {
items: [{
Expand Down Expand Up @@ -424,7 +424,7 @@ describe('KubelessDeploy', () => {
const funcSpec = defaultFuncSpec();
// First call, fails to retrieve status
nock(config.clusters[0].cluster.server)
.get('/api/v1/pods')
.get('/api/v1/namespaces/default/pods')
.replyWithError('etcdserver: request timed out');
// Second call, ready:
mocks.createDeploymentNocks(config.clusters[0].cluster.server, functionName, funcSpec);
Expand All @@ -439,7 +439,7 @@ describe('KubelessDeploy', () => {
// First call, fails to retrieve status
nock(config.clusters[0].cluster.server)
.persist()
.get('/api/v1/pods')
.get('/api/v1/namespaces/default/pods')
.reply(200, { items: [] });
// Second call, ready:
mocks.createDeploymentNocks(config.clusters[0].cluster.server, functionName, funcSpec);
Expand Down Expand Up @@ -1311,7 +1311,7 @@ describe('KubelessDeploy', () => {
};
nock(config.clusters[0].cluster.server)
.persist()
.get('/api/v1/pods')
.get('/api/v1/namespaces/default/pods')
.reply(200, () => ({
items: [
{
Expand Down
62 changes: 34 additions & 28 deletions test/kubelessInfo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,32 +84,35 @@ describe('KubelessInfo', () => {
});
});
function mockGetCalls(config, functions, functionModif) {
nock(config.clusters[0].cluster.server)
.get('/api/v1/services')
.reply(200, {
items: _.map(functions, (f) => ({
metadata:
{
name: f.id,
namespace: f.namespace,
selfLink: `/api/v1/namespaces/${f.namespace}/services/${f.id}`,
uid: '010a169d-618c-11e7-9939-080027abf356',
resourceVersion: '248',
creationTimestamp: '2017-07-05T14:12:39Z',
labels: { function: f.id },
},
spec:
{
ports: [{ protocol: 'TCP', port: 8080, targetPort: 8080, nodePort: 30817 }],
selector: { function: f.id },
clusterIP: '10.0.0.177',
type: 'NodePort',
sessionAffinity: 'None',
},
status: { loadBalancer: {} },
})),
})
.persist();
const namespaces = _.map(functions, f => f.namespace);
_.each(namespaces, ns => {
nock(config.clusters[0].cluster.server)
.get(`/api/v1/namespaces/${ns}/services`)
.reply(200, {
items: _.map(_.filter(functions, (f) => f.namespace === ns), (f) => ({
metadata:
{
name: f.id,
namespace: f.namespace,
selfLink: `/api/v1/namespaces/${f.namespace}/services/${f.id}`,
uid: '010a169d-618c-11e7-9939-080027abf356',
resourceVersion: '248',
creationTimestamp: '2017-07-05T14:12:39Z',
labels: { function: f.id },
},
spec:
{
ports: [{ protocol: 'TCP', port: 8080, targetPort: 8080, nodePort: 30817 }],
selector: { function: f.id },
clusterIP: '10.0.0.177',
type: 'NodePort',
sessionAffinity: 'None',
},
status: { loadBalancer: {} },
})),
})
.persist();
});

// Mock call to get.functions per namespace
const allFunctions = _.map(functions, (f) => (_.defaultsDeep({}, functionModif, {
Expand Down Expand Up @@ -192,7 +195,10 @@ describe('KubelessInfo', () => {
nock.cleanAll();
});
it('should return logs with the correct formating', () => {
mockGetCalls(config, [{ id: func, namespace: 'default' }]);
mockGetCalls(config, [
{ id: func, namespace: 'default' },
{ id: 'my-function-1', namespace: 'custom-1' },
]);
const kubelessInfo = new KubelessInfo(serverless, { function: func });
return expect(kubelessInfo.infoFunction({ color: false })).to.become(
infoMock(func)
Expand Down Expand Up @@ -242,7 +248,7 @@ describe('KubelessInfo', () => {
});
});
it('should return an error message if no function is found', (done) => {
mockGetCalls(config, []);
mockGetCalls(config, [{ id: 'other-function', namespace: 'custom-1' }]);
nock(config.clusters[0].cluster.server)
.get('/apis/kubeless.io/v1beta1/namespaces/custom-1/functions/my-function-1')
.reply(404, { code: 404 });
Expand Down
2 changes: 1 addition & 1 deletion test/kubelessInvoke.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ require('chai').use(chaiAsPromised);

function nocksvc(url, funcs) {
nock(url)
.get('/api/v1/services')
.get('/api/v1/namespaces/default/services')
.reply(200, {
items: _.map(_.flatten([funcs]), f => ({
metadata:
Expand Down
2 changes: 1 addition & 1 deletion test/lib/mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function createDeploymentNocks(endpoint, func, funcSpec, options) {
.reply(200, opts.postReply);
nock(endpoint)
.persist()
.get('/api/v1/pods')
.get(`/api/v1/namespaces/${opts.namespace}/pods`)
.reply(200, JSON.stringify({
items: [{
metadata: {
Expand Down

0 comments on commit f2aedb3

Please sign in to comment.