codefresh 1.3.5 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/lib/binary/components.js +0 -57
  2. package/lib/interface/cli/commands/agent/install.cmd.js +6 -126
  3. package/lib/interface/cli/commands/components/download.cmd.js +1 -1
  4. package/lib/interface/cli/commands/hybrid/execute-test-pipeline.cmd.js +37 -11
  5. package/lib/interface/cli/commands/hybrid/helper.js +8 -896
  6. package/lib/interface/cli/commands/runtimeEnvironments/attach.cmd.js +3 -103
  7. package/lib/interface/cli/commands/runtimeEnvironments/install.cmd.js +8 -134
  8. package/lib/interface/cli/completion/tree.json +1 -1
  9. package/lib/interface/cli/helpers/kubernetes.js +8 -42
  10. package/package.json +3 -22
  11. package/lib/interface/cli/commands/agent/uninstall.cmd.js +0 -92
  12. package/lib/interface/cli/commands/app-proxy/helper.js +0 -63
  13. package/lib/interface/cli/commands/app-proxy/install.cmd.js +0 -204
  14. package/lib/interface/cli/commands/app-proxy/uninstall.cmd.js +0 -175
  15. package/lib/interface/cli/commands/app-proxy/upgrade.cmd.js +0 -110
  16. package/lib/interface/cli/commands/gitops/argocd/install.js +0 -9
  17. package/lib/interface/cli/commands/gitops/argocd/uninstall.js +0 -11
  18. package/lib/interface/cli/commands/gitops/argocd/upgrade.js +0 -9
  19. package/lib/interface/cli/commands/gitops/codefresh/install.js +0 -50
  20. package/lib/interface/cli/commands/gitops/codefresh/uninstall.js +0 -14
  21. package/lib/interface/cli/commands/gitops/codefresh/upgrade.js +0 -9
  22. package/lib/interface/cli/commands/gitops/common/install.js +0 -62
  23. package/lib/interface/cli/commands/gitops/common/uninstall.js +0 -39
  24. package/lib/interface/cli/commands/gitops/common/upgrade.js +0 -45
  25. package/lib/interface/cli/commands/gitops/install.cmd.js +0 -116
  26. package/lib/interface/cli/commands/gitops/install.spec.js +0 -77
  27. package/lib/interface/cli/commands/gitops/uninstall.cmd.js +0 -56
  28. package/lib/interface/cli/commands/gitops/upgrade.cmd.js +0 -56
  29. package/lib/interface/cli/commands/hybrid/InstallationPlan.js +0 -216
  30. package/lib/interface/cli/commands/hybrid/delete.cmd.js +0 -341
  31. package/lib/interface/cli/commands/hybrid/init.cmd.js +0 -957
  32. package/lib/interface/cli/commands/hybrid/installation-process.js +0 -51
  33. package/lib/interface/cli/commands/hybrid/key-helper.js +0 -82
  34. package/lib/interface/cli/commands/hybrid/migration.js +0 -192
  35. package/lib/interface/cli/commands/hybrid/pipeline-helper.js +0 -71
  36. package/lib/interface/cli/commands/hybrid/upgrade.cmd.js +0 -195
  37. package/lib/interface/cli/commands/monitor/install.cmd.js +0 -160
  38. package/lib/interface/cli/commands/monitor/uninstall.cmd.js +0 -78
  39. package/lib/interface/cli/commands/root/uninstall.cmd.js +0 -17
  40. package/lib/interface/cli/commands/runtimeEnvironments/create.cmd.js +0 -23
  41. package/lib/interface/cli/commands/runtimeEnvironments/uninstall.cmd.js +0 -149
  42. package/lib/interface/cli/helpers/progressEvents.js +0 -25
@@ -1,51 +0,0 @@
1
- const Promise = require('bluebird');
2
- const { to } = require('./../../../../logic/cli-config/errors/awaitTo');
3
-
4
- async function create(installer, event) {
5
- const [err, res] = await to(installer.createNewInstallationProgress(event));
6
- if (err) {
7
- return {};
8
- }
9
- return res.progress;
10
- }
11
-
12
- function buildReporter(installer, progress) {
13
- return {
14
- report: async (event, status, options = {}) => {
15
- if (!progress.id) {
16
- return Promise.resolve();
17
- }
18
- const data = {
19
- event,
20
- content: {
21
- status,
22
- ...options,
23
- },
24
- };
25
- return installer.reportInstallationProgressEvent({ id: progress.id }, data);
26
- },
27
- };
28
- }
29
-
30
- module.exports = {
31
- create,
32
- buildReporter,
33
- events: {
34
- ACCEPTANCE_TESTS_RAN: 'acceptance-tests-ran',
35
- AGENT_INSTALLED: 'agent-installed',
36
- AGENT_CREATED: 'agent-created',
37
- RUNNER_INSTALLED: 'runner-installed',
38
- MONITOR_INSTALLED: 'monitor-installed',
39
- CLUSTER_INTEGRATION_ADDED: 'cluster-integration-added',
40
- AGENT_UPDATED: 'agent-updated',
41
- RUNTIME_INSTALLED: 'runtime-installed',
42
- APP_PROXY_INSTALLED: 'app-proxy-installed',
43
- PIPELINE_EXECUTED: 'demo-pipeline-executed',
44
- PIPELINE_CREATED: 'demo-pipeline-created',
45
- FINISHED: 'finished',
46
- },
47
- status: {
48
- SUCCESS: 'success',
49
- FAILURE: 'failure',
50
- },
51
- };
@@ -1,82 +0,0 @@
1
- const forge = require('node-forge');
2
- const rp = require('request-promise');
3
- const AdmZip = require('adm-zip');
4
-
5
- const sdk = require('../../../../logic/sdk');
6
- // eslint-disable-next-line prefer-destructuring
7
- const pki = forge.pki;
8
- // eslint-disable-next-line prefer-destructuring
9
- const rsa = pki.rsa;
10
-
11
- const defaultCertCN = 'docker.codefresh.io';
12
-
13
- function generateKeys() {
14
- return new Promise((resolve, reject) => {
15
- function keyGenerated(err, { publicKey, privateKey }) {
16
- if (err) {
17
- reject(err);
18
- return;
19
- }
20
-
21
- const csr = pki.createCertificationRequest();
22
- csr.publicKey = publicKey;
23
- csr.setSubject([{
24
- name: 'commonName',
25
- value: defaultCertCN,
26
- }]);
27
- csr.sign(privateKey);
28
-
29
- resolve({
30
- key: pki.privateKeyToPem(privateKey),
31
- csr: pki.certificationRequestToPem(csr),
32
- });
33
- }
34
-
35
- rsa.generateKeyPair({
36
- bits: 2048,
37
- }, keyGenerated);
38
- });
39
- }
40
-
41
- function extractZipCerts(zip) {
42
- const data = {};
43
- const admZip = new AdmZip(zip);
44
- admZip.forEach(e => {
45
- if (e.entryName === 'cf-ca.pem') {
46
- data.ca = admZip.readAsText(e);
47
- }
48
- if (e.entryName === 'cf-server-cert.pem') {
49
- data.serverCert = admZip.readAsText(e);
50
- }
51
- });
52
- return data;
53
- }
54
-
55
- async function produceVenonaKeys(namespace) {
56
- const keys = await generateKeys();
57
- const body = JSON.stringify({
58
- reqSubjectAltName: `IP:127.0.0.1,DNS:dind,DNS:*.dind.${namespace},DNS:*.dind.${namespace}.svc,DNS:*.cf-cd.com,DNS:*.codefresh.io`,
59
- csr: keys.csr,
60
- });
61
-
62
- const zip = await rp.post({
63
- uri: `${sdk.config.context.url}/api/custom_clusters/signServerCerts`,
64
- body,
65
- encoding: null,
66
- headers: {
67
- 'Content-type': 'application/json',
68
- Authorization: sdk.config.context.token,
69
- },
70
- });
71
-
72
- const allKeys = {
73
- ...keys,
74
- ...extractZipCerts(zip),
75
- };
76
-
77
- return allKeys;
78
- }
79
-
80
- module.exports = {
81
- produceVenonaKeys,
82
- };
@@ -1,192 +0,0 @@
1
- const _ = require('lodash');
2
- const { to } = require('./../../../../logic/cli-config/errors/awaitTo');
3
- const { sdk } = require('../../../../logic');
4
- const installAgent = require('../agent/install.cmd');
5
- const installMonitoring = require('../monitor/install.cmd');
6
- const colors = require('colors');
7
- const inquirer = require('inquirer').default;
8
- const fs = require('fs');
9
- const {
10
- getTestPipeline,
11
- updateTestPipelineRuntime,
12
- createTestPipeline,
13
- executeTestPipeline,
14
- createProgressBar,
15
- runUpgrade,
16
- serealizeToKeyValuePairs,
17
- } = require('./helper');
18
- const { getNewAgentName } = require('../agent/helper');
19
-
20
-
21
- const TEST_PIPELINE_NAME = 'CF_Runner_Migration_test';
22
-
23
- async function createAndRunTestPipeline(runtimeName, errHandler) {
24
- let testPipeline;
25
- const [getPipelineErr, _testPipeline] = await to(getTestPipeline(TEST_PIPELINE_NAME));
26
- testPipeline = _testPipeline;
27
- await errHandler(getPipelineErr, 'Could not get test pipeline');
28
- if (!testPipeline) {
29
- // eslint-disable-next-line no-shadow
30
- const [createPipelineErr, _testPipeline] = await to(createTestPipeline(
31
- runtimeName,
32
- TEST_PIPELINE_NAME,
33
- [`echo runtime ${runtimeName} migrated successfully!`],
34
- ));
35
- await errHandler(createPipelineErr, 'Failed to create test pipeline');
36
- testPipeline = _testPipeline;
37
- } else {
38
- const [updatePipelineErr] = await to(updateTestPipelineRuntime(testPipeline, runtimeName));
39
- if (updatePipelineErr) {
40
- console.log(colors.yellow('*warning* failed to update test pipeline runtime, you can' +
41
- ' change it manually if you want to run it again on this runtime'));
42
- }
43
- }
44
- const [runPipelineErr] = await to(executeTestPipeline(
45
- runtimeName,
46
- testPipeline.metadata.name,
47
- ));
48
- await errHandler(runPipelineErr, 'Failed to run test pipeline');
49
- }
50
-
51
- async function migrate({
52
- runtimeName,
53
- kubeContextName,
54
- kubeNamespace,
55
- installMonitor,
56
- agentName,
57
- handleError,
58
- kubeConfigPath,
59
- shouldMakeDefaultRe,
60
- storageClassName,
61
- setValue,
62
- setFile,
63
- verbose,
64
- agents,
65
- }) {
66
- const newAgentName = agentName || await getNewAgentName(kubeContextName, kubeNamespace, agents);
67
- const [getRuntimeErr, runtime] = await to(sdk.runtimeEnvs.get({ name: runtimeName }));
68
- handleError(getRuntimeErr, `Failed to get runtime with name "${runtimeName}"`);
69
- let oldNodeSelector = _.get(runtime, 'dockerDaemonScheduler.cluster.nodeSelector');
70
- const oldStorageClassName = _.get(runtime, 'dockerDaemonScheduler.pvcs.dind.storageClassName');
71
-
72
- // prompt migration process confirmation
73
- console.log(`${colors.red('This migration process will do the following:')}`);
74
- console.log('\u2022 Delete the old venona deployment and secrets from the selected namespace');
75
- console.log(`\u2022 Create a new Codefresh runner with the name "${colors.cyan(newAgentName)}" on the selected namespace`);
76
- console.log(`\u2022 Attach runtime "${colors.cyan(runtimeName)}" to the new Codefresh runner`);
77
- console.log('\u2022 Install Codefresh runner monitoring components on the selected namespace');
78
- console.log('\u2022 Run a test pipeline to check that the migration was successful\n');
79
-
80
- const answer = await inquirer.prompt({
81
- type: 'confirm',
82
- name: 'migrationConfirmed',
83
- default: false,
84
- message: 'Are you sure you want to proceed with the migration process?',
85
- });
86
- if (!answer.migrationConfirmed) {
87
- console.log('Migration process aborted, exiting...');
88
- process.exit(1);
89
- }
90
-
91
- // prepare old runtime
92
- if (oldStorageClassName && oldStorageClassName.startsWith('dind-local-volumes-venona')) {
93
- // need to replace to start with 'dind-local-volumes-runner'
94
- const newRe = _.set(runtime, 'dockerDaemonScheduler.pvcs.dind.storageClassName', oldStorageClassName.replace('venona', 'runner'));
95
- const [err] = await to(sdk.runtimeEnvs.update({ name: runtimeName }, newRe));
96
- handleError(err, 'Failed to update runtime storage class name');
97
- }
98
-
99
- // delete old agent and runtime
100
- console.log(`Running migration script on runtime: ${colors.cyan(runtimeName)}`);
101
- const [migrateScriptErr, migrateScriptExitCode] = await to(sdk.agents.migrate({
102
- kubeContextName,
103
- kubeNamespace,
104
- verbose,
105
- events: createProgressBar(),
106
- }));
107
- handleError(migrateScriptErr, 'Failed to execute migration script');
108
- if (migrateScriptExitCode !== 0) {
109
- handleError(new Error(`migration script exited with code ${migrateScriptExitCode}`), 'Migration failed');
110
- }
111
-
112
- // read old deploment configuration
113
- const filename = './migration.json';
114
- let oldConfig = {};
115
- let oldEnv;
116
- try {
117
- const data = fs.readFileSync(filename).toString('utf-8');
118
- oldConfig = JSON.parse(data);
119
- } catch (err) {
120
- console.log(colors.yellow(`could not read old deployment configuration file: ${err}`));
121
- }
122
-
123
- if (oldConfig.tolerations) {
124
- oldConfig.tolerations = oldConfig.tolerations.filter(t => !t.key.includes('node.kubernetes.io'));
125
- }
126
-
127
- if (oldConfig.nodeSelector) {
128
- oldConfig.nodeSelector = serealizeToKeyValuePairs(oldConfig.nodeSelector);
129
- }
130
-
131
- if (oldNodeSelector) {
132
- oldNodeSelector = serealizeToKeyValuePairs(oldNodeSelector);
133
- }
134
- if (oldConfig.env) {
135
- oldEnv = serealizeToKeyValuePairs(oldConfig.env);
136
- }
137
-
138
- // install new agent and runtime
139
- console.log(`Creating new codefresh runner with name: ${colors.cyan(newAgentName)}`);
140
- const agentInstallOptions = {
141
- name: newAgentName,
142
- 'kube-context-name': kubeContextName,
143
- 'kube-node-selector': oldConfig.nodeSelector,
144
- 'build-node-selector': oldNodeSelector,
145
- 'kube-namespace': kubeNamespace,
146
- 'agent-kube-namespace': kubeNamespace,
147
- 'agent-kube-context-name': kubeContextName,
148
- 'agent-kube-config-path': kubeConfigPath,
149
- tolerations: JSON.stringify(oldConfig.tolerations),
150
- 'kube-config-path': kubeConfigPath,
151
- 'install-runtime': true,
152
- 'runtime-name': runtimeName,
153
- 'skip-re-creation': true,
154
- verbose,
155
- 'make-default-runtime': shouldMakeDefaultRe,
156
- 'storage-class-name': storageClassName || oldStorageClassName,
157
- terminateProcess: false,
158
- 'set-value': setValue,
159
- 'set-file': setFile,
160
- envVars: oldEnv,
161
- };
162
- const [agentInstallErr] = await to(installAgent.handler(agentInstallOptions));
163
- handleError(agentInstallErr, 'Failed to install new agent and runtime');
164
-
165
- // Install new monitoring components
166
- if (installMonitor) {
167
- console.log('Installing monitoring components');
168
- const monitorInstallOptions = {
169
- 'kube-config-path': kubeConfigPath,
170
- 'cluster-id': kubeContextName,
171
- 'kube-context-name': kubeContextName,
172
- 'kube-namespace': kubeNamespace,
173
- token: _.get(sdk, 'config.context.token'),
174
- verbose,
175
- noExit: true, // to prevent if from calling inner: process.exit()
176
- };
177
- const [monitorErr] = await to(installMonitoring.handler(monitorInstallOptions));
178
- await handleError(monitorErr, 'Monitor installation failed');
179
- }
180
-
181
- // Execute test pipeline on new runner
182
- await createAndRunTestPipeline(runtimeName, handleError);
183
- }
184
-
185
- async function upgrade({ kubeContextName, kubeNamespace, handleError }) {
186
- const [err] = await to(runUpgrade({ kubeNamespace, kubeContextName }));
187
- await handleError(err, 'Upgrade failed');
188
- }
189
- module.exports = {
190
- migrate,
191
- upgrade,
192
- };
@@ -1,71 +0,0 @@
1
- const sdk = require('../../../../logic/sdk');
2
- const colors = require('colors');
3
- const installationProgress = require('./installation-process');
4
- const _ = require('lodash');
5
-
6
- const {
7
- createTestPipeline,
8
- executeTestPipeline,
9
- updateTestPipelineRuntime,
10
- INSTALLATION_DEFAULTS,
11
- } = require('./helper');
12
-
13
- const defaultDockerRegistry = 'quay.io';
14
-
15
- async function addPipelineToInstallationPlan(installationPlan, dockerRegistry = '', executePipeline = true) {
16
- if (!dockerRegistry) {
17
- // eslint-disable-next-line no-param-reassign
18
- dockerRegistry = defaultDockerRegistry;
19
- }
20
-
21
- const pipelines = await sdk.pipelines.list({ id: `${INSTALLATION_DEFAULTS.PROJECT_NAME}/${INSTALLATION_DEFAULTS.DEMO_PIPELINE_NAME}` });
22
- const testPipelineExists = !!_.get(pipelines, 'docs.length');
23
-
24
- if (!testPipelineExists) {
25
- installationPlan.addStep({
26
- name: 'create test pipeline',
27
- func: async () => {
28
- await createTestPipeline(
29
- installationPlan.getContext('runtimeName'),
30
- INSTALLATION_DEFAULTS.DEMO_PIPELINE_NAME,
31
- ['echo hello Codefresh Runner!'],
32
- dockerRegistry,
33
- );
34
- },
35
- installationEvent: installationProgress.events.PIPELINE_CREATED,
36
- });
37
- } else {
38
- installationPlan.addStep({
39
- name: 'update test pipeline runtime',
40
- func: async () => {
41
- await updateTestPipelineRuntime(
42
- undefined,
43
- installationPlan.getContext('runtimeName'),
44
- INSTALLATION_DEFAULTS.DEMO_PIPELINE_NAME,
45
- dockerRegistry,
46
- );
47
- },
48
- errMessage: colors.yellow('*warning* could not update test pipeline runtime, you can' +
49
- ' change it manually if you want to run it again on this runtime'),
50
- successMessage: 'Updated test pipeline runtime',
51
- exitOnError: false,
52
- });
53
- }
54
-
55
- installationPlan.addStep({
56
- name: 'execute test pipeline',
57
- func: async () => {
58
- await executeTestPipeline(
59
- installationPlan.getContext('runtimeName'),
60
- INSTALLATION_DEFAULTS.DEMO_PIPELINE_NAME,
61
- );
62
- },
63
- errMessage: 'Failed to execute test pipeline',
64
- installationEvent: installationProgress.events.PIPELINE_EXECUTED,
65
- condition: executePipeline,
66
- });
67
- }
68
-
69
- module.exports = {
70
- addPipelineToInstallationPlan,
71
- };
@@ -1,195 +0,0 @@
1
-
2
- /* eslint-disable max-len */
3
- const Command = require('../../Command');
4
- const runnerRoot = require('../root/runner.cmd');
5
- const inquirer = require('inquirer').default;
6
- const { getAllKubeContexts, getKubeContext, getAllNamespaces } = require('../../helpers/kubernetes');
7
- const colors = require('colors');
8
- const DEFAULTS = require('../../defaults');
9
- const sdk = require('../../../../logic/sdk');
10
- const _ = require('lodash');
11
- const semver = require('semver');
12
- const { to } = require('./../../../../logic/cli-config/errors/awaitTo');
13
- const {
14
- createErrorHandler,
15
- getRuntimesWithVersions,
16
- getRuntimeVersion,
17
- drawCodefreshFiglet,
18
- } = require('./helper');
19
- const { migrate, upgrade } = require('./migration');
20
-
21
- const openIssueMessage = `If you had any issues with the upgrade process please report them at: ${colors.blue('https://github.com/codefresh-io/cli/issues/new')}`;
22
- const handleError = createErrorHandler(openIssueMessage);
23
-
24
- function isOldVersion(version) {
25
- const v = version.split('x').join('0');
26
- return semver.lt(v, '1.0.0');
27
- }
28
-
29
- function getStrategy(shouldDoMigration) {
30
- return shouldDoMigration ? migrate : upgrade;
31
- }
32
-
33
- const upgradeCmd = new Command({
34
- root: false,
35
- parent: runnerRoot,
36
- command: 'upgrade',
37
- requiresAuthentication: false,
38
- description: 'Upgrades codefresh runner solution\'s components',
39
- webDocs: {
40
- category: 'Runner',
41
- title: 'Upgrade',
42
- weight: 100,
43
- },
44
- builder: yargs => yargs
45
- .env('CF_ARG_')
46
- .option('agent-name', {
47
- describe: 'The name of the agent to be upgraded or created',
48
- })
49
- .option('runtime-name', {
50
- describe: 'The name of the runtime to be upgraded',
51
- })
52
- .option('url', {
53
- describe: 'Codefresh system custom url',
54
- default: DEFAULTS.URL,
55
- })
56
- .option('kube-context-name', {
57
- describe: 'Name of the kubernetes context from which the Codefresh Agent and Runtime should be removed',
58
- })
59
- .option('kube-namespace', {
60
- describe: 'Name of the kubernetes namespace from which the Codefresh Agent and Runtime should be removed',
61
- })
62
- .option('kube-config-path', {
63
- describe: 'Path to kubeconfig file (default is $HOME/.kube/config)',
64
- })
65
- .option('install-monitor', {
66
- describe: 'Install a monitoring component that will help provide valueable data about your cluster to Codefresh (only useable when running migration)',
67
- type: 'boolean',
68
- default: true,
69
- })
70
- .option('verbose', {
71
- describe: 'Print logs',
72
- }),
73
- handler: async (argv) => {
74
- const {
75
- 'kube-config-path': kubeConfigPath,
76
- 'agent-name': agentName,
77
- 'install-monitor': installMonitor,
78
- verbose,
79
- } = argv;
80
- let {
81
- 'kube-context-name': kubeContextName,
82
- 'kube-namespace': kubeNamespace,
83
- 'runtime-name': runtimeName,
84
- } = argv;
85
-
86
- const [listReErr, runtimes] = await to(sdk.runtimeEnvs.list({ }));
87
- await handleError(listReErr, 'Failed to get runtime environments');
88
- const runtimesByName = runtimes.reduce((acc, cur) => ({ ...acc, [cur.metadata.name]: cur }), {});
89
-
90
- const [listAgentsErr, agents] = await to(sdk.agents.list({ }));
91
- await handleError(listAgentsErr, 'Failed to get agents');
92
- const agentsByName = agents.reduce((acc, cur) => ({ ...acc, [cur.name]: cur }), {});
93
-
94
- console.log(colors.green('This upgrader will guide you through the runner upgrade process'));
95
-
96
- let runtimeVersion;
97
-
98
- if (agentName && agentsByName[agentName]) {
99
- const agent = agentsByName[agentName];
100
- const attachedRuntimes = agent.runtimes || [];
101
- if (attachedRuntimes.length === 1) {
102
- [runtimeName] = attachedRuntimes;
103
- console.log(`Chose to upgrade runner: "${colors.cyan(agentName)}" and runtime: "${colors.cyan(runtimeName)}"`);
104
- }
105
- }
106
-
107
- if (!runtimeName) {
108
- const runtimesWithVersions = getRuntimesWithVersions(runtimes, agents);
109
- if (!_.size(runtimesWithVersions)) {
110
- handleError(new Error('Found 0 runtime environments that can be upgraded or migrated'), 'no runtimes found');
111
- }
112
-
113
- // for fast lookup of the choice
114
- const runtimesWithVersionsStrings = {};
115
- _.map(_.keys(runtimesWithVersions), (re) => { runtimesWithVersionsStrings[`${re}\t(version ${runtimesWithVersions[re]})\t${runtimesWithVersions[re] === '0.x.x' ? '[migrate]' : '[upgrade]'}`] = re; });
116
-
117
- const answer = await inquirer.prompt({
118
- type: 'list',
119
- name: 'runtime',
120
- message: 'The runtimes that can be upgraded or migrated (if version < 1.x.x)',
121
- choices: _.keys(runtimesWithVersionsStrings),
122
- });
123
-
124
- runtimeName = runtimesWithVersionsStrings[answer.runtime];
125
- runtimeVersion = runtimesWithVersions[runtimeName];
126
- } else {
127
- runtimeVersion = getRuntimeVersion(runtimeName, agents);
128
- }
129
- const runtime = runtimesByName[runtimeName];
130
- if (!runtime) {
131
- handleError(new Error(`runtime environment "${colors.cyan(runtimeName)}" does not exist on this account. run "${colors.cyan('codefresh get re')}" to get all runtimes-environments of this account`), 'runtime environment not found');
132
- }
133
- runtime.metadata.version = runtimeVersion;
134
-
135
- if (!kubeContextName) {
136
- const contexts = getAllKubeContexts(kubeConfigPath);
137
- const currentKubeContext = getKubeContext(kubeConfigPath);
138
-
139
- const answer = await inquirer.prompt({
140
- type: 'list',
141
- name: 'context',
142
- message: 'Name of Kubernetes context to use',
143
- default: currentKubeContext,
144
- choices: contexts,
145
- });
146
-
147
- kubeContextName = answer.context;
148
- }
149
-
150
- if (!kubeNamespace) {
151
- kubeNamespace = _.get(runtime, 'runtimeScheduler.cluster.namespace');
152
- }
153
-
154
- if (!kubeNamespace) {
155
- const [err, namespaces] = await to(getAllNamespaces(kubeConfigPath, kubeContextName));
156
- handleError(err, 'Failed to get cluster namespaces');
157
-
158
- const answer = await inquirer.prompt({
159
- type: 'list',
160
- name: 'namespace',
161
- message: 'Kubernetes namespace on which the runtime to be upgraded/migrated is installed',
162
- choices: namespaces,
163
- });
164
-
165
- kubeNamespace = answer.namespace;
166
- }
167
-
168
- console.log(`\n${colors.green('Upgrade options summary:')}
169
- 1. Kubernetes Context: ${colors.cyan(kubeContextName)}
170
- 2. Kubernetes Namespace: ${colors.cyan(kubeNamespace)}
171
- 3. Runtime name: ${colors.cyan(runtimeName)}
172
- `);
173
-
174
- const shouldDoMigration = isOldVersion(runtime.metadata.version);
175
- const strategy = getStrategy(shouldDoMigration);
176
- const [err] = await to(strategy({
177
- kubeContextName,
178
- kubeNamespace,
179
- agentName,
180
- agents,
181
- runtimeName,
182
- installMonitor,
183
- verbose,
184
- handleError,
185
- }));
186
- handleError(err, `Failed to ${shouldDoMigration ? 'migrate' : 'upgrade'} codefresh runner`);
187
-
188
- console.log(colors.green(`\nSuccessfully ${shouldDoMigration ? 'migrated' : 'upgraded'} your Codefresh Runner to the latest version`));
189
- console.log(colors.green(`If you had any issues with the migration process please report them at: ${colors.blue('https://github.com/codefresh-io/cli/issues/new')}`));
190
- await drawCodefreshFiglet();
191
- process.exit(); // TODO : This is not needed - needed to be fixed
192
- },
193
- });
194
-
195
- module.exports = upgradeCmd;