codefresh 1.2.10 → 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.
Files changed (40) hide show
  1. package/lib/binary/components.js +0 -38
  2. package/lib/interface/cli/commands/components/download.cmd.js +1 -1
  3. package/lib/interface/cli/commands/hybrid/helper.js +1 -877
  4. package/lib/interface/cli/completion/tree.json +1 -1
  5. package/package.json +2 -11
  6. package/lib/interface/cli/commands/agent/helper.js +0 -28
  7. package/lib/interface/cli/commands/agent/install.cmd.js +0 -283
  8. package/lib/interface/cli/commands/agent/uninstall.cmd.js +0 -92
  9. package/lib/interface/cli/commands/app-proxy/helper.js +0 -63
  10. package/lib/interface/cli/commands/app-proxy/install.cmd.js +0 -204
  11. package/lib/interface/cli/commands/app-proxy/uninstall.cmd.js +0 -175
  12. package/lib/interface/cli/commands/app-proxy/upgrade.cmd.js +0 -110
  13. package/lib/interface/cli/commands/gitops/argocd/install.js +0 -9
  14. package/lib/interface/cli/commands/gitops/argocd/uninstall.js +0 -11
  15. package/lib/interface/cli/commands/gitops/argocd/upgrade.js +0 -9
  16. package/lib/interface/cli/commands/gitops/codefresh/install.js +0 -50
  17. package/lib/interface/cli/commands/gitops/codefresh/uninstall.js +0 -14
  18. package/lib/interface/cli/commands/gitops/codefresh/upgrade.js +0 -9
  19. package/lib/interface/cli/commands/gitops/common/install.js +0 -62
  20. package/lib/interface/cli/commands/gitops/common/uninstall.js +0 -39
  21. package/lib/interface/cli/commands/gitops/common/upgrade.js +0 -45
  22. package/lib/interface/cli/commands/gitops/install.cmd.js +0 -116
  23. package/lib/interface/cli/commands/gitops/install.spec.js +0 -77
  24. package/lib/interface/cli/commands/gitops/uninstall.cmd.js +0 -56
  25. package/lib/interface/cli/commands/gitops/upgrade.cmd.js +0 -56
  26. package/lib/interface/cli/commands/hybrid/delete.cmd.js +0 -341
  27. package/lib/interface/cli/commands/hybrid/init.cmd.js +0 -957
  28. package/lib/interface/cli/commands/hybrid/key-helper.js +0 -82
  29. package/lib/interface/cli/commands/hybrid/migration.js +0 -192
  30. package/lib/interface/cli/commands/hybrid/upgrade.cmd.js +0 -195
  31. package/lib/interface/cli/commands/monitor/install.cmd.js +0 -160
  32. package/lib/interface/cli/commands/monitor/uninstall.cmd.js +0 -78
  33. package/lib/interface/cli/commands/root/install.cmd.js +0 -17
  34. package/lib/interface/cli/commands/root/uninstall.cmd.js +0 -17
  35. package/lib/interface/cli/commands/runtimeEnvironments/attach.cmd.js +0 -180
  36. package/lib/interface/cli/commands/runtimeEnvironments/create.cmd.js +0 -23
  37. package/lib/interface/cli/commands/runtimeEnvironments/install.cmd.js +0 -340
  38. package/lib/interface/cli/commands/runtimeEnvironments/uninstall.cmd.js +0 -149
  39. package/lib/interface/cli/helpers/kubernetes.js +0 -61
  40. package/lib/interface/cli/helpers/progressEvents.js +0 -25
@@ -1,341 +0,0 @@
1
- /* eslint-disable max-len */
2
- const Command = require('../../Command');
3
- const runnerRoot = require('../root/runner.cmd');
4
- const inquirer = require('inquirer').default;
5
- const { getAllKubeContexts, getKubeContext } = require('../../helpers/kubernetes');
6
- const unInstallRuntime = require('../runtimeEnvironments/uninstall.cmd');
7
- const unInstallAgent = require('../agent/uninstall.cmd');
8
- const unInstallMonitor = require('../monitor/uninstall.cmd');
9
- const colors = require('colors');
10
- const DEFAULTS = require('../../defaults');
11
- const sdk = require('../../../../logic/sdk');
12
- const _ = require('lodash');
13
- const { to } = require('./../../../../logic/cli-config/errors/awaitTo');
14
- const {
15
- createErrorHandler,
16
- getRelatedAgents,
17
- getRelatedNamespaces,
18
- drawCodefreshFiglet,
19
- unInstallAppProxy,
20
- mergeValuesFromValuesFile,
21
- INSTALLATION_DEFAULTS,
22
- } = require('./helper');
23
-
24
- const defaultNamespace = 'codefresh';
25
- const openIssueMessage = `If you had any issues with the uninstallation process please report them at: ${colors.blue('https://github.com/codefresh-io/cli/issues/new')}`;
26
- const handleError = createErrorHandler(openIssueMessage);
27
-
28
- async function promptConfirmationMessage({
29
- agentName,
30
- kubeNamespace,
31
- attachedRuntimes,
32
- defaultRuntime,
33
- clustersToDelete,
34
- appProxyToDelete,
35
- }) {
36
- const note = colors.underline(colors.yellow('Note'));
37
- let newDefaultRuntime = defaultRuntime;
38
-
39
- // prompt confirmation message
40
- console.log(`${colors.red('This process will attempt to delete the following:')}`);
41
- console.log(`\u2022 Codefresh runner with the name "${colors.cyan(agentName)}"`);
42
- attachedRuntimes.forEach((reName) => { console.log(`\u2022 Codefresh runtime with the name "${colors.cyan(reName)}"${defaultRuntime === reName ? ' [default runtime]' : ''}`); });
43
- console.log('\u2022 Codefresh runner monitor component');
44
- clustersToDelete.forEach((cluster) => { console.log(`\u2022 Codefresh cluster integration: "${colors.cyan(cluster.selector)}"`); });
45
- appProxyToDelete.forEach((appProxy) => { console.log(`\u2022 App-Proxy component: "${colors.cyan(appProxy)}"`); });
46
-
47
- // if this includes your default runtime
48
- if (attachedRuntimes.length > 0) {
49
- if (defaultRuntime && attachedRuntimes.includes(defaultRuntime)) {
50
- newDefaultRuntime = INSTALLATION_DEFAULTS.SAAS_RUNTIME;
51
- console.log(`* ${note}: "${colors.cyan(defaultRuntime)}" is set as your default runtime-environment,`
52
- + ` if you delete this runtime your new default runtime will be: "${colors.cyan(newDefaultRuntime)}"`);
53
- }
54
-
55
- console.log(`* ${note}: any pipeline set to run on one of the above runtime environments will be moved to`
56
- + ` run on your ${newDefaultRuntime !== defaultRuntime ? 'new ' : ''}default runtime environment: "${colors.cyan(newDefaultRuntime)}"`);
57
- }
58
-
59
- console.log(`* ${note}: The kubernetes namespace "${colors.cyan(kubeNamespace)}" will ${colors.underline('not')} be deleted\n`);
60
-
61
- const answer = await inquirer.prompt({
62
- type: 'confirm',
63
- name: 'deletionConfirmed',
64
- default: false,
65
- message: 'Are you sure you want to delete all of the above? (default is NO)',
66
- });
67
- if (!answer.deletionConfirmed) {
68
- console.log('Deletion process aborted, exiting...');
69
- process.exit(1);
70
- }
71
- }
72
-
73
- // returns the clusters that are referenced by the runtimesToDelete and not referenced by runtimesToKeep
74
- function getClustersToDelete(clusters, runtimes, runtimesToDelete) {
75
- const potentialClustersNames = _(runtimesToDelete).map(re => _.get(re, 'runtimeScheduler.cluster.clusterProvider.selector')).compact().value();
76
- const runtimesToDeleteNames = _(runtimesToDelete).map(re => _.get(re, 'metadata.name')).compact().value();
77
-
78
- const potentialClustersToDelete = _.filter(clusters, c => potentialClustersNames.includes(c.selector));
79
- const runtimesToKeep = _.filter(runtimes, re => !runtimesToDeleteNames.includes(_.get(re, 'metadata.name')));
80
-
81
- return _.filter(potentialClustersToDelete, c => !_.find(runtimesToKeep, re => _.get(re, 'runtimeScheduler.cluster.clusterProvider.selector') === c.selector));
82
- }
83
-
84
- function getAppProxyToDelete(runtimesToDelete) {
85
- return _.reduce(runtimesToDelete, (acc, re) => {
86
- const appProxy = _.get(re, 'appProxy.externalIP');
87
- if (appProxy) {
88
- acc.push(appProxy);
89
- }
90
- return acc;
91
- }, []);
92
- }
93
-
94
- const deleteCmd = new Command({
95
- root: false,
96
- parent: runnerRoot,
97
- command: 'delete',
98
- description: 'Deletes codefresh runner solution\'s components on kubernetes cluster',
99
- webDocs: {
100
- category: 'Runner',
101
- title: 'Delete',
102
- weight: 100,
103
- },
104
- // requiresAuthentication: argv => argv && !argv.token,
105
- builder: yargs => yargs
106
- .env('CF_ARG_') // this means that every process.env.CF_ARG_* will be passed to argv
107
- .option('name', {
108
- describe: 'Agent\'s name to be deleted',
109
- })
110
- .option('url', {
111
- describe: 'Codefresh system custom url',
112
- })
113
- .option('force', {
114
- describe: 'Run the delete operation without asking to confirm (use with caution!)',
115
- alias: 'f',
116
- type: Boolean,
117
- })
118
- .option('kube-context-name', {
119
- describe: 'Name of the kubernetes context from which the Codefresh Agent and Runtime should be removed',
120
- })
121
- .option('kube-namespace', {
122
- describe: 'Name of the kubernetes namespace from which the Codefresh Agent and Runtime should be removed',
123
- })
124
- .option('kube-config-path', {
125
- describe: 'Path to kubeconfig file (default is $HOME/.kube/config)',
126
- })
127
- .option('keep-cluster-integration', {
128
- describe: 'If true, will not delete dangling cluster integrations from Codefresh',
129
- type: Boolean,
130
- })
131
- .option('values', {
132
- describe: 'specify values in a YAML file',
133
- })
134
- .option('verbose', {
135
- describe: 'Print logs',
136
- }),
137
- handler: async (argv) => {
138
- let _argv = argv;
139
-
140
- // read values from values file
141
- if (argv.values) {
142
- _argv = mergeValuesFromValuesFile(_argv, _argv.values, handleError);
143
- }
144
-
145
- const {
146
- verbose,
147
- force,
148
- 'kube-config-path': kubeConfigPath,
149
- 'keep-cluster-integration': keepClusterIntegration,
150
- } = _argv;
151
- let {
152
- url,
153
- 'kube-context-name': kubeContextName,
154
- 'kube-namespace': kubeNamespace,
155
- name: agentName,
156
- } = _argv;
157
-
158
- const [listReErr, runtimes] = await to(sdk.runtimeEnvs.list({ }));
159
- await handleError(listReErr, 'Failed to get runtime environments');
160
- const [listAgentsErr, agents] = await to(sdk.agents.list({ }));
161
- await handleError(listAgentsErr, 'Failed to get agents');
162
- const [listClustersErr, clusters] = await to(sdk.clusters.list());
163
- await handleError(listClustersErr, 'Failed to get cluster integrations');
164
-
165
- if (!agents || !agents.length) {
166
- console.log('No runners found on your codefresh account');
167
- process.exit(0);
168
- }
169
-
170
- console.log(colors.green('This uninstaller will guide you through the runner uninstallation process'));
171
-
172
- if (!url) {
173
- url = DEFAULTS.URL;
174
- }
175
-
176
- if (!kubeContextName) {
177
- const contexts = getAllKubeContexts(kubeConfigPath);
178
- const currentKubeContext = getKubeContext(kubeConfigPath);
179
-
180
- const answer = await inquirer.prompt({
181
- type: 'list',
182
- name: 'context',
183
- message: 'Name of Kubernetes context to use',
184
- default: currentKubeContext,
185
- choices: contexts,
186
- });
187
-
188
- kubeContextName = answer.context;
189
- }
190
-
191
- if (!kubeNamespace) {
192
- const [getNamespacesErr, relatedNamespaces] = await to(getRelatedNamespaces(kubeConfigPath, kubeContextName, runtimes));
193
- handleError(getNamespacesErr, 'Could not get namespaces in the selected kubernetes cluster');
194
- let answer;
195
- if (!relatedNamespaces.length) {
196
- answer = await inquirer.prompt({
197
- type: 'input',
198
- name: 'namespace',
199
- default: defaultNamespace,
200
- message: 'Kubernetes namespace to remove Codefresh Runner components from',
201
- validate: value => (value !== undefined && value !== '') || 'Please enter namespace\'s name',
202
- });
203
- } else {
204
- answer = await inquirer.prompt({
205
- type: 'list',
206
- name: 'namespace',
207
- default: defaultNamespace,
208
- message: 'Kubernetes namespace to remove Codefresh Runner components from ',
209
- choices: relatedNamespaces,
210
- });
211
- }
212
-
213
- kubeNamespace = answer.namespace;
214
- }
215
-
216
- if (!agentName) {
217
- const relatedAgents = await getRelatedAgents(kubeNamespace, runtimes, agents, handleError);
218
- let agentsChoices = relatedAgents;
219
- if (!relatedAgents.length) {
220
- console.log(colors.yellow('No agents related to the specified kubernetes cluster and namespace were found, displaying all agents'));
221
- agentsChoices = agents;
222
- }
223
- const choicesToAgentNames = agentsChoices.reduce((acc, a) => {
224
- acc[`${a.name}\t${a.runtimes.length ? `(attached runtimes: ${a.runtimes.join(', ')})` : ''}`] = a.name;
225
- return acc;
226
- }, {});
227
- const answer = await inquirer.prompt({
228
- type: 'list',
229
- name: 'name',
230
- message: 'Agent name to uninstall',
231
- choices: Object.keys(choicesToAgentNames),
232
- });
233
- agentName = choicesToAgentNames[answer.name];
234
- }
235
-
236
- // check that agent exists
237
- const agent = _.find(agents, curr => curr.name === agentName);
238
- if (!agent) {
239
- console.log(colors.red(`Agent with name "${agentName}" doesn't exists`));
240
- return;
241
- }
242
- if (agent.runtimes && agent.runtimes.length > 1) {
243
- console.log('Can\'t delete runner with more than one runtime, use runtime delete command');
244
- return;
245
- }
246
-
247
- console.log(`\n${colors.green('Uninstallation options summary:')}
248
- 1. Kubernetes Context: ${colors.cyan(kubeContextName)}
249
- 2. Kubernetes Namespace: ${colors.cyan(kubeNamespace)}
250
- 3. Agent name: ${colors.cyan(agentName)}
251
- `);
252
-
253
- const attachedRuntimes = agent.runtimes || [];
254
- const runtimesToDelete = _.filter(runtimes, re => attachedRuntimes.includes(_.get(re, 'metadata.name')));
255
- const defaultRuntime = _.get(_.find(runtimes, re => re.default), 'metadata.name');
256
-
257
- const clustersToDelete = keepClusterIntegration ? [] : getClustersToDelete(clusters, runtimes, runtimesToDelete);
258
- const appProxyToDelete = getAppProxyToDelete(runtimesToDelete);
259
-
260
- if (!force) {
261
- await promptConfirmationMessage({
262
- agentName,
263
- kubeNamespace,
264
- attachedRuntimes,
265
- defaultRuntime,
266
- clustersToDelete,
267
- appProxyToDelete,
268
- });
269
- }
270
-
271
- await Promise.all(attachedRuntimes.map(async (reName) => {
272
- const uninstallRuntimeOptions = {
273
- 'agent-name': agentName,
274
- 'runtime-kube-namespace': kubeNamespace,
275
- 'runtime-kube-context-name': kubeContextName,
276
- 'agent-kube-context-name': kubeContextName,
277
- 'agent-kube-namespace': kubeNamespace,
278
- name: reName,
279
- terminateProcess: false,
280
- verbose,
281
- };
282
- const re = runtimes.find(runtime => runtime.metadata.name === reName);
283
- if (!re) {
284
- // re already deleted
285
- return;
286
- }
287
-
288
- // remove runtime cluster components
289
- console.log(`Deleting runtime-environment: ${colors.cyan(reName)} from cluster`);
290
- const [uninstallReErr] = await to(unInstallRuntime.handler(uninstallRuntimeOptions));
291
- handleError(uninstallReErr, `Failed to uninstall runtime-environment "${colors.cyan(reName)}"`);
292
-
293
- // delete codefresh entity
294
- console.log(`Deleting runtime-environment: "${colors.cyan(reName)}" from codefresh`);
295
- await to(sdk.runtimeEnvs.delete({ name: reName, force: true })); // also delete default runtime
296
-
297
- if (re.appProxy) {
298
- const [uninstallAppProxyErr] = await to(unInstallAppProxy({
299
- kubeConfigPath,
300
- kubeContextName,
301
- kubeNamespace,
302
- verbose,
303
- }));
304
- handleError(uninstallAppProxyErr, 'Failed to uninstall app-proxy');
305
- console.log('App-Proxy uninstalled successfully');
306
- }
307
- }));
308
-
309
- await Promise.all(clustersToDelete.map(async (cluster) => {
310
- console.log(`Deleting cluster integration: "${colors.cyan(cluster.selector)}"`);
311
- const [clusterDeleteErr] = await to(sdk.clusters.delete({ id: cluster._id, provider: cluster.provider }));
312
- handleError(clusterDeleteErr, 'Failed to delete cluster integration');
313
- }));
314
-
315
- const uninstallAgentOptions = {
316
- 'kube-namespace': kubeNamespace,
317
- 'kube-context-name': kubeContextName,
318
- name: agentName,
319
- terminateProcess: false,
320
- verbose,
321
- };
322
- const [uninstallAgentErr] = await to(unInstallAgent.handler(uninstallAgentOptions));
323
- handleError(uninstallAgentErr, 'Failed to uninstall agent');
324
-
325
- const uninstallMonitorOptions = {
326
- 'kube-namespace': kubeNamespace,
327
- 'kube-context-name': kubeContextName,
328
- verbose,
329
- noExit: true, // to prevent if from calling: process.exit()
330
- };
331
- const [uninstallMonitorErr] = await to(unInstallMonitor.handler(uninstallMonitorOptions));
332
- handleError(uninstallMonitorErr, 'Failed to uninstall monitor');
333
-
334
- console.log('Successfully uninstalled Codefresh Runner');
335
- console.log(`\nIf you had any issues with the uninstallation process please report them at: ${colors.blue('https://github.com/codefresh-io/cli/issues/new')}`);
336
- await drawCodefreshFiglet();
337
- process.exit(); // TODO : This is not needed - needed to be fixed
338
- },
339
- });
340
-
341
- module.exports = deleteCmd;