Skip to content

Commit d15cbfe

Browse files
Cr 2946 (#630)
* CR-2946 * CR-2946 * CR-2946
1 parent d590c64 commit d15cbfe

File tree

6 files changed

+90
-17
lines changed

6 files changed

+90
-17
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const _ = require('lodash');
2+
const gitopsUninstaller = require('../common/uninstall');
3+
4+
class ArgoCDInstall {
5+
// eslint-disable-next-line class-methods-use-this
6+
async uninstall(argv) {
7+
const uninstallOptions = _.pick(argv, ['kube-config-path', 'kube-context-name', 'kube-namespace', 'in-cluster']);
8+
return gitopsUninstaller.uninstall(argv.provider, uninstallOptions);
9+
}
10+
}
11+
module.exports = new ArgoCDInstall();

lib/interface/cli/commands/gitops/codefresh/install.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const fs = require('fs');
22
const _ = require('lodash');
33
const YAML = require('yaml');
44
const gitopsInstaller = require('../common/install');
5-
const argocdInstaller = require('../argocd/install');
65

76
const valuesMapping = {
87
'kube-config-path': 'ConfigPath',
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const _ = require('lodash');
2+
const gitopsUninstaller = require('../common/uninstall');
3+
4+
class CodefreshInstall {
5+
// eslint-disable-next-line class-methods-use-this
6+
async uninstall(argv) {
7+
const uninstallOptions = _.pick(argv, [
8+
'kube-config-path', 'kube-context-name', 'kube-namespace', 'install-manifest', 'in-cluster',
9+
]);
10+
await gitopsUninstaller.uninstall(argv.provider, uninstallOptions);
11+
}
12+
}
13+
14+
module.exports = new CodefreshInstall();
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const { downloadProvider } = require('../../hybrid/helper');
2+
const { Runner, components } = require('../../../../../binary');
3+
const _ = require('lodash');
4+
5+
class GitopsUninstaller {
6+
// eslint-disable-next-line class-methods-use-this
7+
async uninstall(provider, argv) {
8+
const { 'kube-config-path': kubeConfigPath } = argv;
9+
const binLocation = await downloadProvider({ provider });
10+
const componentRunner = new Runner(binLocation);
11+
12+
const commands = [
13+
'uninstall',
14+
];
15+
16+
if (kubeConfigPath) {
17+
commands.push('--kubeconfig');
18+
commands.push(kubeConfigPath);
19+
}
20+
21+
const installOptions = _.omit(argv, 'kube-config-path');
22+
23+
_.forEach(_.pickBy(installOptions, _.identity), (value, key) => {
24+
if (_.isArray(value)) {
25+
value.forEach((item) => {
26+
commands.push(`--${key}`);
27+
commands.push(item);
28+
});
29+
} else {
30+
commands.push(`--${key}`);
31+
if (value !== true) commands.push(value);
32+
}
33+
});
34+
35+
await componentRunner.run(components.gitops[provider], commands);
36+
}
37+
}
38+
39+
module.exports = new GitopsUninstaller();

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

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ const Command = require('../../Command');
33
const unInstallRoot = require('../root/uninstall.cmd');
44
const { downloadProvider } = require('../hybrid/helper');
55
const { Runner, components } = require('../../../../binary');
6+
const codefreshProvider = require('./codefresh/uninstall');
7+
const argocdAgentProvider = require('./argocd/uninstall');
68

9+
const PROVIDERS = {
10+
codefresh: codefreshProvider,
11+
'argocd-agent': argocdAgentProvider,
12+
};
713

814
const unInstallAgentCmd = new Command({
915
root: false,
@@ -19,27 +25,31 @@ const unInstallAgentCmd = new Command({
1925
.env('CF_ARG_')
2026
.positional('provider', {
2127
describe: 'Gitops provider',
22-
choices: ['argocd-agent'],
28+
choices: Object.keys(PROVIDERS),
2329
required: true,
2430
})
2531
.option('kube-config-path', {
2632
describe: 'Path to kubeconfig file (default is $HOME/.kube/config)',
33+
})
34+
.option('kube-context-name', {
35+
describe: 'Name of Kubernetes context',
36+
})
37+
.option('kube-namespace', {
38+
describe: 'Namespace in Kubernetes cluster',
39+
})
40+
.option('install-manifest', {
41+
describe: 'Url of argocd install manifest',
42+
default: 'https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml',
43+
})
44+
.option('in-cluster', {
45+
type: 'boolean',
46+
default: false,
47+
describe: 'Use this option if Argo agent is been updated from inside a cluster',
2748
}),
2849
handler: async (argv) => {
29-
const { 'kube-config-path': kubeConfigPath, provider } = argv;
30-
31-
const binLocation = await downloadProvider({ provider });
32-
const componentRunner = new Runner(binLocation);
33-
const commands = [
34-
'uninstall',
35-
];
36-
37-
if (kubeConfigPath) {
38-
commands.push('--kubeconfig');
39-
commands.push(kubeConfigPath);
40-
}
41-
42-
await componentRunner.run(components.gitops[provider], commands);
50+
const { provider } = argv;
51+
const providerInstaller = PROVIDERS[provider];
52+
return providerInstaller.uninstall(argv);
4353
},
4454
});
4555

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

0 commit comments

Comments
 (0)