Skip to content

Commit ad191e9

Browse files
authored
feat(runner): support custom job template
1 parent 6ac9a53 commit ad191e9

File tree

12 files changed

+71
-20
lines changed

12 files changed

+71
-20
lines changed

docs/devguide/docs/swagger-docs.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2359,6 +2359,9 @@ components:
23592359
description: Percentage of the score affected by requests per second results.
23602360
allOf:
23612361
- $ref: '#/components/schemas/benchmark_weights'
2362+
custom_runner_definition:
2363+
description: custom json that will be merged with the kubernetes/metronome predator runner job definition
2364+
type: object
23622365
benchmark_weights:
23632366
type: object
23642367
required:

docs/openapi3.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2326,6 +2326,9 @@ components:
23262326
description: Percentage of the score affected by requests per second results.
23272327
allOf:
23282328
- $ref: '#/components/schemas/benchmark_weights'
2329+
custom_runner_definition:
2330+
description: custom json that will be merged with the kubernetes/metronome predator runner job definition
2331+
type: object
23292332
benchmark_weights:
23302333
type: object
23312334
required:

src/common/consts.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module.exports = {
3030
SMTP_SERVER: 'smtp_server',
3131
BENCHMARK_THRESHOLD: 'benchmark_threshold',
3232
BENCHMARK_THRESHOLD_WEBHOOK_URL: 'benchmark_threshold_webhook_url',
33-
BENCHMARK_WEIGHTS: 'benchmark_weights'
33+
BENCHMARK_WEIGHTS: 'benchmark_weights',
34+
CUSTOM_RUNNER_DEFINITION: 'custom_runner_definition'
3435
}
3536
};

src/configManager/helpers/configDataMap.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ let configDataMap = {
4040
},
4141
[constConfig.BENCHMARK_THRESHOLD]: { value: process.env.BENCHMARK_THRESHOLD, type: 'int' },
4242
[constConfig.BENCHMARK_THRESHOLD_WEBHOOK_URL]: { value: process.env.BENCHMARK_THRESHOLD_WEBHOOK_URL, type: 'string' },
43-
[constConfig.BENCHMARK_WEIGHTS]: { value: process.env.BENCHMARK_WEIGHTS || JSON.stringify(BENCHMARK_WEIGHTS_DEFAULT), type: 'json' }
43+
[constConfig.BENCHMARK_WEIGHTS]: { value: process.env.BENCHMARK_WEIGHTS || JSON.stringify(BENCHMARK_WEIGHTS_DEFAULT), type: 'json' },
44+
[constConfig.CUSTOM_RUNNER_DEFINITION]: { value: process.env.CUSTOM_RUNNER_DEFINITION, type: 'json' }
45+
4446
};
4547

4648
module.exports.getConstType = (configValue) => {

src/jobs/models/jobManager.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ function createJobRequest(jobId, runId, jobBody, dockerImage, configData) {
258258
});
259259
}
260260

261-
let jobRequest = jobTemplate.createJobRequest(jobName, runId, parallelism, environmentVariables, dockerImage, configData, PREDATOR_RUNNER_PREFIX);
261+
const customRunnerDefinition = configData.custom_runner_definition;
262+
let jobRequest = jobTemplate.createJobRequest(jobName, runId, parallelism, environmentVariables, dockerImage, configData, PREDATOR_RUNNER_PREFIX, customRunnerDefinition);
262263

263264
return jobRequest;
264265
}

src/jobs/models/kubernetes/jobTemplate.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
module.exports.createJobRequest = (jobName, runId, parallelism, environmentVariables, dockerImage, configData, predatorRunner) => {
2-
return {
1+
const _ = require('lodash');
2+
3+
module.exports.createJobRequest = (jobName, runId, parallelism, environmentVariables, dockerImage, configData, predatorRunner, customDefinition) => {
4+
const jobTemplate = {
35
'apiVersion': 'batch/v1',
46
'kind': 'Job',
57
'metadata': {
@@ -36,4 +38,7 @@ module.exports.createJobRequest = (jobName, runId, parallelism, environmentVaria
3638
'backoffLimit': 0
3739
}
3840
};
41+
42+
const jobTemplateWithCustomDefinition = _.merge(jobTemplate, customDefinition);
43+
return jobTemplateWithCustomDefinition;
3944
};

src/jobs/models/metronome/jobTemplate.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
module.exports.createJobRequest = (jobName, runId, parallelism, environmentVariables, dockerImage, configData) => {
2-
return {
1+
const _ = require('lodash');
2+
3+
module.exports.createJobRequest = (jobName, runId, parallelism, environmentVariables, dockerImage, configData, customDefinition) => {
4+
const jobTemplate = {
35
id: jobName,
46
description: 'Runs a performance test',
57
run: {
@@ -14,4 +16,7 @@ module.exports.createJobRequest = (jobName, runId, parallelism, environmentVaria
1416
},
1517
parallelism: parallelism
1618
};
19+
20+
const jobTemplateWithCustomDefinition = _.merge(jobTemplate, customDefinition);
21+
return jobTemplateWithCustomDefinition;
1722
};

tests/integration-tests/jobs/createJobDocker-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('Create job specific docker tests', async function () {
2929
nock.cleanAll();
3030
});
3131
const jobPlatform = process.env.JOB_PLATFORM;
32-
if (jobPlatform === 'DOCKER') {
32+
if (jobPlatform.toUpperCase() === 'DOCKER') {
3333
describe('DOCKER', () => {
3434
before(async () => {
3535
await schedulerRequestCreator.init();

tests/integration-tests/jobs/createJobKubernetes-test.js

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const should = require('should'),
22
uuid = require('uuid'),
33
schedulerRequestCreator = require('./helpers/requestCreator'),
4+
configManagerRequestCreator = require('../configManager/helpers/requestCreator'),
45
testsRequestCreator = require('../tests/helpers/requestCreator'),
56
nock = require('nock'),
67
kubernetesConfig = require('../../../src/config/kubernetesConfig');
@@ -13,10 +14,11 @@ describe('Create job specific kubernetes tests', async function () {
1314
nock.cleanAll();
1415
});
1516
const jobPlatform = process.env.JOB_PLATFORM;
16-
if (jobPlatform === 'KUBERNETES') {
17+
if (jobPlatform.toUpperCase() === 'KUBERNETES') {
1718
describe('Kubernetes', () => {
1819
describe('Good requests', () => {
1920
before(async () => {
21+
await configManagerRequestCreator.init();
2022
await schedulerRequestCreator.init();
2123
await testsRequestCreator.init();
2224

@@ -101,7 +103,8 @@ describe('Create job specific kubernetes tests', async function () {
101103
arrival_rate: 1,
102104
duration: 1,
103105
environment: 'test',
104-
enabled: true });
106+
enabled: true
107+
});
105108

106109
should(relevantJobs).containEql({
107110
id: cronJobId,
@@ -285,11 +288,23 @@ describe('Create job specific kubernetes tests', async function () {
285288
});
286289
});
287290

288-
describe('Create one time job with parallelism, should create job with the right parameters and run it, finally stop and delete it', () => {
291+
describe('Create one time job with parallelism and custom runner definition, should create job with the right parameters and run it, finally stop and delete it', () => {
289292
let createJobResponse;
290293
let getJobsFromService;
291294
let expectedResult;
292295
it('Create the job', async () => {
296+
await configManagerRequestCreator.updateConfig({ custom_runner_definition: {
297+
'spec': {
298+
'template': {
299+
'metadata': {
300+
'annotations': {
301+
'traffic.sidecar.istio.io/excludeOutboundPorts': '8060'
302+
}
303+
}
304+
}
305+
}
306+
} });
307+
293308
let validBody = {
294309
test_id: testId,
295310
arrival_rate: 100,
@@ -310,7 +325,9 @@ describe('Create job specific kubernetes tests', async function () {
310325
parallelism: 7
311326
};
312327
let actualJobEnvVars = {};
328+
let actualAnnotations = {};
313329
nock(kubernetesConfig.kubernetesUrl).post(`/apis/batch/v1/namespaces/${kubernetesConfig.kubernetesNamespace}/jobs`, body => {
330+
actualAnnotations = body.spec.template.metadata.annotations;
314331
actualJobEnvVars = body.spec.template.spec.containers['0'].env;
315332
return true;
316333
}).reply(200, {
@@ -337,6 +354,7 @@ describe('Create job specific kubernetes tests', async function () {
337354
should(rampTo.value).eql('22');
338355
should(arrivalRate.value).eql('15');
339356
should(maxVirtualUsers.value).eql('29');
357+
should(actualAnnotations).eql({ 'traffic.sidecar.istio.io/excludeOutboundPorts': '8060' });
340358
});
341359

342360
it('Get the job', async () => {
@@ -391,18 +409,30 @@ describe('Create job specific kubernetes tests', async function () {
391409
nock(kubernetesConfig.kubernetesUrl).get(`/api/v1/namespaces/${kubernetesConfig.kubernetesNamespace}/pods/podA`)
392410
.reply(200, {
393411
metadata: { labels: { 'job-name': 'predator.job' } },
394-
status: { containerStatuses: [{ name: 'predator-runner',
395-
state: { terminated: { finishedAt: '2020' } } }, { name: 'podB',
396-
state: {} }] }
412+
status: {
413+
containerStatuses: [{
414+
name: 'predator-runner',
415+
state: { terminated: { finishedAt: '2020' } }
416+
}, {
417+
name: 'podB',
418+
state: {}
419+
}]
420+
}
397421

398422
});
399423

400424
nock(kubernetesConfig.kubernetesUrl).get(`/api/v1/namespaces/${kubernetesConfig.kubernetesNamespace}/pods/podB`)
401425
.reply(200, {
402426
metadata: { labels: { 'job-name': 'someJob.job' } },
403-
status: { containerStatuses: [{ name: 'podC',
404-
state: { terminated: { finishedAt: '2020' } } }, { name: 'podD',
405-
state: {} }] }
427+
status: {
428+
containerStatuses: [{
429+
name: 'podC',
430+
state: { terminated: { finishedAt: '2020' } }
431+
}, {
432+
name: 'podD',
433+
state: {}
434+
}]
435+
}
406436

407437
});
408438

tests/integration-tests/jobs/createJobMetronome-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('Create job specific metronome tests', async function () {
1313
nock.cleanAll();
1414
});
1515
const jobPlatform = process.env.JOB_PLATFORM;
16-
if (jobPlatform === 'METRONOME') {
16+
if (jobPlatform.toUpperCase() === 'METRONOME') {
1717
describe('Metronome', () => {
1818
before(async () => {
1919
await schedulerRequestCreator.init();
@@ -204,4 +204,4 @@ describe('Create job specific metronome tests', async function () {
204204
});
205205
});
206206
}
207-
});
207+
});

0 commit comments

Comments
 (0)