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

Commit

Permalink
Merge branch 'master' into disk
Browse files Browse the repository at this point in the history
  • Loading branch information
minzcmu authored Sep 11, 2018
2 parents ace2144 + 2cf85a8 commit cf22ae7
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 3 deletions.
35 changes: 35 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,32 @@ class K8sVMExecutor extends Executor {
this.preferredNodeSelectors = hoek.reach(options, 'kubernetes.preferredNodeSelectors');
}

/**
* Update build status message
* @method updateStatusMessage
* @param {Object} config build config of the job
* @param {String} config.apiUri screwdriver base api uri
* @param {Number} config.buildId build id
* @param {String} config.statusMessage build status message
* @param {String} config.token build temporal jwt token
* @return {Promise}
*/
updateStatusMessage(config) {
const { apiUri, buildId, statusMessage, token } = config;
const statusMessageOptions = {
json: true,
method: 'PUT',
uri: `${apiUri}/v4/builds/${buildId}`,
body: { statusMessage },
headers: { Authorization: `Bearer ${token}` },
strictSSL: false,
maxAttempts: MAXATTEMPTS,
retryDelay: RETRYDELAY
};

return this.breaker.runCommand(statusMessageOptions);
}

/**
* Starts a k8s build
* @method start
Expand Down Expand Up @@ -277,6 +303,15 @@ class K8sVMExecutor extends Executor {
`${JSON.stringify(resp.body.status, null, 2)}`);
}

if (status === 'pending') {
return this.updateStatusMessage({
apiUri: this.ecosystem.api,
buildId: config.buildId,
statusMessage: 'Waiting for resources to be available.',
token: config.token
});
}

return null;
});
}
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@
"devDependencies": {
"chai": "^3.5.0",
"eslint": "^4.19.1",
"eslint-config-screwdriver": "^3.0.0",
"eslint-config-screwdriver": "^3.0.1",
"jenkins-mocha": "^4.0.0",
"mockery": "^2.0.0",
"rewire": "^3.0.2",
"sinon": "^5.0.10"
},
"dependencies": {
"circuit-fuses": "^4.0.0",
"circuit-fuses": "^4.0.3",
"eslint-plugin-import": "^2.14.0",
"hoek": "^5.0.4",
"js-yaml": "^3.12.0",
"lodash": "^4.17.10",
"randomstring": "^1.1.5",
"requestretry": "^1.13.0",
"screwdriver-executor-base": "^6.2.0",
"screwdriver-executor-base": "^6.2.1",
"tinytim": "^0.1.1"
}
}
62 changes: 62 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ describe('index', () => {
describe('start', () => {
let postConfig;
let getConfig;
let putConfig;
let fakeStartConfig;

const fakeStartResponse = {
Expand Down Expand Up @@ -432,6 +433,21 @@ describe('index', () => {
retryStrategy: executor.podRetryStrategy
};

putConfig = {
uri: `${testApiUri}/v4/builds/${testBuildId}`,
method: 'PUT',
headers: {
Authorization: `Bearer ${testToken}`
},
body: {
statusMessage: 'Waiting for resources to be available.'
},
strictSSL: false,
maxAttempts: MAXATTEMPTS,
retryDelay: RETRYDELAY,
json: true
};

fakeStartConfig = {
annotations: {},
buildId: testBuildId,
Expand Down Expand Up @@ -665,6 +681,52 @@ describe('index', () => {
});
});

it('update build status message when pod status is pending', () => {
const returnResponse = {
statusCode: 200,
body: {
status: {
phase: 'pending'
}
}
};

const returnResponseFromSDAPI = { statusCode: 200 };

requestRetryMock.withArgs(getConfig).yieldsAsync(
null, returnResponse, returnResponse.body);

requestRetryMock.withArgs(putConfig).yieldsAsync(
null, returnResponseFromSDAPI);

return executor.start(fakeStartConfig).then((resp) => {
assert.calledWith(requestRetryMock, putConfig);
assert.deepEqual(resp.statusCode, 200);
});
});

it('sets error when pod status is failed', () => {
const returnResponse = {
statusCode: 200,
body: {
status: {
phase: 'failed'
}
}
};
const returnMessage = 'Failed to create pod. Pod status is:' +
`${JSON.stringify(returnResponse.body.status, null, 2)}`;

requestRetryMock.withArgs(getConfig).yieldsAsync(
null, returnResponse, returnResponse.body);

return executor.start(fakeStartConfig).then(() => {
throw new Error('did not fail');
}, (err) => {
assert.equal(err.message, returnMessage);
});
});

it('returns body when request responds with error in response', () => {
const returnResponse = {
statusCode: 500,
Expand Down

0 comments on commit cf22ae7

Please sign in to comment.