Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 35 additions & 10 deletions lib/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ function getFunctionDescription(
secrets,
cpu,
affinity,
tolerations
tolerations,
volumes,
volumeMounts
) {
const funcs = {
apiVersion: 'kubeless.io/v1beta1',
Expand Down Expand Up @@ -119,7 +121,8 @@ function getFunctionDescription(
if (desc) {
funcs.metadata.annotations['kubeless.serverless.com/description'] = desc;
}
if (image || env || memory || secrets || cpu || affinity || tolerations) {

if (image || env || memory || secrets || cpu || affinity || tolerations || volumes) {
const container = {
name: funcName,
};
Expand Down Expand Up @@ -154,20 +157,37 @@ function getFunctionDescription(
},
},
};

// convert secretes to volumes and volume mounts
if (secrets !== undefined && secrets.length > 0) {
if (container.volumeMounts === undefined) {
container.volumeMounts = [];
if (volumes === undefined) {
// eslint-disable-next-line no-param-reassign
volumes = [];
}
if (funcs.spec.deployment.spec.template.spec.volumes === undefined) {
funcs.spec.deployment.spec.template.spec.volumes = [];
if (volumeMounts === undefined) {
// eslint-disable-next-line no-param-reassign
volumeMounts = [];
}
secrets.forEach(secret => {
container.volumeMounts.push({ name: `${secret}-vol`, mountPath: `/${secret}` });
funcs.spec.deployment.spec.template.spec.volumes
.push({ name: `${secret}-vol`, secret: { secretName: secret } });
volumes.push({
name: `${secret}-vol`,
secret: { secretName: secret },
});
volumeMounts.push({
mountPath: `/${secret}`,
name: `${secret}-vol`,
});
});
}

if (volumes !== undefined && volumes.length > 0) {
funcs.spec.deployment.spec.template.spec.volumes = volumes;
}

if (volumeMounts !== undefined && volumeMounts.length > 0) {
container.volumeMounts = volumeMounts;
}

if (affinity) {
funcs.spec.deployment.spec.template.spec.affinity = affinity;
}
Expand All @@ -178,6 +198,7 @@ function getFunctionDescription(
return funcs;
}


function waitForDeployment(funcName, requestMoment, namespace, options) {
const opts = _.defaults({}, options, {
verbose: false,
Expand Down Expand Up @@ -420,6 +441,7 @@ function deployFunction(f, namespace, runtime, contentType, options) {
const fenv = parseEnv(f.environment);
environment = environment ? environment.concat(fenv) : fenv;
}

const funcs = getFunctionDescription(
f.id,
namespace,
Expand All @@ -441,8 +463,11 @@ function deployFunction(f, namespace, runtime, contentType, options) {
f.secrets,
f.cpu || options.cpu,
f.affinity || options.affinity,
f.tolerations || options.tolerations
f.tolerations || options.tolerations,
f.volumes || options.volumes,
f.volumeMounts || options.volumeMounts
);

return functionsApi.getItem(funcs.metadata.name).then((res) => {
if (res.code === 404) {
return deployFunctionAndWait(
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.8.3",
"version": "0.9.0",
"description": "This plugin enables support for Kubeless within the [Serverless Framework](https://github.com/serverless).",
"main": "index.js",
"directories": {
Expand Down
45 changes: 41 additions & 4 deletions test/kubelessDeploy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,9 @@ describe('KubelessDeploy', () => {
const serverlessWithSecrets = _.cloneDeep(serverlessWithFunction);
serverlessWithSecrets.service.functions.myFunction.secrets = ['secret1'];
kubelessDeploy = instantiateKubelessDeploy(
pkgFile,
depsFile,
serverlessWithSecrets
pkgFile,
depsFile,
serverlessWithSecrets
);
mocks.createDeploymentNocks(config.clusters[0].cluster.server, functionName, defaultFuncSpec({
deployment: {
Expand All @@ -387,9 +387,46 @@ describe('KubelessDeploy', () => {
},
}));
return expect( // eslint-disable-line no-unused-expressions
kubelessDeploy.deployFunction()
kubelessDeploy.deployFunction()
).to.be.fulfilled;
});
it('should deploy a function with volumes', () => {
const serverlessWithVolumes = _.cloneDeep(serverlessWithFunction);
serverlessWithVolumes.service.functions.myFunction.volumes = [{
name: 'vol1',
persistentVolumeClaim: {
claimName: 'vol-claim',
},
}];
serverlessWithVolumes.service.functions.myFunction.volumeMounts = [{
name: 'vol1',
mountPath: '/foo/bar',
}];
kubelessDeploy = instantiateKubelessDeploy(
pkgFile,
depsFile,
serverlessWithVolumes
);
mocks.createDeploymentNocks(config.clusters[0].cluster.server, functionName, defaultFuncSpec({
deployment: {
spec: {
template: {
spec: {
containers: [{
name: functionName,
volumeMounts: [{ name: 'vol1', mountPath: '/foo/bar' }],
}],
volumes: [{ name: 'vol1', persistentVolumeClaim: { claimName: 'vol-claim' } }],
},
},
},
},
}));
return expect( // eslint-disable-line no-unused-expressions
kubelessDeploy.deployFunction()
).to.be.fulfilled;
});


it('should wait until a deployment is ready', () => {
const funcSpec = defaultFuncSpec();
Expand Down