Skip to content

Commit

Permalink
Add experimental volumes and volumeMounts properties to jobs (#966)
Browse files Browse the repository at this point in the history
* Update node_modules

Signed-off-by: Radu M <[email protected]>

* Add experimental volumeConfig property to jobs

Signed-off-by: Radu M <[email protected]>

* Update brigadier

Signed-off-by: Radu M <[email protected]>

* Split volumeConfig into volumes and volumeMounts

Signed-off-by: Radu M <[email protected]>

* Check volume refernced by volume mount exists

Signed-off-by: Radu M <[email protected]>

* Update brigadier + volume and mounts doc

Signed-off-by: Radu M <[email protected]>
  • Loading branch information
Radu M authored Aug 8, 2019
1 parent bb61a54 commit 8525067
Show file tree
Hide file tree
Showing 11 changed files with 569 additions and 145 deletions.
4 changes: 2 additions & 2 deletions brigade-worker/node_modules/.yarn-integrity

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

222 changes: 201 additions & 21 deletions brigade-worker/node_modules/@brigadecore/brigadier/LICENSE

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

22 changes: 21 additions & 1 deletion brigade-worker/node_modules/@brigadecore/brigadier/out/job.d.ts

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

2 changes: 2 additions & 0 deletions brigade-worker/node_modules/@brigadecore/brigadier/out/job.js

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

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

2 changes: 1 addition & 1 deletion brigade-worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"typescript": "^3.2.2"
},
"dependencies": {
"@brigadecore/brigadier": "^0.5.0",
"@brigadecore/brigadier": "^0.6.1",
"@kubernetes/client-node": "^0.10.1",
"byline": "^5.0.0",
"child-process-promise": "^2.2.1",
Expand Down
32 changes: 32 additions & 0 deletions brigade-worker/src/k8s.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,27 @@ export class JobRunner implements jobs.JobRunner {
}
}

// If the job defines volumes, add them to the pod's volume list.
// If the volume type is `hostPath`, first check if the project allows host mounts
// and throw an error if it it does not.
for (let v of job.volumes) {
if (v.hostPath != undefined && !project.allowHostMounts) {
throw new Error(`allowHostMounts is false in this project, not mounting ${v.hostPath.path}`);
}
this.runner.spec.volumes.push(v);
}

// If the job defines volume mounts, add them to every container's spec.
for (let m of job.volumeMounts) {
if (!volumeExists(m, job.volumes)) {
throw new Error(`volume ${m.name} referenced in volume mount is not defined`);
}

for (let i = 0; i < this.runner.spec.containers.length; i++) {
this.runner.spec.containers[i].volumeMounts.push(m);
}
}

if (job.args.length > 0) {
this.runner.spec.containers[0].args = job.args;
}
Expand Down Expand Up @@ -1094,3 +1115,14 @@ export function secretToProject(
}
return p;
}

// helper function to check if the volume referenced by a volume mount is defined by the job
function volumeExists(volumeMount: kubernetes.V1VolumeMount, volumes: kubernetes.V1Volume[]): boolean {
for (let v of volumes) {
if (volumeMount.name === v.name) {
return true;
}
}

return false;
}
Loading

0 comments on commit 8525067

Please sign in to comment.