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

Commit

Permalink
Merge pull request #119 from andresmgot/label
Browse files Browse the repository at this point in the history
Parse labels as strings
  • Loading branch information
andresmgot authored May 21, 2018
2 parents cc063bd + d10f4d5 commit 247649e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
24 changes: 20 additions & 4 deletions lib/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ const helpers = require('./helpers');
const ingressHelper = require('./ingress');
const moment = require('moment');

function forceString(obj) {
const result = {};
_.each(obj, (v, k) => {
if (v === null) {
result[k] = 'null';
} else if (v === undefined) {
result[k] = 'undefined';
} else if (typeof v === 'object') {
result[k] = JSON.stringify(v);
} else {
result[k] = v.toString();
}
});
return result;
}

function getFunctionDescription(
funcName,
namespace,
Expand All @@ -48,10 +64,10 @@ function getFunctionDescription(
metadata: {
name: funcName,
namespace,
labels: _.assign({}, labels, {
labels: forceString(_.assign({}, labels, {
'created-by': 'kubeless',
function: funcName,
}),
})),
},
spec: {
deps: deps || '',
Expand All @@ -68,9 +84,9 @@ function getFunctionDescription(
protocol: 'TCP',
targetPort: Number(port || 8080),
}],
selector: _.assign({}, labels, {
selector: {
function: funcName,
}),
},
type: 'ClusterIP',
},
},
Expand Down
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.4.1",
"version": "0.4.2",
"description": "This plugin enables support for Kubeless within the [Serverless Framework](https://github.com/serverless).",
"main": "index.js",
"directories": {
Expand Down
2 changes: 1 addition & 1 deletion test/examples-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ describe('Examples', () => {
if (stdout.match(/mongodb-.*Running/)) {
exec('kubectl logs -l io.kompose.service=mongodb', (lerr, logs) => {
if (lerr) throw lerr;
if (logs.match(/waiting for connections on port 27017/)) {
if (logs.match(/Starting mongod/)) {
clearInterval(wait);
exec(
'serverless info',
Expand Down
19 changes: 17 additions & 2 deletions test/kubelessDeploy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,15 +592,30 @@ describe('KubelessDeploy', () => {
});
it('should deploy a function with labels', () => {
const serverlessWithCustomNamespace = _.cloneDeep(serverlessWithFunction);
const labels = { label1: 'Test Label' };
const labels = {
label1: 'Test Label',
label2: false,
label3: null,
label4: undefined,
label5: 1,
label6: { a: 1 },
};
const sLabels = {
label1: 'Test Label',
label2: 'false',
label3: 'null',
label4: 'undefined',
label5: '1',
label6: '{"a":1}',
};
serverlessWithCustomNamespace.service.functions[functionName].labels = labels;
kubelessDeploy = instantiateKubelessDeploy(
pkgFile,
depsFile,
serverlessWithCustomNamespace
);
mocks.createDeploymentNocks(
config.clusters[0].cluster.server, functionName, defaultFuncSpec(), { labels });
config.clusters[0].cluster.server, functionName, defaultFuncSpec(), { labels: sLabels });
const result = expect( // eslint-disable-line no-unused-expressions
kubelessDeploy.deployFunction()
).to.be.fulfilled;
Expand Down
2 changes: 1 addition & 1 deletion test/lib/mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function createDeploymentNocks(endpoint, func, funcSpec, options) {
};
}
if (opts.labels) {
postBody.spec.service.selector = _.assign(postBody.spec.service.selector, opts.labels);
postBody.spec.service.selector = _.assign(postBody.spec.service.selector);
}
nock(endpoint)
.persist()
Expand Down

0 comments on commit 247649e

Please sign in to comment.