Skip to content

Commit 59ca43e

Browse files
author
olegs-codefresh
authored
add more description to delete release cmd
1 parent e45f2b8 commit 59ca43e

File tree

5 files changed

+170
-11
lines changed

5 files changed

+170
-11
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
const Command = require('../../../Command');
2+
const {
3+
deleteRelease,
4+
} = require('./../../../../../logic/api/helm');
5+
const { printError } = require('./../../../helpers/general');
6+
const { log, workflow } = require('../../../../../logic').api;
7+
8+
const install = new Command({
9+
root: true,
10+
command: 'delete-release [name]',
11+
cliDocs: {
12+
description: 'Delete helm release',
13+
},
14+
webDocs: {
15+
category: 'Predefined Pipelines',
16+
title: 'Delete helm release',
17+
},
18+
builder: (yargs) => {
19+
return yargs
20+
.usage('Delete helm release from kubernetes cluster')
21+
.example('$0 delete-release my-release --cluster my-cluster', 'Delete release "my-release" from cluster "my-cluster"')
22+
.option('cluster', {
23+
description: 'Run on cluster',
24+
type: 'string',
25+
required: true,
26+
})
27+
.option('timeout', {
28+
description: 'time in seconds to wait for any individual kubernetes operation (like Jobs for hooks) (default 300)',
29+
default: '300',
30+
type: 'number',
31+
})
32+
.option('purge', {
33+
description: 'remove the release from the store and make its name free for later use (default true)',
34+
default: false,
35+
type: 'boolean',
36+
})
37+
.option('detach', {
38+
alias: 'd',
39+
describe: 'Run pipeline and print build ID',
40+
})
41+
.option('no-hooks', {
42+
description: 'prevent hooks from running during deletion',
43+
default: false,
44+
type: 'boolean',
45+
});
46+
},
47+
handler: async (argv) => {
48+
const releaseName = argv.name;
49+
if (!releaseName) {
50+
throw new Error('Release name is required');
51+
}
52+
try {
53+
const workflowId = await deleteRelease({
54+
releaseName,
55+
cluster: argv.cluster,
56+
timeout: argv.timeout,
57+
purge: argv.purge,
58+
noHooks: argv.noHooks,
59+
});
60+
if (argv.detach) {
61+
console.log(workflowId);
62+
} else {
63+
await log.showWorkflowLogs(workflowId, true);
64+
const workflowInstance = await workflow.getWorkflowById(workflowId);
65+
switch (workflowInstance.getStatus()) {
66+
case 'success':
67+
process.exit(0);
68+
break;
69+
case 'error':
70+
process.exit(1);
71+
break;
72+
case 'terminated':
73+
process.exit(2);
74+
break;
75+
default:
76+
process.exit(100);
77+
break;
78+
}
79+
}
80+
} catch (err) {
81+
printError(err);
82+
process.exit(1);
83+
}
84+
},
85+
});
86+
87+
module.exports = install;

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

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

88
const install = new Command({
99
root: true,
@@ -12,6 +12,10 @@ const install = new Command({
1212
description: `Install or upgrade Helm chart
1313
Repository flag can be either absolute url or saved repository in Codefresh`,
1414
},
15+
webDocs: {
16+
category: 'Predefined Pipelines',
17+
title: 'Delete helm release',
18+
},
1519
builder: (yargs) => {
1620
return yargs
1721
.usage('Display one or many resources\n\n' +
@@ -53,6 +57,10 @@ const install = new Command({
5357
description: 'Contexts (yaml || secret-yaml) to be passed to the install',
5458
array: true,
5559
})
60+
.option('detach', {
61+
alias: 'd',
62+
describe: 'Run pipeline and print build ID',
63+
})
5664
.option('release-name', {
5765
description: 'The name to set to the release',
5866
});
@@ -69,9 +77,26 @@ const install = new Command({
6977
values: argv.context,
7078
tillerNamespace: argv.tillerNamespace,
7179
});
72-
console.log(`Started with id: ${workflowId}`);
73-
log.showWorkflowLogs(workflowId, true);
74-
process.exit(0);
80+
if (argv.detach) {
81+
console.log(workflowId);
82+
} else {
83+
await log.showWorkflowLogs(workflowId, true);
84+
const workflowInstance = await workflow.getWorkflowById(workflowId);
85+
switch (workflowInstance.getStatus()) {
86+
case 'success':
87+
process.exit(0);
88+
break;
89+
case 'error':
90+
process.exit(1);
91+
break;
92+
case 'terminated':
93+
process.exit(2);
94+
break;
95+
default:
96+
process.exit(100);
97+
break;
98+
}
99+
}
75100
} catch (err) {
76101
printError(err);
77102
process.exit(1);

lib/interface/cli/commands/pipeline/dynamic/test-release.cmd.js

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

88
const install = new Command({
99
root: true,
@@ -19,7 +19,7 @@ const install = new Command({
1919
return yargs
2020
.usage('Test helm relaese')
2121
.option('cluster', {
22-
description: 'Install on cluster',
22+
description: 'Run on cluster',
2323
type: 'string',
2424
required: true,
2525
})
@@ -28,6 +28,10 @@ const install = new Command({
2828
default: '300',
2929
type: 'number',
3030
})
31+
.option('detach', {
32+
alias: 'd',
33+
describe: 'Run pipeline and print build ID',
34+
})
3135
.option('cleanup', {
3236
description: 'delete test pods upon completion (default false)',
3337
default: 'false',
@@ -46,9 +50,27 @@ const install = new Command({
4650
cleanup: argv.cleanup,
4751
timeout: argv.timeout,
4852
});
49-
console.log(`Started with id: ${workflowId}`);
50-
await log.showWorkflowLogs(workflowId, true);
51-
process.exit(0);
53+
54+
if (argv.detach) {
55+
console.log(workflowId);
56+
} else {
57+
await log.showWorkflowLogs(workflowId, true);
58+
const workflowInstance = await workflow.getWorkflowById(workflowId);
59+
switch (workflowInstance.getStatus()) {
60+
case 'success':
61+
process.exit(0);
62+
break;
63+
case 'error':
64+
process.exit(1);
65+
break;
66+
case 'terminated':
67+
process.exit(2);
68+
break;
69+
default:
70+
process.exit(100);
71+
break;
72+
}
73+
}
5274
} catch (err) {
5375
printError(err);
5476
process.exit(1);

lib/logic/api/helm.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const testRelease = async ({
7676
timeout,
7777
}) => {
7878
const options = {
79-
url: `/api/kubernetes/releases/test/${releaseName}`,
79+
url: `/api/kubernetes/releases/${releaseName}/test`,
8080
method: 'POST',
8181
qs: {
8282
selector: cluster,
@@ -91,7 +91,32 @@ const testRelease = async ({
9191
return res.id;
9292
};
9393

94+
const deleteRelease = async ({
95+
releaseName,
96+
cluster,
97+
timeout,
98+
purge,
99+
noHooks,
100+
}) => {
101+
const options = {
102+
url: `/api/kubernetes/releases/${releaseName}/delete`,
103+
method: 'POST',
104+
qs: {
105+
selector: cluster,
106+
},
107+
body: {
108+
purge,
109+
noHooks,
110+
timeout,
111+
},
112+
};
113+
114+
const res = await sendHttpRequest(options);
115+
return res.id;
116+
};
117+
94118
module.exports = {
95119
installChart,
96120
testRelease,
121+
deleteRelease,
97122
};

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.7.4",
3+
"version": "0.7.5",
44
"description": "Codefresh command line utility",
55
"main": "index.js",
66
"preferGlobal": true,

0 commit comments

Comments
 (0)