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

Commit

Permalink
feat(757): Pass disk annotation as toleration and node selector
Browse files Browse the repository at this point in the history
  • Loading branch information
Filbird committed Sep 10, 2018
1 parent 56c0c0f commit ace2144
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const MAXATTEMPTS = 5;
const RETRYDELAY = 3000;
const CPU_RESOURCE = 'beta.screwdriver.cd/cpu';
const RAM_RESOURCE = 'beta.screwdriver.cd/ram';
const DISK_RESOURCE = 'beta.screwdriver.cd/disk';
const ANNOTATION_BUILD_TIMEOUT = 'beta.screwdriver.cd/timeout';
const TOLERATIONS_PATH = 'spec.tolerations';
const AFFINITY_NODE_SELECTOR_PATH = 'spec.affinity.nodeAffinity.' +
Expand Down Expand Up @@ -224,7 +225,12 @@ class K8sVMExecutor extends Executor {

const podConfig = yaml.safeLoad(podTemplate);

setNodeSelector(podConfig, this.nodeSelectors);
const diskConfig = annotations[DISK_RESOURCE] || '';
const nodeSelectors = diskConfig.toUpperCase() === 'HIGH' ? { disk: 'high' } : {};

hoek.merge(nodeSelectors, this.nodeSelectors);

setNodeSelector(podConfig, nodeSelectors);
setPreferredNodeSelector(podConfig, this.preferredNodeSelectors);

const options = {
Expand Down
64 changes: 64 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,40 @@ describe('index', () => {
}
}
};
const testSpecWithDisk = {
tolerations: [{
key: 'disk',
value: 'high',
effect: 'NoSchedule',
operator: 'Equal'
}, {
key: 'key',
value: 'value',
effect: 'NoSchedule',
operator: 'Equal'
}],
affinity: {
nodeAffinity: {
requiredDuringSchedulingIgnoredDuringExecution: {
nodeSelectorTerms: [
{
matchExpressions: [{
key: 'disk',
operator: 'In',
values: ['high']
}]
}, {
matchExpressions: [{
key: 'key',
operator: 'In',
values: ['value']
}]
}
]
}
}
}
};
const testPreferredSpec = {
affinity: {
nodeAffinity: {
Expand Down Expand Up @@ -493,6 +527,36 @@ describe('index', () => {
});
});

it('sets disk toleration and node affinity when disk is HIGH', () => {
fakeStartConfig.annotations = { 'beta.screwdriver.cd/disk': 'HIGH' };
const spec = _.merge({}, testSpecWithDisk, testPodSpec);

postConfig.body.spec = spec;

executor = new Executor({
ecosystem: {
api: testApiUri,
store: testStoreUri
},
fusebox: { retry: { minTimeout: 1 } },
kubernetes: {
nodeSelectors: { key: 'value' },
token: 'api_key',
host: 'kubernetes.default',
baseImage: 'hyperctl'
},
prefix: 'beta_'
});

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);

Expand Down

0 comments on commit ace2144

Please sign in to comment.