Skip to content
Permalink
Browse files

Actually use the job shell when defining the container cmd

Fix default case and add test for job shell
  • Loading branch information
radu-matei committed Jan 7, 2019
1 parent 2738b29 commit 1b8594e3cf24351a0a558801eebed986f3ca2504
Showing with 31 additions and 9 deletions.
  1. +16 −9 brigade-worker/src/k8s.ts
  2. +15 −0 brigade-worker/test/k8s.ts
@@ -238,7 +238,7 @@ export class JobRunner implements jobs.JobRunner {
pod: kubernetes.V1Pod;
cancel: boolean;
reconnect: boolean;

constructor() {}

/**
@@ -273,7 +273,8 @@ export class JobRunner implements jobs.JobRunner {
this.serviceAccount,
job.resourceRequests,
job.resourceLimits,
job.annotations
job.annotations,
job.shell
);

// Experimenting with setting a deadline field after which something
@@ -454,7 +455,7 @@ export class JobRunner implements jobs.JobRunner {
// appended to job name.
return `${this.project.name.replace(/[.\/]/g, "-")}-${
this.job.name
}`.toLowerCase();
}`.toLowerCase();
}

public logs(): Promise<string> {
@@ -558,7 +559,7 @@ export class JobRunner implements jobs.JobRunner {
private startUpdatingPod(): request.Request {
const url = `${kc.getCurrentCluster().server}/api/v1/namespaces/${
this.project.kubernetes.namespace
}/pods`;
}/pods`;
const requestOptions = {
qs: {
watch: true,
@@ -649,11 +650,11 @@ export class JobRunner implements jobs.JobRunner {
clearTimers();
let result = new K8sResult(phase);
resolve(result);
}
}
// make sure Pod is running before we start following its logs
else if (phase == "Running") {
else if (phase == "Running") {
// do that only if we haven't hooked up the follow request before
if (followLogsRequest == null && this.job.streamLogs) {
if (followLogsRequest == null && this.job.streamLogs) {
followLogsRequest = followLogs(this.pod.metadata.namespace, this.pod.metadata.name);
}
} else if (phase == "Failed") {
@@ -870,7 +871,8 @@ function newRunnerPod(
serviceAccount: string,
resourceRequests: jobs.JobResourceRequest,
resourceLimits: jobs.JobResourceLimit,
jobAnnotations: { [key: string]: string }
jobAnnotations: { [key: string]: string },
jobShell: string
): kubernetes.V1Pod {
let pod = new kubernetes.V1Pod();
pod.metadata = new kubernetes.V1ObjectMeta();
@@ -884,7 +886,12 @@ function newRunnerPod(
let c1 = new kubernetes.V1Container();
c1.name = "brigaderun";
c1.image = brigadeImage;
c1.command = ["/bin/sh", "/hook/main.sh"];

if (jobShell == "") {
jobShell = "/bin/sh";
}
c1.command = [jobShell, "/hook/main.sh"];

c1.imagePullPolicy = imageForcePull ? "Always" : "IfNotPresent";
c1.securityContext = new kubernetes.V1SecurityContext();

@@ -508,6 +508,21 @@ describe("k8s", function() {
);
});
});
context("when no job shell is specified", function() {
it("default shell is /bin/sh", function() {
let jr = new k8s.JobRunner().init(j, e, p);
assert.deepEqual(jr.runner.spec.containers[0].command, [ '/bin/sh', '/hook/main.sh' ]);
});
});
context("when job shell is specified", function() {
beforeEach(function() {
j.shell = "/bin/bash"
});
it("shell is /bin/bash", function() {
let jr = new k8s.JobRunner().init(j, e, p);
assert.deepEqual(jr.runner.spec.containers[0].command, [ '/bin/bash', '/hook/main.sh' ]);
});
});
});
});
});

0 comments on commit 1b8594e

Please sign in to comment.
You can’t perform that action at this time.