Skip to content

Commit c863895

Browse files
author
olegs-codefresh
authored
add test release command
1 parent c29c554 commit c863895

File tree

4 files changed

+86
-3
lines changed

4 files changed

+86
-3
lines changed

lib/interface/cli/commands/pipeline/dynamic/install-chart.cmd.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const {
33
installChart,
44
} = require('./../../../../../logic/api/helm');
55
const { printError } = require('./../../../helpers/general');
6+
const { log } = require('../../../../../logic').api;
67

78
const install = new Command({
89
root: true,
@@ -62,6 +63,8 @@ const install = new Command({
6263
tillerNamespace: argv.tillerNamespace,
6364
});
6465
console.log(`Started with id: ${workflowId}`);
66+
log.showWorkflowLogs(workflowId, true);
67+
process.exit(0);
6568
} catch (err) {
6669
printError(err);
6770
process.exit(1);
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
const Command = require('../../../Command');
2+
const {
3+
testRelease,
4+
} = require('./../../../../../logic/api/helm');
5+
const { printError } = require('./../../../helpers/general');
6+
const { log } = require('../../../../../logic').api;
7+
8+
const install = new Command({
9+
root: true,
10+
command: 'test-release [name]',
11+
description: 'Test helm releaes',
12+
builder: (yargs) => {
13+
return yargs
14+
.usage('Test helm relaese')
15+
.option('cluster', {
16+
description: 'Install on cluster',
17+
type: 'string',
18+
required: true,
19+
})
20+
.option('timeout', {
21+
description: 'time in seconds to wait for any individual kubernetes operation (like Jobs for hooks) (default 300)',
22+
default: '300',
23+
type: 'number',
24+
})
25+
.option('cleanup', {
26+
description: 'delete test pods upon completion (default false)',
27+
default: 'false',
28+
type: 'boolean',
29+
});
30+
},
31+
handler: async (argv) => {
32+
const releaseName = argv.name;
33+
if (!releaseName) {
34+
throw new Error('Release name is required');
35+
}
36+
try {
37+
const workflowId = await testRelease({
38+
releaseName,
39+
cluster: argv.cluster,
40+
cleanup: argv.cleanup,
41+
timeout: argv.timeout,
42+
});
43+
console.log(`Started with id: ${workflowId}`);
44+
await log.showWorkflowLogs(workflowId, true);
45+
process.exit(0);
46+
} catch (err) {
47+
printError(err);
48+
process.exit(1);
49+
}
50+
},
51+
});
52+
53+
module.exports = install;

lib/logic/api/helm.js

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
const Promise = require('bluebird');
22
const _ = require('lodash');
33
const CFError = require('cf-errors'); // eslint-disable-line
4-
const { sendHttpRequest } = require('./helper');
5-
const { getContextByName } = require('./context');
4+
const {
5+
sendHttpRequest,
6+
} = require('./helper');
7+
const {
8+
getContextByName,
9+
} = require('./context');
610

711
const SUPPORTED_TYPES = [
812
'yaml',
@@ -65,6 +69,29 @@ const installChart = async ({
6569
return res.id;
6670
};
6771

72+
const testRelease = async ({
73+
releaseName,
74+
cluster,
75+
cleanup,
76+
timeout,
77+
}) => {
78+
const options = {
79+
url: `/api/kubernetes/release/test/${releaseName}`,
80+
method: 'POST',
81+
qs: {
82+
selector: cluster,
83+
},
84+
body: {
85+
cleanup,
86+
timeout,
87+
},
88+
};
89+
90+
const res = await sendHttpRequest(options);
91+
return res.id;
92+
};
93+
6894
module.exports = {
6995
installChart,
96+
testRelease,
7097
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codefresh",
3-
"version": "0.6.91",
3+
"version": "0.7.0",
44
"description": "Codefresh command line utility",
55
"main": "index.js",
66
"preferGlobal": true,

0 commit comments

Comments
 (0)