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

feat(757): Pass disk annotation as toleration and node selector #39

Merged
merged 2 commits into from
Sep 11, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Member

@tkyi tkyi Sep 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.nodeSelectors will override nodeSelectors if there's any conflicts (https://github.com/hapijs/hoek/blob/master/API.md#mergetarget-source-isnulloverride-ismergearrays). Is this a concern at all?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it should be fine since we currently do not specify a default selector in regards to any resource.


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