Skip to content
This repository has been archived by the owner on Sep 6, 2024. It is now read-only.

Commit

Permalink
fix: Do not set disk toleration when annotation is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
tkyi committed Jun 20, 2019
1 parent abaaf8d commit 46688a6
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,15 @@ class K8sVMExecutor extends Executor {

if (this.diskLabel) {
const diskConfig = (annotations[DISK_RESOURCE] || '').toLowerCase();
const diskSelectors = { [this.diskLabel]: diskConfig };
const diskSelectors = diskConfig ? { [this.diskLabel]: diskConfig } : {};

hoek.merge(nodeSelectors, diskSelectors);
}

if (this.diskSpeedLabel) {
const diskSpeedConfig = (annotations[DISK_SPEED_RESOURCE] || '').toLowerCase();
const diskSpeedSelectors = { [this.diskSpeedLabel]: diskSpeedConfig };
const diskSpeedSelectors = diskSpeedConfig ?
{ [this.diskSpeedLabel]: diskSpeedConfig } : {};

hoek.merge(nodeSelectors, diskSpeedSelectors);
}
Expand Down
54 changes: 54 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,33 @@ describe('index', () => {
});
});

it('does not set disk toleration and node affinity when disk is not set', () => {
fakeStartConfig.annotations = {};
const spec = _.merge({}, testSpec, testPodSpec);
const options = _.assign({}, executorOptions, {
kubernetes: {
nodeSelectors: { key: 'value' },
token: 'api_key',
host: 'kubernetes.default',
baseImage: 'hyperctl',
resources: {
disk: {
space: 'screwdriver.cd/disk'
}
}
}
});

executor = new Executor(options);
postConfig.body.spec = spec;
getConfig.retryStrategy = executor.podRetryStrategy;

return executor.start(fakeStartConfig).then(() => {
assert.calledWith(requestRetryMock.firstCall, postConfig);
assert.calledWith(requestRetryMock.secondCall, sinon.match(getConfig));
});
});

it('sets disk speed toleration and node affinity when diskSpeed is HIGH', () => {
const spec = _.merge({}, testSpecWithDiskSpeed, testPodSpec);
const options = _.assign({}, executorOptions, {
Expand Down Expand Up @@ -701,6 +728,33 @@ describe('index', () => {
});
});

it('does not set disk speed toleration when disk speed is not set', () => {
fakeStartConfig.annotations = {};
const spec = _.merge({}, testSpec, testPodSpec);
const options = _.assign({}, executorOptions, {
kubernetes: {
nodeSelectors: { key: 'value' },
token: 'api_key',
host: 'kubernetes.default',
baseImage: 'hyperctl',
resources: {
disk: {
speed: 'screwdriver.cd/diskspeed'
}
}
}
});

executor = new Executor(options);
postConfig.body.spec = spec;
getConfig.retryStrategy = executor.podRetryStrategy;

return executor.start(fakeStartConfig).then(() => {
assert.calledWith(requestRetryMock.firstCall, postConfig);
assert.calledWith(requestRetryMock.secondCall, sinon.match(getConfig));
});
});

it('sets preferred node affinity with appropriate node config', () => {
const spec = _.merge({}, testPreferredSpec, testPodSpec);
const options = _.assign({}, executorOptions, {
Expand Down

0 comments on commit 46688a6

Please sign in to comment.