Skip to content

Commit 2a73765

Browse files
Saas 4713 (#425)
* [other] - added flag `--all` for getting pipelines without limit (in such cases, actually limit of 10k) * [other] - chamged >-1 to >=0 * [other] - v up * bump version * support test/delete/rollback * support test/delete/rollback * support test/delete/rollback * support test/delete/rollback Co-authored-by: zagnit <riftersound@gmail.com>
1 parent 1afc275 commit 2a73765

File tree

7 files changed

+237
-7
lines changed

7 files changed

+237
-7
lines changed

lib/interface/cli/commands/helm/release/delete-release.cmd.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const Command = require('../../../Command');
22
const { sdk } = require('../../../../../logic');
33
const { followLogs } = require('../../../helpers/logs');
44
const Output = require('../../../../../output/Output');
5+
const helmUtil = require('./util');
56

67
const install = new Command({
78
root: true,
@@ -43,11 +44,17 @@ const install = new Command({
4344
alias: 'nh',
4445
})
4546
.option('tiller-namespace', {
46-
description: 'prevent hooks from running during deletion',
47+
description: 'namespace where is tiller running ( helm 2 only )',
4748
type: 'string',
4849
alias: 'n',
4950
default: 'kube-system',
5051
})
52+
.option('namespace', {
53+
description: 'namespace where is chart located ( helm 3 )',
54+
type: 'string',
55+
alias: 'ns',
56+
default: 'default',
57+
})
5158
.example('codefresh delete-release my-release --cluster my-cluster', 'Delete release "my-release" from cluster "my-cluster"');
5259
},
5360
handler: async (argv) => {
@@ -57,18 +64,21 @@ const install = new Command({
5764
noHooks,
5865
timeout,
5966
cluster,
60-
tillerNamespace,
67+
'tiller-namespace': tillerNamespace,
68+
namespace,
6169
} = argv;
6270

6371
if (!releaseName) {
6472
throw new Error('Release name is required');
6573
}
6674

6775
try {
76+
const ns = (await helmUtil.isHelm3(cluster)) ? namespace : tillerNamespace;
77+
6878
const result = await sdk.helm.releases.delete({
6979
releaseName,
7080
selector: cluster,
71-
tillerNamespace,
81+
tillerNamespace: ns,
7282
}, {
7383
purge,
7484
timeout,

lib/interface/cli/commands/helm/release/helm-releases.sdk.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ describe('helm-release commands', () => {
4444
cleanup: true,
4545
timeout: 300,
4646
cluster: 'cluster',
47+
tillerNamespace: 'tillerNamespace',
4748
};
4849
await testCmd.handler(argv);
4950
await verifyResponsesReturned([DEFAULT_RESPONSE]); // eslint-disable-line
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 { sdk } = require('../../../../../logic');
3+
const { followLogs } = require('../../../helpers/logs');
4+
const Output = require('../../../../../output/Output');
5+
const helmUtil = require('./util');
6+
7+
const rollback = new Command({
8+
root: true,
9+
command: 'rollback-release <name>',
10+
description: 'Rollback a helm release from a kubernetes cluster',
11+
webDocs: {
12+
category: 'Predefined Pipelines',
13+
title: 'Rollback Helm Release',
14+
weight: 10,
15+
},
16+
builder: (yargs) => {
17+
return yargs
18+
.option('cluster', {
19+
description: 'Run on cluster',
20+
type: 'string',
21+
required: true,
22+
alias: 'c',
23+
})
24+
.option('revision', {
25+
description: 'revision number',
26+
type: 'number',
27+
alias: 't',
28+
required: true,
29+
})
30+
.option('tiller-namespace', {
31+
description: 'prevent hooks from running during deletion',
32+
type: 'string',
33+
alias: 'n',
34+
default: 'kube-system',
35+
})
36+
.option('namespace', {
37+
description: 'prevent hooks from running during deletion',
38+
type: 'string',
39+
alias: 'ns',
40+
default: 'default',
41+
})
42+
.option('detach', {
43+
alias: 'd',
44+
describe: 'Run pipeline and print build ID',
45+
})
46+
.example('codefresh rollback my-release --cluster my-cluster --revision 1',
47+
'rollback release "my-release" from cluster "my-cluster"');
48+
},
49+
handler: async (argv) => {
50+
const {
51+
name: releaseName,
52+
revision,
53+
cluster: selector,
54+
tillerNamespace,
55+
namespace,
56+
} = argv;
57+
58+
if (!releaseName) {
59+
throw new Error('Release name is required');
60+
}
61+
62+
try {
63+
const ns = (await helmUtil.isHelm3(selector)) ? namespace : tillerNamespace;
64+
65+
const result = await sdk.kubernetes.rollback({
66+
release: releaseName,
67+
selector,
68+
tillerNamespace: ns,
69+
revision,
70+
});
71+
72+
const workflowId = result.id;
73+
74+
if (argv.detach) {
75+
console.log(workflowId);
76+
return;
77+
}
78+
const exitCode = await followLogs(workflowId);
79+
process.exit(exitCode);
80+
} catch (err) {
81+
Output.printError(err);
82+
process.exit(1);
83+
}
84+
},
85+
});
86+
87+
module.exports = rollback;

lib/interface/cli/commands/helm/release/test-release.cmd.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const Command = require('../../../Command');
22
const { followLogs } = require('../../../helpers/logs');
33
const { sdk } = require('../../../../../logic');
44
const Output = require('../../../../../output/Output');
5+
const helmUtil = require('./util');
56

67
const install = new Command({
78
root: true,
@@ -24,6 +25,18 @@ const install = new Command({
2425
type: 'string',
2526
required: true,
2627
})
28+
.option('tiller-namespace', {
29+
description: 'namespace where is tiller running ( helm 2 only )',
30+
type: 'string',
31+
alias: 'n',
32+
default: 'kube-system',
33+
})
34+
.option('namespace', {
35+
description: 'namespace where is chart located ( helm 3 )',
36+
type: 'string',
37+
alias: 'ns',
38+
default: 'default',
39+
})
2740
.option('timeout', {
2841
description: 'time in seconds to wait for any individual kubernetes operation (like Jobs for hooks) (default 300)',
2942
default: '300',
@@ -45,14 +58,19 @@ const install = new Command({
4558
cluster,
4659
cleanup,
4760
timeout,
61+
'tiller-namespace': tillerNamespace,
62+
namespace,
4863
} = argv;
4964
if (!releaseName) {
5065
throw new Error('Release name is required');
5166
}
5267
try {
68+
const ns = (await helmUtil.isHelm3(cluster)) ? namespace : tillerNamespace;
69+
5370
const result = await sdk.helm.releases.test({
5471
releaseName,
5572
selector: cluster,
73+
tillerNamespace: ns,
5674
}, {
5775
cleanup,
5876
timeout,
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const { sdk } = require('../../../../../logic');
2+
3+
class HelmUtil {
4+
// eslint-disable-next-line class-methods-use-this
5+
async isHelm3(cluster) {
6+
try {
7+
const config = await sdk.helm['cluster-config'].get({
8+
selector: cluster,
9+
});
10+
return config.helmVersion === 'helm3';
11+
} catch (e) {
12+
return false;
13+
}
14+
}
15+
}
16+
module.exports = new HelmUtil();

openapi.json

Lines changed: 101 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,7 +1633,6 @@
16331633
"x-sdk-interface": "onPrem.runtimeEnvs.plan.get"
16341634
}
16351635
},
1636-
16371636
"/pipelines/analyze": {
16381637
"post": {
16391638
"responses": {
@@ -1653,6 +1652,32 @@
16531652
"x-sdk-interface": "pipelines.analyze"
16541653
}
16551654
},
1655+
"/helm/cluster-config/{selector}": {
1656+
"get": {
1657+
"responses": {
1658+
"200": {
1659+
"$ref": "#/components/responses/Json"
1660+
}
1661+
},
1662+
"tags": [
1663+
"helm.cluster-config"
1664+
],
1665+
"operationId": "helm-cluster-config-get",
1666+
"parameters": [
1667+
{
1668+
"in": "path",
1669+
"name": "selector",
1670+
"description": "Cluster selector",
1671+
"schema": {
1672+
"type": "string"
1673+
},
1674+
"required": true
1675+
}
1676+
],
1677+
"summary": "Get cluster config",
1678+
"x-sdk-interface": "helm.cluster-config.get"
1679+
}
1680+
},
16561681

16571682
"/annotations": {
16581683
"delete": {
@@ -5125,8 +5150,7 @@
51255150
"name": "tillerNamespace",
51265151
"schema": {
51275152
"type": "string"
5128-
},
5129-
"required": true
5153+
}
51305154
}
51315155
],
51325156
"requestBody": {
@@ -5142,6 +5166,73 @@
51425166
"x-sdk-interface": "helm.releases.delete"
51435167
}
51445168
},
5169+
"/kubernetes/rollback/{release}/{revision}": {
5170+
"get": {
5171+
"responses": {
5172+
"200": {
5173+
"description": "id of pipeline with rollback",
5174+
"content": {
5175+
"application/json": {
5176+
"schema": {
5177+
"type": "object",
5178+
"properties": {
5179+
"id": {
5180+
"type": "string"
5181+
}
5182+
}
5183+
}
5184+
}
5185+
}
5186+
}
5187+
},
5188+
"tags": [
5189+
"kubernetes"
5190+
],
5191+
"operationId": "kubernetes-rollback-release",
5192+
"parameters": [
5193+
{
5194+
"in": "path",
5195+
"name": "release",
5196+
"schema": {
5197+
"type": "string"
5198+
},
5199+
"description": "release",
5200+
"required": true
5201+
},
5202+
{
5203+
"in": "path",
5204+
"name": "revision",
5205+
"schema": {
5206+
"type": "string"
5207+
},
5208+
"description": "revision",
5209+
"required": true
5210+
},
5211+
{
5212+
"in": "query",
5213+
"name": "selector",
5214+
"schema": {
5215+
"type": "string"
5216+
},
5217+
"description": "Selector"
5218+
},
5219+
{
5220+
"in": "query",
5221+
"name": "tillerNamespace",
5222+
"schema": {
5223+
"type": "string"
5224+
},
5225+
"required": true,
5226+
"description": "Tiller namespace"
5227+
}
5228+
],
5229+
"requestBody": {
5230+
"$ref": "#/components/requestBodies/Json"
5231+
},
5232+
"summary": "Rollback",
5233+
"x-sdk-interface": "kubernetes.rollback"
5234+
}
5235+
},
51455236
"/kubernetes/releases/{releaseName}/test": {
51465237
"post": {
51475238
"responses": {
@@ -5168,6 +5259,13 @@
51685259
"schema": {
51695260
"type": "string"
51705261
}
5262+
},
5263+
{
5264+
"in": "query",
5265+
"name": "tillerNamespace",
5266+
"schema": {
5267+
"type": "string"
5268+
}
51715269
}
51725270
],
51735271
"requestBody": {

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

0 commit comments

Comments
 (0)