Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion lib/interface/cli/commands/agent/uninstall.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const unInstallAgentCmd = new Command({
name,
'kube-namespace': kubeNamespace,
'kube-config-path': kubeConfigPath,
terminateProcess,

} = argv;

Expand Down Expand Up @@ -80,7 +81,9 @@ const unInstallAgentCmd = new Command({
console.log('Agent uninsalled successfully');
await deleteAgent.handler({ name, id: name });
}
process.exit(0);
if (terminateProcess !== false) {
process.exit(0);
}
},
});

Expand Down
127 changes: 127 additions & 0 deletions lib/interface/cli/commands/hybrid/delete.cmd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/* eslint-disable max-len */
const Command = require('../../Command');
const runnerRoot = require('../root/runner.cmd');
const inquirer = require('inquirer');
const { getAllKubeContexts, getKubeContext } = require('../../helpers/kubernetes');
const unInstallRuntime = require('../runtimeEnvironments/uninstall.cmd');
const unInstallAgent = require('../agent/uninstall.cmd');
const colors = require('colors');
const DEFAULTS = require('../../defaults');
const sdk = require('../../../../logic/sdk');
const _ = require('lodash');

const defaultNamespace = 'codefresh';

const deleteCmd = new Command({
root: false,
parent: runnerRoot,
command: 'delete',
requiresAuthentication: false,
description: 'Deletes codefresh runner solution\'s components on kubernetes cluster',
webDocs: {
category: 'Runner',
title: 'Delete',
weight: 100,
},
// requiresAuthentication: argv => argv && !argv.token,
builder: yargs => yargs
.env('CF_ARG_') // this means that every process.env.CF_ARG_* will be passed to argv
.option('name', {
describe: 'Agent\'s name to be deleted',
})
.option('url', {
describe: 'Codefresh system custom url',
default: DEFAULTS.URL,
})
.option('kube-context-name', {
describe: 'Name of the kubernetes context on which venona should be installed [$CF_ARG_KUBE_CONTEXT_NAME]',
})
.option('kube-namespace', {
describe: 'Name of the namespace on which venona should be installed [$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-config-path': kubeConfigPath,
} = argv;
let {
'kube-context-name': kubeContextName,
'kube-namespace': kubeNamespace,
name: agentName,
} = argv;

const questions = [];
if (!kubeContextName) {
const contexts = getAllKubeContexts(kubeConfigPath);
const currentKubeContext = getKubeContext(kubeConfigPath);

questions.push({
type: 'list',
name: 'context',
message: 'Name of Kubernetes context to use',
default: currentKubeContext,
choices: contexts,
});
}
if (!kubeNamespace) {
questions.push({
type: 'input',
name: 'namespace',
default: defaultNamespace,
message: 'Kubernetes namespace to remove Runner components from it ',
validate: value => (value !== undefined && value !== '') || 'Please enter namespace\'s name',
});
}
const agents = await sdk.agents.list({});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we show here only the relavant agents that would be way better

if (!agentName) {
questions.push({
type: 'list',
name: 'name',
message: 'Runner manager name to uninstall',
choices: agents,
});
}
console.log(colors.green('This uninstaller will guide you through the hybrid uninstallation process'));
const answers = await inquirer.prompt(questions);
kubeContextName = kubeContextName || answers.context;
kubeNamespace = kubeNamespace || answers.namespace;
agentName = agentName || answers.name;
// check that agent exists
const agent = _.find(agents, curr => curr.name === agentName);
if (!agent) {
console.log(colors.red(`Runner manager with name ${agentName} doesn\'t exists`));
return;
}
if (agent.runtimes && agent.runtimes > 1) {
console.log('Can\'t delete runner with more than one runtime , use runtime delete command');
return;
}
console.log(colors.green(`Uninstallation options summary : \n Context: ${colors.blue(kubeContextName)} \n Namespace: ${colors.blue(kubeNamespace)} \n Agent name: ${colors.blue(agentName)} `));
if (agent.runtimes.length === 1) {
await unInstallRuntime.handler({
'agent-name': agentName,
'runtime-kube-namespace': kubeNamespace,
'runtime-kube-context-name': kubeContextName,
'agent-kube-context-name': kubeContextName,
'agent-kube-namespace': kubeNamespace,
name: agent.runtimes[0],
terminateProcess: false,
});
}
await unInstallAgent.handler({
'kube-namespace': kubeNamespace,
'kube-context-name': kubeContextName,
name: agentName,
terminateProcess: false,
});
console.log('Successfully uninstalled Codefresh runner');
process.exit(); // TODO : This is not needed - needed to be fixed
},
});

module.exports = deleteCmd;
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const unInstallRuntimeCmd = new Command({
'restart-agent': restartAgent,
'agent-kube-config-path': agentKubeConfigPath,
verbose,
terminateProcess,

} = argv;

Expand Down Expand Up @@ -137,7 +138,7 @@ const unInstallRuntimeCmd = new Command({
restartAgent,
storageClassName,
verbose,
terminateProcess: true,
terminateProcess: (terminateProcess !== false),
events,
});
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codefresh",
"version": "0.59.1",
"version": "0.60.0",
"description": "Codefresh command line utility",
"main": "index.js",
"preferGlobal": true,
Expand Down