Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions lib/interface/cli/commands/monitor/install.cmd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/* eslint-disable max-len */
const Command = require('../../Command');
const installRoot = require('../root/install.cmd');
const { sdk } = require('../../../../logic');
const ProgressEvents = require('../../helpers/progressEvents');
const cliProgress = require('cli-progress');

const installMonitorCmd = new Command({
root: false,
parent: installRoot,
command: 'monitor',
description: 'Install and create an cluster resources monitor on kubernetes cluster',
webDocs: {
category: 'Monitor',
title: 'Install',
weight: 100,
},
builder: yargs => yargs
.env('CF_ARG_') // this means that every process.env.CF_ARG_* will be passed to argv
.option('cluster-id', {
describe: 'Cluster id - freestyle name',
})
.option('token', {
describe: 'Codefresh user token',
})
.option('kube-context-name', {
describe: 'Name of the kubernetes context on which monitor should be installed [$CF_ARG_KUBE_CONTEXT_NAME]',
})
.option('in-cluster', {
describe: 'Set flag if monitor is been installed from inside a cluster',
})
.option('kube-namespace', {
describe: 'Name of the namespace on which monitor should be installed [$CF_ARG_KUBE_NAMESPACE]',
})
.option('verbose', {
describe: 'Print logs',
}),
handler: async (argv) => {
const {
'in-cluster': inCluster,
'kube-config-path': kubeConfigPath,
'cluster-id': clusterId,
token,
'kube-context-name': kubeContextName,
'kube-namespace': kubeNamespace,
verbose,
} = argv;
const apiHost = sdk.config.context.url;
const events = new ProgressEvents();
const format = 'downloading [{bar}] {percentage}% | {value}/{total}';
const progressBar = new cliProgress.SingleBar({ stopOnComplete: true, format }, cliProgress.Presets.shades_classic);
let totalSize;
events.onStart((size) => {
console.log('Downloading agent\'s installer \n');
progressBar.start(size, 0);
totalSize = size;
});
events.onProgress((progress) => {
progressBar.update(progress);
if (progress >= totalSize) {
console.log('\n');
}
});
const monitorInstallStatusCode = await sdk.monitor.install({
apiHost,
kubeContextName,
kubeNamespace,
token,
clusterId,
inCluster,
kubeConfigPath,
verbose,
events,
});
if (monitorInstallStatusCode !== 0) {
throw new Error(`\nAgent installation failed with code ${monitorInstallStatusCode}`);
}
process.exit(0);
},
});

module.exports = installMonitorCmd;
72 changes: 72 additions & 0 deletions lib/interface/cli/commands/monitor/uninstall.cmd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* eslint-disable max-len */
const Command = require('../../Command');
const unInstallRoot = require('../root/uninstall.cmd');
const { sdk } = require('../../../../logic');
const ProgressEvents = require('../../helpers/progressEvents');
const cliProgress = require('cli-progress');


const unInstallAgentCmd = new Command({
root: false,
parent: unInstallRoot,
command: 'monitor',
description: 'Uninstall an monitor on kubernetes cluster',
webDocs: {
category: 'Monitor',
title: 'Uninstall',
weight: 100,
},
builder: yargs => yargs
.env('CF_ARG_') // this means that every process.env.CF_ARG_* will be passed to argv
.option('kube-context-name', {
describe: 'Name of the kubernetes context on which monitor should be uninstalled [$CF_ARG_KUBE_CONTEXT_NAME]',
})
.option('kube-namespace', {
describe: 'Name of the namespace on which monitor should be uninstalled [$CF_ARG_KUBE_NAMESPACE]',
})
.option('kube-config-path', {
describe: 'Path to kubeconfig file (default is $HOME/.kube/config)',
})
.option('verbose', {
describe: 'Print logs',
}),
handler: async (argv) => {
const {
'kube-namespace': kubeNamespace,
'kube-config-path': kubeConfigPath,
'kube-context-name': kubeContextName,

} = argv;

const events = new ProgressEvents();
const format = 'downloading [{bar}] {percentage}% | {value}/{total}';
const progressBar = new cliProgress.SingleBar({ stopOnComplete: true, format }, cliProgress.Presets.shades_classic);
let totalSize;
events.onStart((size) => {
progressBar.start(size, 0);
totalSize = size;
});
events.onProgress((progress) => {
progressBar.update(progress);
if (progress >= totalSize) {
console.log('\n');
}
});


const exitCode = await sdk.monitor.unInstall({
kubeContextName,
kubeNamespace,
kubeConfigPath,
terminateProcess: false,
events,
});
if (exitCode === 0) {
console.log('Monitor uninsalled successfully');
process.exit(0);
}
process.exit(1);
},
});

module.exports = unInstallAgentCmd;
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codefresh",
"version": "0.57.0",
"version": "0.58.0",
"description": "Codefresh command line utility",
"main": "index.js",
"preferGlobal": true,
Expand Down Expand Up @@ -37,7 +37,7 @@
"cf-errors": "^0.1.12",
"chalk": "^1.1.3",
"cli-progress": "3.6.0",
"codefresh-sdk": "^1.7.1",
"codefresh-sdk": "^1.8.0",
"colors": "^1.1.2",
"columnify": "^1.5.4",
"compare-versions": "^3.4.0",
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ code-point-at@^1.0.0:
resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77"
integrity sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=

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