codefresh 1.2.9 → 1.2.11
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.
- package/lib/binary/components.js +0 -38
- package/lib/interface/cli/commands/components/download.cmd.js +1 -1
- package/lib/interface/cli/commands/hybrid/helper.js +1 -877
- package/lib/interface/cli/completion/tree.json +1 -1
- package/package.json +2 -11
- package/lib/interface/cli/commands/agent/helper.js +0 -28
- package/lib/interface/cli/commands/agent/install.cmd.js +0 -283
- package/lib/interface/cli/commands/agent/uninstall.cmd.js +0 -92
- package/lib/interface/cli/commands/app-proxy/helper.js +0 -63
- package/lib/interface/cli/commands/app-proxy/install.cmd.js +0 -204
- package/lib/interface/cli/commands/app-proxy/uninstall.cmd.js +0 -175
- package/lib/interface/cli/commands/app-proxy/upgrade.cmd.js +0 -110
- package/lib/interface/cli/commands/gitops/argocd/install.js +0 -9
- package/lib/interface/cli/commands/gitops/argocd/uninstall.js +0 -11
- package/lib/interface/cli/commands/gitops/argocd/upgrade.js +0 -9
- package/lib/interface/cli/commands/gitops/codefresh/install.js +0 -50
- package/lib/interface/cli/commands/gitops/codefresh/uninstall.js +0 -14
- package/lib/interface/cli/commands/gitops/codefresh/upgrade.js +0 -9
- package/lib/interface/cli/commands/gitops/common/install.js +0 -62
- package/lib/interface/cli/commands/gitops/common/uninstall.js +0 -39
- package/lib/interface/cli/commands/gitops/common/upgrade.js +0 -45
- package/lib/interface/cli/commands/gitops/install.cmd.js +0 -116
- package/lib/interface/cli/commands/gitops/install.spec.js +0 -77
- package/lib/interface/cli/commands/gitops/uninstall.cmd.js +0 -56
- package/lib/interface/cli/commands/gitops/upgrade.cmd.js +0 -56
- package/lib/interface/cli/commands/hybrid/delete.cmd.js +0 -341
- package/lib/interface/cli/commands/hybrid/init.cmd.js +0 -957
- package/lib/interface/cli/commands/hybrid/key-helper.js +0 -82
- package/lib/interface/cli/commands/hybrid/migration.js +0 -192
- package/lib/interface/cli/commands/hybrid/upgrade.cmd.js +0 -195
- package/lib/interface/cli/commands/monitor/install.cmd.js +0 -160
- package/lib/interface/cli/commands/monitor/uninstall.cmd.js +0 -78
- package/lib/interface/cli/commands/root/install.cmd.js +0 -17
- package/lib/interface/cli/commands/root/uninstall.cmd.js +0 -17
- package/lib/interface/cli/commands/runtimeEnvironments/attach.cmd.js +0 -180
- package/lib/interface/cli/commands/runtimeEnvironments/create.cmd.js +0 -23
- package/lib/interface/cli/commands/runtimeEnvironments/install.cmd.js +0 -340
- package/lib/interface/cli/commands/runtimeEnvironments/uninstall.cmd.js +0 -149
- package/lib/interface/cli/helpers/kubernetes.js +0 -61
- package/lib/interface/cli/helpers/progressEvents.js +0 -25
|
@@ -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,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;
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
/* eslint-disable max-len */
|
|
2
|
-
const Command = require('../../Command');
|
|
3
|
-
const installRoot = require('../root/install.cmd');
|
|
4
|
-
const { DefaultLogFormatter } = require('./../hybrid/helper');
|
|
5
|
-
const { downloadVeonona } = require('../hybrid/helper');
|
|
6
|
-
const { Runner, components } = require('../../../../binary');
|
|
7
|
-
const sdk = require('../../../../logic/sdk');
|
|
8
|
-
const _ = require('lodash');
|
|
9
|
-
|
|
10
|
-
const installMonitorCmd = new Command({
|
|
11
|
-
root: false,
|
|
12
|
-
parent: installRoot,
|
|
13
|
-
command: 'monitor',
|
|
14
|
-
description: 'Install and create an cluster resources monitor on kubernetes cluster',
|
|
15
|
-
webDocs: {
|
|
16
|
-
category: 'Monitor',
|
|
17
|
-
title: 'Install',
|
|
18
|
-
weight: 100,
|
|
19
|
-
},
|
|
20
|
-
builder: yargs => yargs
|
|
21
|
-
.env('CF_ARG_') // this means that every process.env.CF_ARG_* will be passed to argv
|
|
22
|
-
.option('cluster-id', {
|
|
23
|
-
describe: 'Cluster id - freestyle name',
|
|
24
|
-
})
|
|
25
|
-
.option('token', {
|
|
26
|
-
describe: 'Codefresh user token',
|
|
27
|
-
})
|
|
28
|
-
.option('kube-config-path', {
|
|
29
|
-
describe: 'Path to kubeconfig file (default is $HOME/.kube/config)',
|
|
30
|
-
type: 'string',
|
|
31
|
-
})
|
|
32
|
-
.option('kube-context-name', {
|
|
33
|
-
describe: 'Name of the kubernetes context on which monitor should be installed [$CF_ARG_KUBE_CONTEXT_NAME]',
|
|
34
|
-
})
|
|
35
|
-
.option('url', {
|
|
36
|
-
describe: 'Codefresh url, by default https://g.codefresh.io',
|
|
37
|
-
})
|
|
38
|
-
.option('kube-namespace', {
|
|
39
|
-
describe: 'Name of the namespace on which monitor should be installed [$CF_ARG_KUBE_NAMESPACE]',
|
|
40
|
-
})
|
|
41
|
-
.option('docker-registry', {
|
|
42
|
-
describe: 'The prefix for the container registry that will be used for pulling the required components images. Example: --docker-registry="docker.io"',
|
|
43
|
-
type: 'string',
|
|
44
|
-
})
|
|
45
|
-
.option('values', {
|
|
46
|
-
describe: 'specify values in a YAML file',
|
|
47
|
-
})
|
|
48
|
-
.option('verbose', {
|
|
49
|
-
describe: 'Print logs',
|
|
50
|
-
})
|
|
51
|
-
.option('dry-run', {
|
|
52
|
-
describe: 'dry run',
|
|
53
|
-
default: false,
|
|
54
|
-
type: 'boolean',
|
|
55
|
-
})
|
|
56
|
-
.option('bypass-download', {
|
|
57
|
-
describe: 'If the flag is set, then the first attempt (to get the required component) would be by searching for it locally. If the search fails, there will be a download attempt',
|
|
58
|
-
default: false,
|
|
59
|
-
type: 'boolean',
|
|
60
|
-
}),
|
|
61
|
-
handler: async (argv) => {
|
|
62
|
-
const {
|
|
63
|
-
url,
|
|
64
|
-
// 'kube-config-path': kubeConfigPath,
|
|
65
|
-
'cluster-id': clusterId,
|
|
66
|
-
token,
|
|
67
|
-
'kube-config-path': kubeConfigPath,
|
|
68
|
-
'kube-context-name': kubeContextName,
|
|
69
|
-
'kube-namespace': kubeNamespace,
|
|
70
|
-
'docker-registry': dockerRegistry,
|
|
71
|
-
verbose,
|
|
72
|
-
values: valuesFile,
|
|
73
|
-
'env-vars': envVars,
|
|
74
|
-
'set-value': setValue,
|
|
75
|
-
'set-file': setFile,
|
|
76
|
-
'dry-run': dryRun,
|
|
77
|
-
'bypass-download': bypassDownload,
|
|
78
|
-
// noExit,
|
|
79
|
-
} = argv;
|
|
80
|
-
const binLocation = await downloadVeonona(undefined, bypassDownload);
|
|
81
|
-
const componentRunner = new Runner(binLocation);
|
|
82
|
-
|
|
83
|
-
const commands = [
|
|
84
|
-
'install',
|
|
85
|
-
'monitor',
|
|
86
|
-
];
|
|
87
|
-
|
|
88
|
-
if (clusterId) {
|
|
89
|
-
commands.push('--clusterId');
|
|
90
|
-
commands.push(clusterId);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
commands.push('--codefreshToken');
|
|
94
|
-
if (token) {
|
|
95
|
-
commands.push(token);
|
|
96
|
-
} else {
|
|
97
|
-
commands.push(_.get(sdk, 'config.context.token'));
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (kubeConfigPath) {
|
|
101
|
-
commands.push('--kube-config-path');
|
|
102
|
-
commands.push(kubeConfigPath);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (kubeContextName) {
|
|
106
|
-
commands.push('--kube-context-name');
|
|
107
|
-
commands.push(kubeContextName);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// if (helm3) {
|
|
111
|
-
// commands.push('--helm3');
|
|
112
|
-
// }
|
|
113
|
-
|
|
114
|
-
if (kubeNamespace) {
|
|
115
|
-
commands.push('--kube-namespace');
|
|
116
|
-
commands.push(kubeNamespace);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (url) {
|
|
120
|
-
commands.push('--codefreshHost');
|
|
121
|
-
commands.push(url);
|
|
122
|
-
}
|
|
123
|
-
if (verbose) {
|
|
124
|
-
commands.push('--verbose');
|
|
125
|
-
}
|
|
126
|
-
if (DefaultLogFormatter) {
|
|
127
|
-
commands.push(`--log-formtter=${DefaultLogFormatter}`);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
if (dockerRegistry) {
|
|
131
|
-
commands.push(`--docker-registry=${dockerRegistry}`);
|
|
132
|
-
}
|
|
133
|
-
if (valuesFile) {
|
|
134
|
-
commands.push(`--values=${valuesFile}`);
|
|
135
|
-
}
|
|
136
|
-
if (setFile) {
|
|
137
|
-
commands.push(`--set-file=${setFile}`);
|
|
138
|
-
}
|
|
139
|
-
if (setValue) {
|
|
140
|
-
if (_.isArray(setValue)) {
|
|
141
|
-
setValue.forEach(sv => commands.push(`--set-value=${sv}`));
|
|
142
|
-
} else {
|
|
143
|
-
commands.push(`--set-value=${setValue}`);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
if (envVars) {
|
|
147
|
-
envVars.forEach((item) => {
|
|
148
|
-
const parts = item.split('=');
|
|
149
|
-
commands.push(`--set-value=EnvVars.${parts[0]}=${parts[1].replace(/,/g, '\\,')}`);
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
if (dryRun) {
|
|
153
|
-
commands.push('--dry-run');
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
await componentRunner.run(components.venona, commands);
|
|
157
|
-
},
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
module.exports = installMonitorCmd;
|