Skip to content

Commit 36c999d

Browse files
Saas 489 cli helm promotion (#221)
1 parent b91363f commit 36c999d

File tree

4 files changed

+171
-1
lines changed

4 files changed

+171
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Commands:
4141
codefresh run <name> Run a pipeline by id or name and attach the created workflow logs.
4242
codefresh delete-release [name] Delete a helm release from a kubernetes cluster.
4343
codefresh install-chart Install or upgrade a Helm chart Repository flag can be either absolute url or saved repository in Codefresh.
44+
codefresh helm-promotion Promote a Helm release in another environment.
4445
codefresh test-release [name] Test a helm release.
4546
4647
Options:
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
const Command = require('../../../Command');
2+
const {
3+
promoteChart,
4+
} = require('./../../../../../logic/api/helm');
5+
const { printError } = require('./../../../helpers/general');
6+
const { log, workflow } = require('../../../../../logic').api;
7+
8+
const promote = new Command({
9+
root: true,
10+
command: 'helm-promotion',
11+
description: 'Promote a Helm release in another environment',
12+
webDocs: {
13+
category: 'Predefined Pipelines',
14+
title: 'Promote Helm Release',
15+
weight: 20,
16+
},
17+
builder: (yargs) => {
18+
return yargs
19+
.option('board', {
20+
description: 'Board for promotion',
21+
type: 'string',
22+
required: false,
23+
})
24+
.option('source', {
25+
description: 'Source column',
26+
type: 'string',
27+
required: false,
28+
})
29+
.option('target', {
30+
description: 'Target column',
31+
type: 'string',
32+
required: false,
33+
})
34+
.option('namespace', {
35+
description: 'Promote to namespace',
36+
default: 'default',
37+
type: 'string',
38+
})
39+
.option('source-tiller-namespace', {
40+
description: 'Where tiller has been installed in source cluster',
41+
default: 'kube-system',
42+
type: 'string',
43+
})
44+
.option('target-tiller-namespace', {
45+
description: 'Where tiller has been installed in target cluster',
46+
default: 'kube-system',
47+
type: 'string',
48+
})
49+
.option('source-release', {
50+
description: 'The name of source release',
51+
})
52+
.option('revision', {
53+
description: 'Revision of source release',
54+
type: 'string',
55+
required: false,
56+
})
57+
.option('target-release', {
58+
description: 'The name to set to the release',
59+
})
60+
.option('context', {
61+
description: 'Contexts (yaml || secret-yaml) to be passed to the install',
62+
array: true,
63+
})
64+
.option('set', {
65+
description: 'set of KEY=VALUE to be passed to the install',
66+
array: true,
67+
})
68+
.option('detach', {
69+
alias: 'd',
70+
describe: 'Run pipeline and print build ID',
71+
})
72+
.example(
73+
'codefresh helm-promotion --board app --source dev --target test --source-release application',
74+
`Promote 'application' release on board 'app' from 'dev' to 'test' environment`);
75+
},
76+
handler: async (argv) => {
77+
try {
78+
const workflowId = await promoteChart({
79+
board: argv.board,
80+
sourceSection: argv.source,
81+
targetSection: argv.target,
82+
sourceCluster: argv.sourceCluster,
83+
tillerNamespace: argv.sourceTillerNamespace,
84+
releaseName: argv.sourceRelease,
85+
revision: argv.revision,
86+
targetCluster: argv.targetCluster,
87+
targetTillerNamespace: argv.targetTillerNamespace,
88+
targetNamespace: argv.namespace,
89+
targetReleaseName: argv.targetRelease,
90+
values: argv.context,
91+
setValues: argv.set,
92+
});
93+
if (argv.detach) {
94+
console.log(workflowId);
95+
} else {
96+
await log.showWorkflowLogs(workflowId, true);
97+
const workflowInstance = await workflow.getWorkflowById(workflowId);
98+
switch (workflowInstance.getStatus()) {
99+
case 'success':
100+
process.exit(0);
101+
break;
102+
case 'error':
103+
process.exit(1);
104+
break;
105+
case 'terminated':
106+
process.exit(2);
107+
break;
108+
default:
109+
process.exit(100);
110+
break;
111+
}
112+
}
113+
} catch (err) {
114+
printError(err);
115+
process.exit(1);
116+
}
117+
},
118+
});
119+
120+
module.exports = promote;

lib/logic/api/helm.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,54 @@ const installChart = async ({
8989
return res.id;
9090
};
9191

92+
const promoteChart = async ({
93+
board,
94+
sourceSection,
95+
targetSection,
96+
sourceCluster,
97+
tillerNamespace,
98+
releaseName,
99+
revision,
100+
targetCluster,
101+
targetTillerNamespace,
102+
targetNamespace,
103+
targetReleaseName,
104+
values,
105+
setValues,
106+
}) => {
107+
let normalizedValues = [];
108+
if (values && _.isArray(values) && values.length > 0) {
109+
normalizedValues = await _normalizeValues(values);
110+
}
111+
112+
const normalizedSetValues = await _normalizeSetValues(setValues);
113+
const options = {
114+
url: '/api/kubernetes/chart/promote',
115+
method: 'POST',
116+
qs: {
117+
selector: sourceCluster,
118+
tillerNamespace,
119+
},
120+
body: {
121+
board,
122+
sourceSection,
123+
targetSection,
124+
sourceCluster,
125+
releaseName,
126+
revision,
127+
targetSelector: targetCluster,
128+
targetTillerNamespace,
129+
targetNamespace,
130+
targetReleaseName,
131+
values: normalizedValues,
132+
set: normalizedSetValues,
133+
},
134+
};
135+
136+
const res = await sendHttpRequest(options);
137+
return res.id;
138+
};
139+
92140
const testRelease = async ({
93141
releaseName,
94142
cluster,
@@ -198,6 +246,7 @@ const deleteRepo = async (name) => {
198246

199247
module.exports = {
200248
installChart,
249+
promoteChart,
201250
testRelease,
202251
deleteRelease,
203252
getAllRepos,

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

0 commit comments

Comments
 (0)