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

Commit 247649e

Browse files
authored
Merge pull request #119 from andresmgot/label
Parse labels as strings
2 parents cc063bd + d10f4d5 commit 247649e

File tree

5 files changed

+40
-9
lines changed

5 files changed

+40
-9
lines changed

lib/deploy.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ const helpers = require('./helpers');
2424
const ingressHelper = require('./ingress');
2525
const moment = require('moment');
2626

27+
function forceString(obj) {
28+
const result = {};
29+
_.each(obj, (v, k) => {
30+
if (v === null) {
31+
result[k] = 'null';
32+
} else if (v === undefined) {
33+
result[k] = 'undefined';
34+
} else if (typeof v === 'object') {
35+
result[k] = JSON.stringify(v);
36+
} else {
37+
result[k] = v.toString();
38+
}
39+
});
40+
return result;
41+
}
42+
2743
function getFunctionDescription(
2844
funcName,
2945
namespace,
@@ -48,10 +64,10 @@ function getFunctionDescription(
4864
metadata: {
4965
name: funcName,
5066
namespace,
51-
labels: _.assign({}, labels, {
67+
labels: forceString(_.assign({}, labels, {
5268
'created-by': 'kubeless',
5369
function: funcName,
54-
}),
70+
})),
5571
},
5672
spec: {
5773
deps: deps || '',
@@ -68,9 +84,9 @@ function getFunctionDescription(
6884
protocol: 'TCP',
6985
targetPort: Number(port || 8080),
7086
}],
71-
selector: _.assign({}, labels, {
87+
selector: {
7288
function: funcName,
73-
}),
89+
},
7490
type: 'ClusterIP',
7591
},
7692
},

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "serverless-kubeless",
3-
"version": "0.4.1",
3+
"version": "0.4.2",
44
"description": "This plugin enables support for Kubeless within the [Serverless Framework](https://github.com/serverless).",
55
"main": "index.js",
66
"directories": {

test/examples-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ describe('Examples', () => {
532532
if (stdout.match(/mongodb-.*Running/)) {
533533
exec('kubectl logs -l io.kompose.service=mongodb', (lerr, logs) => {
534534
if (lerr) throw lerr;
535-
if (logs.match(/waiting for connections on port 27017/)) {
535+
if (logs.match(/Starting mongod/)) {
536536
clearInterval(wait);
537537
exec(
538538
'serverless info',

test/kubelessDeploy.test.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,15 +592,30 @@ describe('KubelessDeploy', () => {
592592
});
593593
it('should deploy a function with labels', () => {
594594
const serverlessWithCustomNamespace = _.cloneDeep(serverlessWithFunction);
595-
const labels = { label1: 'Test Label' };
595+
const labels = {
596+
label1: 'Test Label',
597+
label2: false,
598+
label3: null,
599+
label4: undefined,
600+
label5: 1,
601+
label6: { a: 1 },
602+
};
603+
const sLabels = {
604+
label1: 'Test Label',
605+
label2: 'false',
606+
label3: 'null',
607+
label4: 'undefined',
608+
label5: '1',
609+
label6: '{"a":1}',
610+
};
596611
serverlessWithCustomNamespace.service.functions[functionName].labels = labels;
597612
kubelessDeploy = instantiateKubelessDeploy(
598613
pkgFile,
599614
depsFile,
600615
serverlessWithCustomNamespace
601616
);
602617
mocks.createDeploymentNocks(
603-
config.clusters[0].cluster.server, functionName, defaultFuncSpec(), { labels });
618+
config.clusters[0].cluster.server, functionName, defaultFuncSpec(), { labels: sLabels });
604619
const result = expect( // eslint-disable-line no-unused-expressions
605620
kubelessDeploy.deployFunction()
606621
).to.be.fulfilled;

test/lib/mocks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ function createDeploymentNocks(endpoint, func, funcSpec, options) {
118118
};
119119
}
120120
if (opts.labels) {
121-
postBody.spec.service.selector = _.assign(postBody.spec.service.selector, opts.labels);
121+
postBody.spec.service.selector = _.assign(postBody.spec.service.selector);
122122
}
123123
nock(endpoint)
124124
.persist()

0 commit comments

Comments
 (0)