Skip to content

Commit

Permalink
Cr 2946 (#630)
Browse files Browse the repository at this point in the history
* CR-2946

* CR-2946

* CR-2946
  • Loading branch information
olegz-codefresh committed Feb 10, 2021
1 parent d590c64 commit d15cbfe
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 17 deletions.
11 changes: 11 additions & 0 deletions lib/interface/cli/commands/gitops/argocd/uninstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const _ = require('lodash');
const gitopsUninstaller = require('../common/uninstall');

class ArgoCDInstall {
// eslint-disable-next-line class-methods-use-this
async uninstall(argv) {
const uninstallOptions = _.pick(argv, ['kube-config-path', 'kube-context-name', 'kube-namespace', 'in-cluster']);
return gitopsUninstaller.uninstall(argv.provider, uninstallOptions);
}
}
module.exports = new ArgoCDInstall();
1 change: 0 additions & 1 deletion lib/interface/cli/commands/gitops/codefresh/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const fs = require('fs');
const _ = require('lodash');
const YAML = require('yaml');
const gitopsInstaller = require('../common/install');
const argocdInstaller = require('../argocd/install');

const valuesMapping = {
'kube-config-path': 'ConfigPath',
Expand Down
14 changes: 14 additions & 0 deletions lib/interface/cli/commands/gitops/codefresh/uninstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const _ = require('lodash');
const gitopsUninstaller = require('../common/uninstall');

class CodefreshInstall {
// eslint-disable-next-line class-methods-use-this
async uninstall(argv) {
const uninstallOptions = _.pick(argv, [
'kube-config-path', 'kube-context-name', 'kube-namespace', 'install-manifest', 'in-cluster',
]);
await gitopsUninstaller.uninstall(argv.provider, uninstallOptions);
}
}

module.exports = new CodefreshInstall();
39 changes: 39 additions & 0 deletions lib/interface/cli/commands/gitops/common/uninstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const { downloadProvider } = require('../../hybrid/helper');
const { Runner, components } = require('../../../../../binary');
const _ = require('lodash');

class GitopsUninstaller {
// eslint-disable-next-line class-methods-use-this
async uninstall(provider, argv) {
const { 'kube-config-path': kubeConfigPath } = argv;
const binLocation = await downloadProvider({ provider });
const componentRunner = new Runner(binLocation);

const commands = [
'uninstall',
];

if (kubeConfigPath) {
commands.push('--kubeconfig');
commands.push(kubeConfigPath);
}

const installOptions = _.omit(argv, 'kube-config-path');

_.forEach(_.pickBy(installOptions, _.identity), (value, key) => {
if (_.isArray(value)) {
value.forEach((item) => {
commands.push(`--${key}`);
commands.push(item);
});
} else {
commands.push(`--${key}`);
if (value !== true) commands.push(value);
}
});

await componentRunner.run(components.gitops[provider], commands);
}
}

module.exports = new GitopsUninstaller();
40 changes: 25 additions & 15 deletions lib/interface/cli/commands/gitops/uninstall.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ const Command = require('../../Command');
const unInstallRoot = require('../root/uninstall.cmd');
const { downloadProvider } = require('../hybrid/helper');
const { Runner, components } = require('../../../../binary');
const codefreshProvider = require('./codefresh/uninstall');
const argocdAgentProvider = require('./argocd/uninstall');

const PROVIDERS = {
codefresh: codefreshProvider,
'argocd-agent': argocdAgentProvider,
};

const unInstallAgentCmd = new Command({
root: false,
Expand All @@ -19,27 +25,31 @@ const unInstallAgentCmd = new Command({
.env('CF_ARG_')
.positional('provider', {
describe: 'Gitops provider',
choices: ['argocd-agent'],
choices: Object.keys(PROVIDERS),
required: true,
})
.option('kube-config-path', {
describe: 'Path to kubeconfig file (default is $HOME/.kube/config)',
})
.option('kube-context-name', {
describe: 'Name of Kubernetes context',
})
.option('kube-namespace', {
describe: 'Namespace in Kubernetes cluster',
})
.option('install-manifest', {
describe: 'Url of argocd install manifest',
default: 'https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml',
})
.option('in-cluster', {
type: 'boolean',
default: false,
describe: 'Use this option if Argo agent is been updated from inside a cluster',
}),
handler: async (argv) => {
const { 'kube-config-path': kubeConfigPath, provider } = argv;

const binLocation = await downloadProvider({ provider });
const componentRunner = new Runner(binLocation);
const commands = [
'uninstall',
];

if (kubeConfigPath) {
commands.push('--kubeconfig');
commands.push(kubeConfigPath);
}

await componentRunner.run(components.gitops[provider], commands);
const { provider } = argv;
const providerInstaller = PROVIDERS[provider];
return providerInstaller.uninstall(argv);
},
});

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.74.9",
"version": "0.75.0",
"description": "Codefresh command line utility",
"main": "index.js",
"preferGlobal": true,
Expand Down

0 comments on commit d15cbfe

Please sign in to comment.