Skip to content

Commit 70cbfbe

Browse files
runner delete (#455)
* runner delete
1 parent f2c84f5 commit 70cbfbe

File tree

5 files changed

+148
-6
lines changed

5 files changed

+148
-6
lines changed

lib/interface/cli/commands/agent/uninstall.cmd.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const unInstallAgentCmd = new Command({
4040
name,
4141
'kube-namespace': kubeNamespace,
4242
'kube-config-path': kubeConfigPath,
43+
terminateProcess,
4344

4445
} = argv;
4546

@@ -80,7 +81,9 @@ const unInstallAgentCmd = new Command({
8081
console.log('Agent uninsalled successfully');
8182
await deleteAgent.handler({ name, id: name });
8283
}
83-
process.exit(0);
84+
if (terminateProcess !== false) {
85+
process.exit(0);
86+
}
8487
},
8588
});
8689

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/* eslint-disable max-len */
2+
const Command = require('../../Command');
3+
const runnerRoot = require('../root/runner.cmd');
4+
const inquirer = require('inquirer');
5+
const { getAllKubeContexts, getKubeContext } = require('../../helpers/kubernetes');
6+
const unInstallRuntime = require('../runtimeEnvironments/uninstall.cmd');
7+
const unInstallAgent = require('../agent/uninstall.cmd');
8+
const unInstallMonitor = require('../monitor/uninstall.cmd');
9+
const colors = require('colors');
10+
const DEFAULTS = require('../../defaults');
11+
const sdk = require('../../../../logic/sdk');
12+
const _ = require('lodash');
13+
14+
const defaultNamespace = 'codefresh';
15+
16+
const deleteCmd = new Command({
17+
root: false,
18+
parent: runnerRoot,
19+
command: 'delete',
20+
requiresAuthentication: false,
21+
description: 'Deletes codefresh runner solution\'s components on kubernetes cluster',
22+
webDocs: {
23+
category: 'Runner',
24+
title: 'Delete',
25+
weight: 100,
26+
},
27+
// requiresAuthentication: argv => argv && !argv.token,
28+
builder: yargs => yargs
29+
.env('CF_ARG_') // this means that every process.env.CF_ARG_* will be passed to argv
30+
.option('name', {
31+
describe: 'Agent\'s name to be deleted',
32+
})
33+
.option('url', {
34+
describe: 'Codefresh system custom url',
35+
default: DEFAULTS.URL,
36+
})
37+
.option('kube-context-name', {
38+
describe: 'Name of the kubernetes context on which venona should be installed [$CF_ARG_KUBE_CONTEXT_NAME]',
39+
})
40+
.option('kube-namespace', {
41+
describe: 'Name of the namespace on which venona should be installed [$CF_ARG_KUBE_NAMESPACE]',
42+
})
43+
.option('kube-config-path', {
44+
describe: 'Path to kubeconfig file (default is $HOME/.kube/config)',
45+
})
46+
.option('verbose', {
47+
describe: 'Print logs',
48+
}),
49+
handler: async (argv) => {
50+
const {
51+
'kube-config-path': kubeConfigPath,
52+
} = argv;
53+
let {
54+
'kube-context-name': kubeContextName,
55+
'kube-namespace': kubeNamespace,
56+
name: agentName,
57+
} = argv;
58+
59+
const questions = [];
60+
if (!kubeContextName) {
61+
const contexts = getAllKubeContexts(kubeConfigPath);
62+
const currentKubeContext = getKubeContext(kubeConfigPath);
63+
64+
questions.push({
65+
type: 'list',
66+
name: 'context',
67+
message: 'Name of Kubernetes context to use',
68+
default: currentKubeContext,
69+
choices: contexts,
70+
});
71+
}
72+
if (!kubeNamespace) {
73+
questions.push({
74+
type: 'input',
75+
name: 'namespace',
76+
default: defaultNamespace,
77+
message: 'Kubernetes namespace to remove Codefresh Runner components from ',
78+
validate: value => (value !== undefined && value !== '') || 'Please enter namespace\'s name',
79+
});
80+
}
81+
const agents = await sdk.agents.list({});
82+
if (!agentName) {
83+
questions.push({
84+
type: 'list',
85+
name: 'name',
86+
message: 'Runner manager name to uninstall',
87+
choices: agents,
88+
});
89+
}
90+
console.log(colors.green('This uninstaller will guide you through the runner uninstallation process'));
91+
const answers = await inquirer.prompt(questions);
92+
kubeContextName = kubeContextName || answers.context;
93+
kubeNamespace = kubeNamespace || answers.namespace;
94+
agentName = agentName || answers.name;
95+
// check that agent exists
96+
const agent = _.find(agents, curr => curr.name === agentName);
97+
if (!agent) {
98+
console.log(colors.red(`Runner Manager with name ${agentName} doesn\'t exists`));
99+
return;
100+
}
101+
if (agent.runtimes && agent.runtimes > 1) {
102+
console.log('Can\'t delete runner with more than one runtime , use runtime delete command');
103+
return;
104+
}
105+
console.log(colors.green(`Uninstallation options summary : \n Context: ${colors.blue(kubeContextName)} \n Namespace: ${colors.blue(kubeNamespace)} \n Agent name: ${colors.blue(agentName)} `));
106+
if (agent.runtimes.length === 1) {
107+
await unInstallRuntime.handler({
108+
'agent-name': agentName,
109+
'runtime-kube-namespace': kubeNamespace,
110+
'runtime-kube-context-name': kubeContextName,
111+
'agent-kube-context-name': kubeContextName,
112+
'agent-kube-namespace': kubeNamespace,
113+
name: agent.runtimes[0],
114+
terminateProcess: false,
115+
});
116+
}
117+
await unInstallAgent.handler({
118+
'kube-namespace': kubeNamespace,
119+
'kube-context-name': kubeContextName,
120+
name: agentName,
121+
terminateProcess: false,
122+
});
123+
await unInstallMonitor.handler({
124+
'kube-namespace': kubeNamespace,
125+
'kube-context-name': kubeContextName,
126+
noExit: true, // to prevent if from calling: process.exit()
127+
128+
});
129+
console.log('Successfully uninstalled Codefresh Runner');
130+
process.exit(); // TODO : This is not needed - needed to be fixed
131+
},
132+
});
133+
134+
module.exports = deleteCmd;

lib/interface/cli/commands/monitor/uninstall.cmd.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const unInstallAgentCmd = new Command({
3535
'kube-namespace': kubeNamespace,
3636
'kube-config-path': kubeConfigPath,
3737
'kube-context-name': kubeContextName,
38-
38+
noExit,
3939
} = argv;
4040

4141
const events = new ProgressEvents();
@@ -63,9 +63,13 @@ const unInstallAgentCmd = new Command({
6363
});
6464
if (exitCode === 0) {
6565
console.log('Monitor uninsalled successfully');
66-
process.exit(0);
66+
if (!noExit) {
67+
process.exit(0);
68+
}
69+
}
70+
if (!noExit) {
71+
process.exit(1);
6772
}
68-
process.exit(1);
6973
},
7074
});
7175

lib/interface/cli/commands/runtimeEnvironments/uninstall.cmd.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ const unInstallRuntimeCmd = new Command({
6767
'restart-agent': restartAgent,
6868
'agent-kube-config-path': agentKubeConfigPath,
6969
verbose,
70+
terminateProcess,
7071

7172
} = argv;
7273

@@ -137,7 +138,7 @@ const unInstallRuntimeCmd = new Command({
137138
restartAgent,
138139
storageClassName,
139140
verbose,
140-
terminateProcess: true,
141+
terminateProcess: (terminateProcess !== false),
141142
events,
142143
});
143144
},

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

0 commit comments

Comments
 (0)