Skip to content

Commit e44594a

Browse files
added --force flag to runner delete flow (#491)
* added --force flag to runner delete flow
1 parent c3258ae commit e44594a

File tree

5 files changed

+58
-28
lines changed

5 files changed

+58
-28
lines changed

lib/interface/cli/commands/hybrid/delete.cmd.js

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,41 @@ const DEFAULTS = require('../../defaults');
1111
const sdk = require('../../../../logic/sdk');
1212
const _ = require('lodash');
1313
const { to } = require('./../../../../logic/cli-config/errors/awaitTo');
14-
const { createErrorHandler, getRelatedAgents, getRelatedNamespaces } = require('./helper');
14+
const {
15+
createErrorHandler,
16+
getRelatedAgents,
17+
getRelatedNamespaces,
18+
drawCodefreshFiglet,
19+
} = require('./helper');
1520

1621
const defaultNamespace = 'codefresh';
1722
const openIssueMessage = `If you had any issues with the uninstallation process please report them at: ${colors.blue('https://github.com/codefresh-io/cli/issues/new')}`;
1823
const handleError = createErrorHandler(openIssueMessage);
1924

25+
async function promptConfirmationMessage({
26+
agentName,
27+
kubeNamespace,
28+
attachedRuntimes,
29+
}) {
30+
// prompt confirmation message
31+
console.log(`${colors.red('This process will attempt to delete the following:')}`);
32+
console.log(`\u2022 Codefresh runner with the name "${colors.cyan(agentName)}"`);
33+
attachedRuntimes.forEach((reName) => { console.log(`\u2022 Codefresh runtime with the name "${colors.cyan(reName)}"`); });
34+
console.log('\u2022 Codefresh runner monitor component');
35+
console.log(`* The kubernetes namespace "${colors.cyan(kubeNamespace)}" will ${colors.underline('not')} be deleted\n`);
36+
37+
const answer = await inquirer.prompt({
38+
type: 'confirm',
39+
name: 'deletionConfirmed',
40+
default: false,
41+
message: 'Are you sure you want to delete all of the above? (default is NO)',
42+
});
43+
if (!answer.deletionConfirmed) {
44+
console.log('Deletion process aborted, exiting...');
45+
process.exit(1);
46+
}
47+
}
48+
2049
const deleteCmd = new Command({
2150
root: false,
2251
parent: runnerRoot,
@@ -38,6 +67,11 @@ const deleteCmd = new Command({
3867
describe: 'Codefresh system custom url',
3968
default: DEFAULTS.URL,
4069
})
70+
.option('force', {
71+
describe: 'Run the delete operation without asking to confirm (use with caution!)',
72+
alias: 'f',
73+
type: Boolean,
74+
})
4175
.option('kube-context-name', {
4276
describe: 'Name of the kubernetes context from which the Codefresh Agent and Runtime should be removed',
4377
})
@@ -53,6 +87,7 @@ const deleteCmd = new Command({
5387
handler: async (argv) => {
5488
const {
5589
'kube-config-path': kubeConfigPath,
90+
force,
5691
} = argv;
5792
let {
5893
'kube-context-name': kubeContextName,
@@ -146,22 +181,8 @@ const deleteCmd = new Command({
146181

147182
const attachedRuntimes = agent.runtimes || [];
148183

149-
// prompt confirmation message
150-
console.log(`${colors.red('This process will attempt to delete the following:')}`);
151-
console.log(`\u2022 Codefresh runner with the name "${colors.cyan(agentName)}"`);
152-
attachedRuntimes.forEach((reName) => { console.log(`\u2022 Codefresh runtime with the name "${colors.cyan(reName)}"`); });
153-
console.log('\u2022 Codefresh runner monitor component');
154-
console.log(`* The kubernetes namespace "${colors.cyan(kubeNamespace)}" will ${colors.underline('not')} be deleted\n`);
155-
156-
const answer = await inquirer.prompt({
157-
type: 'confirm',
158-
name: 'deletionConfirmed',
159-
default: false,
160-
message: 'Are you sure you want to delete all of the above? (default is NO)',
161-
});
162-
if (!answer.deletionConfirmed) {
163-
console.log('Deletion process aborted, exiting...');
164-
process.exit(1);
184+
if (!force) {
185+
await promptConfirmationMessage({ agentName, kubeNamespace, attachedRuntimes });
165186
}
166187

167188
attachedRuntimes.forEach(async (reName) => {
@@ -197,6 +218,7 @@ const deleteCmd = new Command({
197218

198219
console.log('Successfully uninstalled Codefresh Runner');
199220
console.log(colors.green(`\nIf you had any issues with the uninstallation process please report them at: ${colors.blue('https://github.com/codefresh-io/cli/issues/new')}`));
221+
await drawCodefreshFiglet();
200222
process.exit(); // TODO : This is not needed - needed to be fixed
201223
},
202224
});

lib/interface/cli/commands/hybrid/helper.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const { getAllNamespaces } = require('../../helpers/kubernetes');
1010
const { followLogs } = require('../../helpers/logs');
1111
const ProgressEvents = require('../../helpers/progressEvents');
1212
const cliProgress = require('cli-progress');
13+
const figlet = require('figlet');
1314

1415
const INSTALLATION_DEFAULTS = {
1516
NAMESPACE: 'codefresh',
@@ -256,6 +257,18 @@ function createProgressBar() {
256257
return runtimeEvents;
257258
}
258259

260+
function drawCodefreshFiglet() {
261+
return new Promise((resolve) => {
262+
figlet('CODEFRESH', (err, data) => {
263+
if (err) {
264+
return;
265+
}
266+
console.log(data);
267+
resolve();
268+
});
269+
});
270+
}
271+
259272
module.exports = {
260273
getRelatedAgents,
261274
createErrorHandler,
@@ -268,6 +281,7 @@ module.exports = {
268281
executeTestPipeline,
269282
createProgressBar,
270283
getTestPipelineLink,
284+
drawCodefreshFiglet,
271285
INSTALLATION_DEFAULTS,
272286
DefaultLogFormatter,
273287
};

lib/interface/cli/commands/hybrid/init.cmd.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ const Command = require('../../Command');
33
const runnerRoot = require('../root/runner.cmd');
44
const inquirer = require('inquirer');
55
const colors = require('colors');
6-
const figlet = require('figlet');
76
const _ = require('lodash');
87
const cliProgress = require('cli-progress');
98
const { getAllKubeContexts, getKubeContext, getAllNamespaces } = require('../../helpers/kubernetes');
@@ -22,6 +21,7 @@ const {
2221
createTestPipeline,
2322
executeTestPipeline,
2423
updateTestPipelineRuntime,
24+
drawCodefreshFiglet,
2525
INSTALLATION_DEFAULTS,
2626
} = require('./helper');
2727
const {
@@ -367,15 +367,7 @@ const initCmd = new Command({
367367
console.log(colors.green(`\nDocumenation link: ${colors.blue('https://codefresh.io/docs/docs/enterprise/codefresh-runner/#codefresh-runner-preview-release')}`));
368368
console.log(colors.green(`If you had any issues with the installation please report them at: ${colors.blue('https://github.com/codefresh-io/cli/issues/new')}`));
369369
await to(progressReporter.report(installationProgress.events.FINISHED, installationProgress.status.SUCCESS));
370-
await new Promise((resolve) => {
371-
figlet('CODEFRESH', (err, data) => {
372-
if (err) {
373-
return;
374-
}
375-
console.log(data);
376-
resolve();
377-
});
378-
});
370+
await drawCodefreshFiglet();
379371
process.exit(); // TODO : This is not needed - needed to be fixed
380372
},
381373
});

lib/interface/cli/commands/hybrid/upgrade.cmd.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const {
1414
createErrorHandler,
1515
getRuntimesWithVersions,
1616
getRuntimeVersion,
17+
drawCodefreshFiglet,
1718
} = require('./helper');
1819
const { migrate, upgrade } = require('./migration');
1920

@@ -168,6 +169,7 @@ const upgradeCmd = new Command({
168169

169170
console.log(colors.green(`\nSuccessfully ${shouldDoMigration ? 'migrated' : 'upgraded'} your Codefresh Runner to the latest version`));
170171
console.log(colors.green(`If you had any issues with the uninstallation process please report them at: ${colors.blue('https://github.com/codefresh-io/cli/issues/new')}`));
172+
await drawCodefreshFiglet();
171173
process.exit(); // TODO : This is not needed - needed to be fixed
172174
},
173175
});

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

0 commit comments

Comments
 (0)