Skip to content

Commit d9e7875

Browse files
integrate with monitor (#447)
* integrate with monitor * upgrade sdk version * bump version * bump version * bump version * bump version * bump version * bump version * bump version * bump version * change sdk version
1 parent eeaa924 commit d9e7875

File tree

4 files changed

+157
-3
lines changed

4 files changed

+157
-3
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/* eslint-disable max-len */
2+
const Command = require('../../Command');
3+
const installRoot = require('../root/install.cmd');
4+
const { sdk } = require('../../../../logic');
5+
const ProgressEvents = require('../../helpers/progressEvents');
6+
const cliProgress = require('cli-progress');
7+
8+
const installMonitorCmd = new Command({
9+
root: false,
10+
parent: installRoot,
11+
command: 'monitor',
12+
description: 'Install and create an cluster resources monitor on kubernetes cluster',
13+
webDocs: {
14+
category: 'Monitor',
15+
title: 'Install',
16+
weight: 100,
17+
},
18+
builder: yargs => yargs
19+
.env('CF_ARG_') // this means that every process.env.CF_ARG_* will be passed to argv
20+
.option('cluster-id', {
21+
describe: 'Cluster id - freestyle name',
22+
})
23+
.option('token', {
24+
describe: 'Codefresh user token',
25+
})
26+
.option('kube-context-name', {
27+
describe: 'Name of the kubernetes context on which monitor should be installed [$CF_ARG_KUBE_CONTEXT_NAME]',
28+
})
29+
.option('in-cluster', {
30+
describe: 'Set flag if monitor is been installed from inside a cluster',
31+
})
32+
.option('kube-namespace', {
33+
describe: 'Name of the namespace on which monitor should be installed [$CF_ARG_KUBE_NAMESPACE]',
34+
})
35+
.option('verbose', {
36+
describe: 'Print logs',
37+
}),
38+
handler: async (argv) => {
39+
const {
40+
'in-cluster': inCluster,
41+
'kube-config-path': kubeConfigPath,
42+
'cluster-id': clusterId,
43+
token,
44+
'kube-context-name': kubeContextName,
45+
'kube-namespace': kubeNamespace,
46+
verbose,
47+
} = argv;
48+
const apiHost = sdk.config.context.url;
49+
const events = new ProgressEvents();
50+
const format = 'downloading [{bar}] {percentage}% | {value}/{total}';
51+
const progressBar = new cliProgress.SingleBar({ stopOnComplete: true, format }, cliProgress.Presets.shades_classic);
52+
let totalSize;
53+
events.onStart((size) => {
54+
console.log('Downloading agent\'s installer \n');
55+
progressBar.start(size, 0);
56+
totalSize = size;
57+
});
58+
events.onProgress((progress) => {
59+
progressBar.update(progress);
60+
if (progress >= totalSize) {
61+
console.log('\n');
62+
}
63+
});
64+
const monitorInstallStatusCode = await sdk.monitor.install({
65+
apiHost,
66+
kubeContextName,
67+
kubeNamespace,
68+
token,
69+
clusterId,
70+
inCluster,
71+
kubeConfigPath,
72+
verbose,
73+
events,
74+
});
75+
if (monitorInstallStatusCode !== 0) {
76+
throw new Error(`\nAgent installation failed with code ${monitorInstallStatusCode}`);
77+
}
78+
process.exit(0);
79+
},
80+
});
81+
82+
module.exports = installMonitorCmd;
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/* eslint-disable max-len */
2+
const Command = require('../../Command');
3+
const unInstallRoot = require('../root/uninstall.cmd');
4+
const { sdk } = require('../../../../logic');
5+
const ProgressEvents = require('../../helpers/progressEvents');
6+
const cliProgress = require('cli-progress');
7+
8+
9+
const unInstallAgentCmd = new Command({
10+
root: false,
11+
parent: unInstallRoot,
12+
command: 'monitor',
13+
description: 'Uninstall an monitor on kubernetes cluster',
14+
webDocs: {
15+
category: 'Monitor',
16+
title: 'Uninstall',
17+
weight: 100,
18+
},
19+
builder: yargs => yargs
20+
.env('CF_ARG_') // this means that every process.env.CF_ARG_* will be passed to argv
21+
.option('kube-context-name', {
22+
describe: 'Name of the kubernetes context on which monitor should be uninstalled [$CF_ARG_KUBE_CONTEXT_NAME]',
23+
})
24+
.option('kube-namespace', {
25+
describe: 'Name of the namespace on which monitor should be uninstalled [$CF_ARG_KUBE_NAMESPACE]',
26+
})
27+
.option('kube-config-path', {
28+
describe: 'Path to kubeconfig file (default is $HOME/.kube/config)',
29+
})
30+
.option('verbose', {
31+
describe: 'Print logs',
32+
}),
33+
handler: async (argv) => {
34+
const {
35+
'kube-namespace': kubeNamespace,
36+
'kube-config-path': kubeConfigPath,
37+
'kube-context-name': kubeContextName,
38+
39+
} = argv;
40+
41+
const events = new ProgressEvents();
42+
const format = 'downloading [{bar}] {percentage}% | {value}/{total}';
43+
const progressBar = new cliProgress.SingleBar({ stopOnComplete: true, format }, cliProgress.Presets.shades_classic);
44+
let totalSize;
45+
events.onStart((size) => {
46+
progressBar.start(size, 0);
47+
totalSize = size;
48+
});
49+
events.onProgress((progress) => {
50+
progressBar.update(progress);
51+
if (progress >= totalSize) {
52+
console.log('\n');
53+
}
54+
});
55+
56+
57+
const exitCode = await sdk.monitor.unInstall({
58+
kubeContextName,
59+
kubeNamespace,
60+
kubeConfigPath,
61+
terminateProcess: false,
62+
events,
63+
});
64+
if (exitCode === 0) {
65+
console.log('Monitor uninsalled successfully');
66+
process.exit(0);
67+
}
68+
process.exit(1);
69+
},
70+
});
71+
72+
module.exports = unInstallAgentCmd;

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codefresh",
3-
"version": "0.57.0",
3+
"version": "0.58.0",
44
"description": "Codefresh command line utility",
55
"main": "index.js",
66
"preferGlobal": true,
@@ -37,7 +37,7 @@
3737
"cf-errors": "^0.1.12",
3838
"chalk": "^1.1.3",
3939
"cli-progress": "3.6.0",
40-
"codefresh-sdk": "^1.7.1",
40+
"codefresh-sdk": "^1.8.0",
4141
"colors": "^1.1.2",
4242
"columnify": "^1.5.4",
4343
"compare-versions": "^3.4.0",

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,7 @@ code-point-at@^1.0.0:
12221222
resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77"
12231223
integrity sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=
12241224

1225-
codefresh-sdk@^1.7.1:
1225+
codefresh-sdk@^1.8.0:
12261226
version "1.8.1"
12271227
resolved "https://registry.yarnpkg.com/codefresh-sdk/-/codefresh-sdk-1.8.1.tgz#6b10e2724e319dbafa365994efb3609fd95e6321"
12281228
integrity sha512-vQKmGCFvrV48UU087zoeoRgyD21qeoUbwwM4H+x3CAj0uYIc/oXF7+W8ukF2lvh0RiDU7V2r00ykznGhFdck6g==

0 commit comments

Comments
 (0)