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

Commit 22c31fd

Browse files
authored
Merge pull request #106 from gimlet2/secrets
Add Secrets support
2 parents 2fdd77a + 3837497 commit 22c31fd

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

lib/deploy.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ function getFunctionDescription(
4141
eventTrigger,
4242
eventSchedule,
4343
timeout,
44-
port
44+
port,
45+
secrets
4546
) {
4647
const funcs = {
4748
apiVersion: 'k8s.io/v1',
@@ -79,7 +80,7 @@ function getFunctionDescription(
7980
if (labels) {
8081
funcs.metadata.labels = labels;
8182
}
82-
if (image || env || memory) {
83+
if (image || env || memory || secrets) {
8384
const container = {
8485
name: funcName,
8586
};
@@ -113,6 +114,19 @@ function getFunctionDescription(
113114
funcs.spec.template = {
114115
spec: { containers: [container] },
115116
};
117+
if (secrets !== undefined && secrets.length > 0) {
118+
if (container.volumeMounts === undefined) {
119+
container.volumeMounts = [];
120+
}
121+
if (funcs.spec.template.spec.volumes === undefined) {
122+
funcs.spec.template.spec.volumes = [];
123+
}
124+
secrets.forEach(secret => {
125+
container.volumeMounts.push({ name: `${secret}-vol`, mountPath: `/${secret}` });
126+
funcs.spec.template.spec.volumes
127+
.push({ name: `${secret}-vol`, secret: { secretName: secret } });
128+
});
129+
}
116130
}
117131
switch (eventType) {
118132
case 'http':
@@ -337,7 +351,8 @@ function deploy(functions, runtime, options) {
337351
event.trigger,
338352
event.schedule,
339353
description.timeout || opts.timeout,
340-
description.port
354+
description.port,
355+
description.secrets
341356
);
342357
let deploymentPromise = null;
343358
let redeployed = false;

test/kubelessDeploy.test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,40 @@ describe('KubelessDeploy', () => {
323323
kubelessDeploy.deployFunction()
324324
).to.be.fulfilled;
325325
});
326+
it('should deploy a function with Secrets', () => {
327+
const serverlessWithSecrets = _.cloneDeep(serverlessWithFunction);
328+
serverlessWithSecrets.service.functions.myFunction.secrets = ['secret1'];
329+
kubelessDeploy = instantiateKubelessDeploy(
330+
pkgFile,
331+
depsFile,
332+
serverlessWithSecrets
333+
);
334+
mocks.createDeploymentNocks(config.clusters[0].cluster.server, functionName, {
335+
deps: '',
336+
function: functionText,
337+
handler: serverlessWithFunction.service.functions[functionName].handler,
338+
runtime: serverlessWithFunction.service.provider.runtime,
339+
type: 'HTTP',
340+
}, {
341+
deps: '',
342+
function: functionText,
343+
handler: serverlessWithFunction.service.functions[functionName].handler,
344+
runtime: serverlessWithFunction.service.provider.runtime,
345+
type: 'HTTP',
346+
template: {
347+
spec: {
348+
containers: [{
349+
name: functionName,
350+
volumeMounts: [{ name: 'secret1-vol', mountPath: '/secret1' }],
351+
}],
352+
volumes: [{ name: 'secret1-vol', secret: { secretName: 'secret1' } }],
353+
},
354+
},
355+
});
356+
return expect( // eslint-disable-line no-unused-expressions
357+
kubelessDeploy.deployFunction()
358+
).to.be.fulfilled;
359+
});
326360

327361
it('should wait until a deployment is ready', () => {
328362
const funcSpec = {

0 commit comments

Comments
 (0)