From 46688a664cd911d3df38aa725eaf5ea987ecedcf Mon Sep 17 00:00:00 2001 From: Tiffany Kyi Date: Thu, 20 Jun 2019 15:32:35 -0700 Subject: [PATCH] fix: Do not set disk toleration when annotation is not set --- index.js | 5 +++-- test/index.test.js | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 26e56df..6150d91 100644 --- a/index.js +++ b/index.js @@ -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); } diff --git a/test/index.test.js b/test/index.test.js index 7b3e80a..bc12640 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -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, { @@ -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, {