Skip to content

Commit

Permalink
feat(#2830): format and store buildCluster name (#572)
Browse files Browse the repository at this point in the history
  • Loading branch information
pritamstyz4ever authored Feb 2, 2023
1 parent 0a43a7b commit 4ffe088
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 22 deletions.
11 changes: 7 additions & 4 deletions lib/buildFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,21 @@ class BuildFactory extends BaseFactory {
const permutation = job.permutations[index];
const annotations = hoek.reach(job.permutations[0], 'annotations', { default: {} });
let buildClusterName;
let bookendClusterName;

if (String(this.multiBuildClusterEnabled) === 'true') {
buildClusterName = await helper.getBuildClusterName({
annotations,
pipeline
});
bookendClusterName = buildClusterName;
}
if (hoek.reach(permutation, 'provider')) {
const { provider } = permutation;

if (provider && provider.name) {
buildClusterName = provider.name;
if (provider) {
buildClusterName = `${provider.name}-${provider.executor}-${provider.accountId}`;
bookendClusterName = provider.name;
}
}

Expand Down Expand Up @@ -251,8 +254,8 @@ class BuildFactory extends BaseFactory {
}

const [setup, teardown] = await Promise.all([
this.bookend.getSetupCommands(bookendConfig, buildClusterName),
this.bookend.getTeardownCommands(bookendConfig, buildClusterName)
this.bookend.getSetupCommands(bookendConfig, bookendClusterName),
this.bookend.getTeardownCommands(bookendConfig, bookendClusterName)
]);

modelConfig.createTime = new Date(number).toISOString();
Expand Down
File renamed without changes.
47 changes: 29 additions & 18 deletions test/lib/buildFactory.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,9 @@ describe('Build Factory', () => {
environment: { NODE_ENV: 'test', NODE_VERSION: '4' },
image: 'node:4',
provider: {
name: 'aws'
name: 'aws',
executor: 'sls',
accountId: '123456789012'
}
},
{
Expand Down Expand Up @@ -639,7 +641,7 @@ describe('Build Factory', () => {
});
});

it('sets build cluster from provider if available', () => {
it('sets build cluster from provider as providerName-executor-accountId if available', () => {
const user = { unsealToken: sinon.stub().resolves('foo') };
const jobMock = {
permutations: permutationsWithProvider,
Expand All @@ -650,7 +652,7 @@ describe('Build Factory', () => {
jobFactoryMock.get.resolves(jobMock);
userFactoryMock.get.resolves(user);
delete saveConfig.params.commit;
saveConfig.params.buildClusterName = 'aws';
saveConfig.params.buildClusterName = 'aws-sls-123456789012';

return factory
.create({
Expand Down Expand Up @@ -1000,11 +1002,12 @@ describe('Build Factory', () => {
});
});

it('passes buildClusterName from provider config to the bookend config', () => {
it('passes buildClusterName as provider.name from provider config to the bookend config', () => {
const pipelineMock = {
configPipelineId: 2,
configPipeline: Promise.resolve({ spooky: 'ghost' })
};
const bookendClusterName = 'aws';
const jobMock = {
permutations: permutationsWithProvider,
pipeline: Promise.resolve(pipelineMock)
Expand All @@ -1023,20 +1026,28 @@ describe('Build Factory', () => {
meta
})
.then(() => {
assert.calledWith(bookendMock.getSetupCommands, {
pipeline: pipelineMock,
job: jobMock,
build: sinon.match.object,
configPipeline: { spooky: 'ghost' },
configPipelineSha
});
assert.calledWith(bookendMock.getTeardownCommands, {
pipeline: pipelineMock,
job: jobMock,
build: sinon.match.object,
configPipeline: { spooky: 'ghost' },
configPipelineSha
});
assert.calledWith(
bookendMock.getSetupCommands,
{
pipeline: pipelineMock,
job: jobMock,
build: sinon.match.object,
configPipeline: { spooky: 'ghost' },
configPipelineSha
},
bookendClusterName
);
assert.calledWith(
bookendMock.getTeardownCommands,
{
pipeline: pipelineMock,
job: jobMock,
build: sinon.match.object,
configPipeline: { spooky: 'ghost' },
configPipelineSha
},
bookendClusterName
);
});
});
});
Expand Down

0 comments on commit 4ffe088

Please sign in to comment.