Skip to content

Commit

Permalink
CR-2946
Browse files Browse the repository at this point in the history
  • Loading branch information
olegz-codefresh committed Feb 12, 2021
1 parent 1a01afb commit 89af496
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 37 deletions.
9 changes: 9 additions & 0 deletions lib/interface/cli/commands/gitops/argocd/upgrade.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const gitopsUpgrader = require('../common/upgrade');

class ArgoCDUpgrade {
// eslint-disable-next-line class-methods-use-this
async upgrade(argv) {
return gitopsUpgrader.upgrade(argv);
}
}
module.exports = new ArgoCDUpgrade();
9 changes: 9 additions & 0 deletions lib/interface/cli/commands/gitops/codefresh/upgrade.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const gitopsUpgrader = require('../common/upgrade');

class CodefreshGitopsUpgrade {
// eslint-disable-next-line class-methods-use-this
async upgrade(argv) {
return gitopsUpgrader.upgrade(argv);
}
}
module.exports = new CodefreshGitopsUpgrade();
44 changes: 44 additions & 0 deletions lib/interface/cli/commands/gitops/common/upgrade.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const { downloadProvider } = require('../../hybrid/helper');
const { Runner, components } = require('../../../../../binary');
const _ = require('lodash');

class GitopsUpgrader {
// eslint-disable-next-line class-methods-use-this
async upgrade(argv) {
const {
provider,
'kube-config-path': kubeConfigPath,
'kube-namespace': kubeNamespace,
'kube-context-name': kubeContextName,
'in-cluster': inCluster,
} = argv;

const binLocation = await downloadProvider({ provider });
const componentRunner = new Runner(binLocation);

const commands = [
'update',
];

if (kubeConfigPath) {
commands.push('--kubeconfig');
commands.push(kubeConfigPath);
}
if (kubeNamespace) {
commands.push('--kube-namespace');
commands.push(kubeNamespace);
}
if (kubeContextName) {
commands.push('--kube-context-name');
commands.push(kubeContextName);
}
if (inCluster) {
commands.push('--in-cluster');
commands.push('true');
}

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

module.exports = new GitopsUpgrader();
47 changes: 11 additions & 36 deletions lib/interface/cli/commands/gitops/upgrade.cmd.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
const Command = require('../../Command');

const upgradeRoot = require('../root/upgrade.cmd');
const { downloadProvider } = require('../hybrid/helper');
const { Runner, components } = require('../../../../binary');
const codefreshProvider = require('./codefresh/upgrade');
const argocdAgentProvider = require('./argocd/upgrade');

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

const command = new Command({
root: false,
Expand All @@ -18,7 +22,7 @@ const command = new Command({
yargs
.positional('provider', {
describe: 'Gitops provider',
choices: ['argocd-agent'],
choices: Object.keys(PROVIDERS),
required: true,
})
.option('kube-config-path', {
Expand All @@ -41,39 +45,10 @@ const command = new Command({
);
},
handler: async (argv) => {
const {
provider,
'kube-config-path': kubeConfigPath,
'kube-namespace': kubeNamespace,
'kube-context-name': kubeContextName,
'in-cluster': inCluster,
} = argv;

const binLocation = await downloadProvider({ provider });
const componentRunner = new Runner(binLocation);

const commands = [
'update',
];

if (kubeConfigPath) {
commands.push('--kubeconfig');
commands.push(kubeConfigPath);
}
if (kubeNamespace) {
commands.push('--kube-namespace');
commands.push(kubeNamespace);
}
if (kubeContextName) {
commands.push('--kube-context-name');
commands.push(kubeContextName);
}
if (inCluster) {
commands.push('--in-cluster');
commands.push('true');
}
const { provider } = argv;

await componentRunner.run(components.gitops[provider], commands);
const providerInstaller = PROVIDERS[provider];
return providerInstaller.upgrade(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.75.1",
"version": "0.75.2",
"description": "Codefresh command line utility",
"main": "index.js",
"preferGlobal": true,
Expand Down

0 comments on commit 89af496

Please sign in to comment.