Skip to content

Commit

Permalink
replace existing job on re-run
Browse files Browse the repository at this point in the history
  • Loading branch information
cdupuis committed May 17, 2018
1 parent f06ebb9 commit db4da3f
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions src/handlers/events/delivery/goals/k8s/launchGoalK8.ts
Expand Up @@ -47,7 +47,7 @@ export const KubernetesIsolatedGoalLauncher = async (goal: OnAnyRequestedSdmGoal

const log = new StringCapturingProgressLog();

const spec = await spawnAndWatch({
let result = await spawnAndWatch({
command: "kubectl",
args: ["get", "deployment", deploymentName, "-n", deploymentNamespace, "-o", "json"],
},
Expand All @@ -58,8 +58,8 @@ export const KubernetesIsolatedGoalLauncher = async (goal: OnAnyRequestedSdmGoal
},
);

if (spec.code !== 0) {
return spec;
if (result.code !== 0) {
return result;
}

const jobSpec = JSON.parse(JobSpec);
Expand Down Expand Up @@ -99,10 +99,10 @@ export const KubernetesIsolatedGoalLauncher = async (goal: OnAnyRequestedSdmGoal
const tempfile = require("tempfile")(".json");
await fs.writeFile(tempfile, JSON.stringify(jobSpec, null, 2));

// TODO CD the following code needs to be replaced with proper job scheduling via k8-automation
return spawnAndWatch({
// Check if this job was previously launched
result = await spawnAndWatch({
command: "kubectl",
args: ["apply", "-f", tempfile],
args: ["get", "job", jobSpec.metadata.name, "-n", deploymentNamespace],
},
{},
progressLog,
Expand All @@ -111,6 +111,29 @@ export const KubernetesIsolatedGoalLauncher = async (goal: OnAnyRequestedSdmGoal
},
);

if (result.code !== 0) {
return spawnAndWatch({
command: "kubectl",
args: ["apply", "-f", tempfile],
},
{},
progressLog,
{
errorFinder: code => code !== 0,
},
);
} else {
return spawnAndWatch({
command: "kubectl",
args: ["replace", "--force", "-f", tempfile],
},
{},
progressLog,
{
errorFinder: code => code !== 0,
},
);
}
// query kube to make sure the job got scheduled
// kubectl get job <jobname> -o json
};
Expand Down

0 comments on commit db4da3f

Please sign in to comment.