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,56 +1,24 @@
1
1
  const _ = require('lodash');
2
2
  const colors = require('colors');
3
3
  const cliProgress = require('cli-progress');
4
- const figlet = require('figlet');
5
4
  const path = require('path');
6
- const { homedir } = require('os');
7
- const Promise = require('bluebird');
8
- const YAML = require('yaml');
9
- const fs = require('fs');
10
5
 
11
6
  const { prettyError } = require('../../../../logic/cli-config/errors/helpers');
12
7
  const { to } = require('../../../../logic/cli-config/errors/awaitTo');
13
8
  const sdk = require('../../../../logic/sdk');
14
9
  const { status: STATUSES } = require('./installation-process');
15
10
  const pipelinesRunCmd = require('../pipeline/run.cmd');
16
- const { getAllNamespaces } = require('../../helpers/kubernetes');
17
11
  const { followLogs } = require('../../helpers/logs');
18
- const ProgressEvents = require('../../helpers/progressEvents');
19
12
  const {
20
- components, Runner, Downloader, CommonProgressFormat,
13
+ components, Downloader, CommonProgressFormat,
21
14
  CODEFRESH_PATH,
22
15
  } = require('../../../../binary');
23
16
  const { pathExists } = require('../../helpers/general');
24
17
 
25
18
  const INSTALLATION_DEFAULTS = {
26
- NAMESPACE: 'codefresh',
27
- MAKE_DEFAULT_RE: false,
28
- RUN_DEMO_PIPELINE: true,
29
19
  DEMO_PIPELINE_NAME: 'CF_Runner_Demo',
30
20
  PROJECT_NAME: 'Runner',
31
- CF_CONTEXT_NAME: 'cf-runner',
32
- STORAGE_CLASS_PREFIX: 'dind-local-volumes-runner',
33
- RUNTIME_SERVICE_ACCOUNT: 'codefresh-engine',
34
- RESUME_OLD_INSTALLATION: true,
35
21
  COMPONENTS_FOLDER: 'components',
36
- KUBECONFIG_PATH: path.join(homedir(), '.kube', 'config'),
37
- SAAS_RUNTIME: 'SAAS runtime',
38
- HELM_FILE_PATH: path.join(process.cwd(), 'generated_values.yaml'),
39
- };
40
-
41
- const RUNTIME_IMAGES = {
42
- DOCKER_PUSHER_IMAGE: 'codefresh/cf-docker-pusher:6.0.3',
43
- DOCKER_PULLER_IMAGE: 'codefresh/cf-docker-puller:8.0.2',
44
- DOCKER_TAG_PUSHER_IMAGE: 'codefresh/cf-docker-tag-pusher:1.3.0',
45
- DOCKER_BUILDER_IMAGE: 'codefresh/cf-docker-builder:1.1.12',
46
- GC_BUILDER_IMAGE: 'codefresh/cf-gc-builder:0.4.4',
47
- CONTAINER_LOGGER_IMAGE: 'codefresh/cf-container-logger:1.6.1',
48
- GIT_CLONE_IMAGE: 'codefresh/cf-git-cloner:10.0.3',
49
- COMPOSE_IMAGE: 'docker/compose:1.11.2',
50
- KUBE_DEPLOY: 'codefresh/cf-deploy-kubernetes:latest',
51
- FS_OPS_IMAGE: 'codefresh/fs-ops:latest',
52
- TEMPLATE_ENGINE: 'codefresh/pikolo:latest',
53
- PIPELINE_DEBUGGER_IMAGE: 'codefresh/cf-debugger:1.1.2',
54
22
  };
55
23
 
56
24
  const DEMO_STEP_IMAGE = {
@@ -60,9 +28,6 @@ const DEMO_STEP_IMAGE = {
60
28
  default: 'quay.io/codefresh/alpine:3.11',
61
29
  };
62
30
 
63
- const maxRuntimeNameLength = 63;
64
- const DefaultLogFormatter = 'plain';
65
-
66
31
  const defaultOpenIssueMessage = 'If you had any issues with this process please report them at: ' +
67
32
  `${colors.blue('https://github.com/codefresh-io/cli/issues/new')}`;
68
33
 
@@ -211,146 +176,6 @@ function createErrorHandler(openIssueMessage = defaultOpenIssueMessage) {
211
176
  };
212
177
  }
213
178
 
214
- async function getRelatedAgents(kubeNamespace, runtimes, agents, errHandler) {
215
- let allAgents = agents;
216
- if (!agents) {
217
- const [listAgentsErr, _agents] = await to(sdk.agents.list({}));
218
- await errHandler(listAgentsErr, 'Failed to get agents');
219
- allAgents = _agents;
220
- }
221
-
222
- const relatedREs = new Set();
223
- _.forEach(runtimes, (r) => {
224
- if (_.get(r, 'runtimeScheduler.cluster.namespace') === kubeNamespace) {
225
- relatedREs.add(r.metadata.name);
226
- }
227
- });
228
-
229
- const relatedAgents = [];
230
- _.forEach(allAgents, (a) => {
231
- _.forEach(_.get(a, 'runtimes', []), (r) => {
232
- if (relatedREs.has(r)) {
233
- relatedAgents.push(a);
234
- }
235
- });
236
- });
237
-
238
- return relatedAgents;
239
- }
240
-
241
- // Try to get the most relevant namespaces
242
- async function getRelatedNamespaces(kubeConfigPath, kubeContextName, runtimes) {
243
- const [err, namespacesOnCluster] = await to(getAllNamespaces(kubeConfigPath, kubeContextName));
244
- if (err) {
245
- throw err;
246
- }
247
-
248
- const nsOnCluster = new Set(namespacesOnCluster || []);
249
- return _(runtimes)
250
- .filter(re => nsOnCluster.has(_.get(re, 'runtimeScheduler.cluster.namespace')))
251
- .map(re => _.get(re, 'runtimeScheduler.cluster.namespace'))
252
- .uniq()
253
- .value();
254
- }
255
-
256
- function getRuntimesWithVersions(runtimes, agents) {
257
- const hybridRuntimes = runtimes.filter(re => _.get(re, 'metadata.agent'));
258
- const runtimesWithOldVersion = new Set(_.map(hybridRuntimes, re => re.metadata.name));
259
- const runtimesWithNewVersion = new Set();
260
- _.forEach(agents, (a) => {
261
- _.forEach(a.runtimes, (re) => {
262
- runtimesWithOldVersion.delete(re);
263
- runtimesWithNewVersion.add(re);
264
- });
265
- });
266
-
267
- const runtimesWithVersions = [...runtimesWithOldVersion, ...runtimesWithNewVersion].reduce((acc, cur, i) => {
268
- acc[cur] = i < runtimesWithOldVersion.size ? '0.x.x' : '1.x.x';
269
- return acc;
270
- }, {});
271
-
272
- return runtimesWithVersions;
273
- }
274
-
275
- function getRuntimeVersion(runtimeName, agents) {
276
- let hasAgentsAttached = false;
277
- _.forEach(agents, (a) => {
278
- _.forEach(a.runtimes, (re) => {
279
- if (re === runtimeName) {
280
- hasAgentsAttached = true;
281
- }
282
- });
283
- });
284
-
285
- return hasAgentsAttached ? '1.0.0' : '0.0.1';
286
- }
287
-
288
- function createProgressBar() {
289
- const runtimeEvents = new ProgressEvents();
290
- const runtimeFormat = 'downloading runtime installer [{bar}] {percentage}% | {value}/{total}';
291
- const runtimmrProgressBar = new cliProgress.SingleBar(
292
- { stopOnComplete: true, format: runtimeFormat },
293
- cliProgress.Presets.shades_classic,
294
- );
295
- let runtimeTotalSize;
296
- runtimeEvents.onStart((size) => {
297
- console.log('Downloading runtime installer:\n');
298
- runtimmrProgressBar.start(size, 0);
299
- runtimeTotalSize = size;
300
- });
301
- runtimeEvents.onProgress((progress) => {
302
- runtimmrProgressBar.update(progress);
303
- if (progress >= runtimeTotalSize) {
304
- console.log('\n');
305
- }
306
- });
307
-
308
- return runtimeEvents;
309
- }
310
-
311
- function drawCodefreshFiglet() {
312
- return Promise.race([new Promise((resolve) => {
313
- figlet('CODEFRESH', (err, data) => {
314
- if (err) {
315
- resolve();
316
- }
317
- if (data) {
318
- console.log(data);
319
- }
320
- resolve();
321
- });
322
- }), Promise.delay(5000)]);
323
- }
324
-
325
- async function getDefaultRuntime(runtimes) {
326
- let _runtimes = runtimes;
327
- if (!_runtimes) {
328
- _runtimes = await sdk.runtimeEnvs.list({ });
329
- }
330
- const defaultRe = _.find(_runtimes, re => re.default);
331
-
332
- return defaultRe;
333
- }
334
-
335
- async function getRecommendedKubeNamespace(kubeconfigPath, kubeContextName) {
336
- const defaultName = INSTALLATION_DEFAULTS.NAMESPACE;
337
- const [err, namespaces] = await to(getAllNamespaces(kubeconfigPath, kubeContextName));
338
- let name;
339
-
340
- if (err || !_.isArray(namespaces) || !_.find(namespaces, ns => ns === defaultName)) {
341
- name = defaultName; // use the default name if there are no collisions
342
- } else {
343
- const namespacesSet = new Set(namespaces); // for fast lookup
344
- let i = 1;
345
- while (namespacesSet.has(`${defaultName}-${i}`)) {
346
- i += 1;
347
- }
348
- name = `${defaultName}-${i}`;
349
- }
350
-
351
- return name;
352
- }
353
-
354
179
  async function getComponent(location = CODEFRESH_PATH, component, bypassDownload) {
355
180
  const componentName = component.name || 'component';
356
181
  const localBinLocation = path.join(
@@ -406,10 +231,6 @@ async function downloadVeonona(location, bypassDownload = false) {
406
231
  return await getComponent(location, components.venona, bypassDownload);
407
232
  }
408
233
 
409
- async function downloadProvider({ provider, location }, bypassDownload = false) {
410
- return await await getComponent(location, components.gitops[provider], bypassDownload);
411
- }
412
-
413
234
  async function downloadSteveDore(location, bypassDownload = false) {
414
235
  return await getComponent(location, components.stevedore, bypassDownload);
415
236
  }
@@ -434,14 +255,6 @@ async function downloadComponents(location = CODEFRESH_PATH, componentsArg = [])
434
255
  await downloadVeonona(location);
435
256
  console.log(colors.green(`Kubernetes components installer downloaded successfully to ${location}`));
436
257
  break;
437
- case 'argocd-agent':
438
- await downloadProvider({ provider: 'argocd-agent', location });
439
- console.log(colors.green(`Argocd-agent downloaded successfully to ${location}`));
440
- break;
441
- case 'codefresh':
442
- await downloadProvider({ provider: 'codefresh', location });
443
- console.log(colors.green(`Codefresh gitops provider downloaded successfully to ${location}`));
444
- break;
445
258
  default:
446
259
  console.log(colors.yellow(`Skip unknown component ${component}`));
447
260
  }
@@ -449,703 +262,14 @@ async function downloadComponents(location = CODEFRESH_PATH, componentsArg = [])
449
262
  }
450
263
  /* eslint-enable no-restricted-syntax, no-await-in-loop */
451
264
 
452
- async function runClusterAcceptanceTests({
453
- apiHost,
454
- kubeNamespace,
455
- kubeConfigPath,
456
- kubeContextName,
457
- dockerRegistry,
458
- envVars,
459
- verbose,
460
- valuesFile, // --values
461
- setValue, // --set-value
462
- setFile, // --set-file
463
- bypassDownload, // --bypass-download
464
- }) {
465
- const binLocation = await downloadVeonona(undefined, bypassDownload);
466
- const componentRunner = new Runner(binLocation);
467
- const cmd = ['test', '--log-formtter', DefaultLogFormatter];
468
- if (apiHost) {
469
- cmd.push(`--api-host=${apiHost}`);
470
- }
471
- if (kubeNamespace) {
472
- cmd.push('--kube-namespace');
473
- cmd.push(kubeNamespace);
474
- }
475
- if (kubeContextName) {
476
- cmd.push('--kube-context-name');
477
- cmd.push(kubeContextName);
478
- }
479
- if (kubeConfigPath) {
480
- cmd.push('--kube-config-path');
481
- cmd.push(kubeConfigPath);
482
- }
483
- if (process.env.NODE_TLS_REJECT_UNAUTHORIZED === '0') {
484
- cmd.push('--insecure');
485
- }
486
- if (dockerRegistry) {
487
- cmd.push(`--set-value=DockerRegistry=${dockerRegistry}`);
488
- }
489
- if (verbose) {
490
- cmd.push(`--verbose=${verbose}`);
491
- }
492
- if (envVars) {
493
- envVars.forEach((item) => {
494
- const parts = item.split('=');
495
- cmd.push(`--set-value=EnvVars.${parts[0]}=${parts[1].replace(/,/g, '\\,')}`);
496
- });
497
- }
498
- if (valuesFile) {
499
- cmd.push(`--values=${valuesFile}`);
500
- }
501
- if (setValue) {
502
- cmd.push(`--set-value=${setValue}`);
503
- }
504
- if (setFile) {
505
- cmd.push(`--set-file=${setFile}`);
506
- }
507
- await componentRunner.run(components.venona, cmd);
508
- }
509
-
510
- async function runUpgrade({ kubeNamespace, kubeContextName, bypassDownload }) {
511
- const binLocation = await downloadVeonona(undefined, bypassDownload);
512
- const componentRunner = new Runner(binLocation);
513
- const cmd = ['upgrade', '--log-formtter', DefaultLogFormatter];
514
- if (kubeNamespace) {
515
- cmd.push('--kube-namespace');
516
- cmd.push(kubeNamespace);
517
- }
518
- if (kubeContextName) {
519
- cmd.push('--kube-context-name');
520
- cmd.push(kubeContextName);
521
- }
522
- await componentRunner.run(components.venona, cmd);
523
- }
524
-
525
- async function installAgent({
526
- apiHost, // --api-host
527
- agentId, // --agnetId
528
- kubeContextName, // kube-context-name
529
- kubeNamespace, // --kube-namespace
530
- dockerRegistry, // --docker-registry
531
- token, // --agentToken
532
- kubeNodeSelector, // --kube-node-selector
533
- dryRun, // --dryRun
534
- bypassDownload, // --bypass-download
535
- inCluster, // -inCluster
536
- tolerations, // --tolerations
537
- venonaVersion, // --venona-version
538
- kubeConfigPath, // --kube-config-path
539
- skipVersionCheck, // --skip-version-check
540
- verbose, // --verbose
541
- logFormatting = DefaultLogFormatter, // --log-formtter
542
- envVars,
543
- valuesFile, // --values
544
- setValue, // --set-value
545
- setFile, // --set-file
546
- }) {
547
- const binLocation = await downloadVeonona(undefined, bypassDownload);
548
- const componentRunner = new Runner(binLocation);
549
- const cmd = [
550
- 'install',
551
- 'agent',
552
- '--agentId',
553
- agentId,
554
- '--api-host',
555
- apiHost,
556
- '--kube-context-name',
557
- kubeContextName,
558
- '--kube-namespace',
559
- kubeNamespace,
560
- '--log-formtter',
561
- logFormatting,
562
- ];
563
- if (kubeNodeSelector) {
564
- cmd.push('--kube-node-selector');
565
- cmd.push(kubeNodeSelector);
566
- }
567
-
568
- if (dockerRegistry) {
569
- cmd.push(`--docker-registry=${dockerRegistry}`);
570
- }
571
-
572
- if (token) {
573
- cmd.push(`--agentToken=${token}`);
574
- }
575
- if (dryRun) {
576
- cmd.push('--dry-run');
577
- }
578
-
579
- if (bypassDownload) {
580
- cmd.push(`--bypass-download=${bypassDownload}`);
581
- }
582
-
583
- if (inCluster) {
584
- cmd.push('--in-cluster');
585
- }
586
- if (tolerations) {
587
- cmd.push(`--tolerations=${tolerations}`);
588
- }
589
- if (venonaVersion) {
590
- cmd.push(`--venona-version=${venonaVersion}`);
591
- }
592
- if (kubeConfigPath) {
593
- cmd.push(`--kube-config-path=${kubeConfigPath}`);
594
- }
595
- if (skipVersionCheck) {
596
- cmd.push('--skip-version-check');
597
- }
598
- if (verbose) {
599
- cmd.push('--verbose');
600
- }
601
- if (envVars) {
602
- envVars.forEach((item) => {
603
- const parts = item.split('=');
604
- cmd.push(`--set-value=EnvVars.${parts[0]}=${parts[1].replace(/,/g, '\\,')}`);
605
- });
606
- }
607
- if (valuesFile) {
608
- cmd.push(`--values=${valuesFile}`);
609
- }
610
- if (setValue) {
611
- cmd.push(`--set-value=${setValue}`);
612
- }
613
- if (setFile) {
614
- cmd.push(`--set-file=${setFile}`);
615
- }
616
- await componentRunner.run(components.venona, cmd);
617
- }
618
-
619
- async function installRuntime({
620
- apiHost, // --api-host
621
- token, // --agent-token
622
- kubeContextName, // kube-context-name
623
- kubeNamespace, // --kube-namespace
624
- dockerRegistry, // --docker-registry
625
- dryRun, // --dryRun
626
- bypassDownload, // --bypass-download
627
- inCluster, // -inCluster
628
- kubeConfigPath, // --kube-config-path
629
- verbose, // --verbose
630
- name, // --runtimeEnvironmentName
631
- envVars,
632
- valuesFile, // --values
633
- setValue, // --set-value
634
- setFile, // --set-file
635
- kubeNodeSelector, // --kube-node-selector
636
- storageClassName, // --storage-class
637
- logFormatting = DefaultLogFormatter, // --log-formtter
638
- }) {
639
- const binLocation = await downloadVeonona(undefined, bypassDownload);
640
- const componentRunner = new Runner(binLocation);
641
- const cmd = [
642
- 'install',
643
- 'runtime',
644
- '--codefreshToken',
645
- token,
646
- '--api-host',
647
- apiHost,
648
- '--kube-context-name',
649
- kubeContextName,
650
- '--kube-namespace',
651
- kubeNamespace,
652
- '--log-formtter',
653
- logFormatting,
654
- ];
655
-
656
- if (dockerRegistry) {
657
- cmd.push(`--docker-registry=${dockerRegistry}`);
658
- }
659
-
660
- if (dryRun) {
661
- cmd.push('--dry-run');
662
- }
663
- if (inCluster) {
664
- cmd.push('--in-cluster');
665
- }
666
- if (kubeConfigPath) {
667
- cmd.push(`--kube-config-path=${kubeConfigPath}`);
668
- }
669
- if (verbose) {
670
- cmd.push('--verbose');
671
- }
672
- if (valuesFile) {
673
- cmd.push(`--values=${valuesFile}`);
674
- }
675
- if (setValue) {
676
- cmd.push(`--set-value=${setValue}`);
677
- }
678
- if (envVars) {
679
- envVars.forEach((item) => {
680
- const parts = item.split('=');
681
- cmd.push(`--set-value=EnvVars.${parts[0]}=${parts[1].replace(/,/g, '\\,')}`);
682
- });
683
- }
684
- if (setFile) {
685
- cmd.push(`--set-file=${setFile}`);
686
- }
687
- if (kubeNodeSelector) {
688
- cmd.push(`--kube-node-selector=${kubeNodeSelector}`);
689
- }
690
- if (name) {
691
- cmd.push('--runtimeName');
692
- cmd.push(name);
693
- }
694
- if (storageClassName) {
695
- cmd.push(`--storage-class=${storageClassName}`);
696
- }
697
- if (process.env.NODE_TLS_REJECT_UNAUTHORIZED === '0') {
698
- cmd.push('--insecure');
699
- }
700
-
701
- await componentRunner.run(components.venona, cmd);
702
- }
703
-
704
- async function installAppProxy({
705
- kubeContextName, // kube-context-name
706
- kubeNamespace, // --kube-namespace
707
- kubeConfigPath, // --kube-config-path
708
- verbose, // --verbose
709
- dockerRegistry, // --docker-registry
710
- logFormatting = DefaultLogFormatter, // --log-formtter
711
- bypassDownload, // --bypass-download
712
- valuesFile, // --values
713
- setValue, // --set-value
714
- setFile, // --set-file
715
- appProxyHost, // --app-proxy-host
716
- appProxyIngressClass, // --app-proxy-ingress-class
717
- apiHost, // --api-host
718
- envVars, // --envVars
719
- dryRun, // --dry-run
720
- }) {
721
- const binLocation = await downloadVeonona(undefined, bypassDownload);
722
- const componentRunner = new Runner(binLocation);
723
- const cmd = [
724
- 'install',
725
- 'app-proxy',
726
- '--kube-context-name',
727
- kubeContextName,
728
- '--kube-namespace',
729
- kubeNamespace,
730
- '--log-formtter',
731
- logFormatting,
732
- ];
733
-
734
- if (dockerRegistry) {
735
- cmd.push(`--docker-registry=${dockerRegistry}`);
736
- }
737
-
738
- if (apiHost) {
739
- cmd.push(`--api-host=${apiHost}`);
740
- }
741
-
742
- if (kubeConfigPath) {
743
- cmd.push(`--kube-config-path=${kubeConfigPath}`);
744
- }
745
- if (verbose) {
746
- cmd.push('--verbose');
747
- }
748
- if (process.env.NODE_TLS_REJECT_UNAUTHORIZED === '0') {
749
- cmd.push('--insecure');
750
- }
751
- if (setValue) {
752
- if (_.isArray(setValue)) {
753
- setValue.forEach(sv => cmd.push(`--set-value=${sv}`));
754
- } else {
755
- cmd.push(`--set-value=${setValue}`);
756
- }
757
- }
758
- if (envVars) {
759
- envVars.forEach((item) => {
760
- const parts = item.split('=');
761
- cmd.push(`--set-value=EnvVars.${parts[0]}=${parts[1].replace(/,/g, '\\,')}`);
762
- });
763
- }
764
- if (valuesFile) {
765
- cmd.push(`--values=${valuesFile}`);
766
- }
767
- if (setFile) {
768
- cmd.push(`--set-file=${setFile}`);
769
- }
770
- if (appProxyHost) {
771
- cmd.push(`--host=${appProxyHost}`);
772
- }
773
- if (dryRun) {
774
- cmd.push('--dry-run');
775
- }
776
- if (appProxyIngressClass) {
777
- cmd.push(`--ingress-class=${appProxyIngressClass}`);
778
- }
779
-
780
- await componentRunner.run(components.venona, cmd, true);
781
- }
782
-
783
- async function unInstallAppProxy({
784
- kubeContextName, // kube-context-name
785
- kubeNamespace, // --kube-namespace
786
- kubeConfigPath, // --kube-config-path
787
- verbose, // --verbose
788
- bypassDownload, // --bypass-download
789
- logFormatting = DefaultLogFormatter, // --log-formtter
790
- valuesFile, // --values
791
- setValue, // --set-value
792
- }) {
793
- const binLocation = await downloadVeonona(undefined, bypassDownload);
794
- const componentRunner = new Runner(binLocation);
795
- const cmd = [
796
- 'uninstall',
797
- 'app-proxy',
798
- '--kube-context-name',
799
- kubeContextName,
800
- '--kube-namespace',
801
- kubeNamespace,
802
- '--log-formtter',
803
- logFormatting,
804
- ];
805
-
806
- if (kubeConfigPath) {
807
- cmd.push(`--kube-config-path=${kubeConfigPath}`);
808
- }
809
- if (verbose) {
810
- cmd.push('--verbose');
811
- }
812
- if (setValue) {
813
- if (_.isArray(setValue)) {
814
- setValue.forEach(sv => cmd.push(`--set-value=${sv}`));
815
- } else {
816
- cmd.push(`--set-value=${setValue}`);
817
- }
818
- }
819
- if (valuesFile) {
820
- cmd.push(`--values=${valuesFile}`);
821
- }
822
- await componentRunner.run(components.venona, cmd);
823
- }
824
-
825
- async function upgradeAppProxy({
826
- kubeContextName, // kube-context-name
827
- kubeNamespace, // --kube-namespace
828
- kubeConfigPath, // --kube-config-path
829
- verbose, // --verbose
830
- bypassDownload, // --bypass-download
831
- logFormatting = DefaultLogFormatter, // --log-formtter
832
- valuesFile, // --values
833
- setValue, // --set-value
834
- }) {
835
- const binLocation = await downloadVeonona(undefined, bypassDownload);
836
- const componentRunner = new Runner(binLocation);
837
- const cmd = [
838
- 'upgrade',
839
- 'app-proxy',
840
- '--kube-context-name',
841
- kubeContextName,
842
- '--kube-namespace',
843
- kubeNamespace,
844
- '--log-formtter',
845
- logFormatting,
846
- ];
847
-
848
- if (kubeConfigPath) {
849
- cmd.push(`--kube-config-path=${kubeConfigPath}`);
850
- }
851
- if (verbose) {
852
- cmd.push('--verbose');
853
- }
854
- if (setValue) {
855
- if (_.isArray(setValue)) {
856
- setValue.forEach(sv => cmd.push(`--set-value=${sv}`));
857
- } else {
858
- cmd.push(`--set-value=${setValue}`);
859
- }
860
- }
861
- if (valuesFile) {
862
- cmd.push(`--values=${valuesFile}`);
863
- }
864
- await componentRunner.run(components.venona, cmd);
865
- }
866
-
867
- async function attachRuntime({
868
- kubeServiceAccount, // kube-service-account
869
- kubeContextName, // kube-context-name
870
- kubeNamespace, // --kube-namespace
871
- kubeConfigPath, // --kube-config-path
872
- agentKubeContextName, // --kube-context-name-agent
873
- agentKubeNamespace, // --kube-namespace-agent
874
- agentKubeConfigPath, // --kube-config-path-agent
875
- restartAgent, // --restart-agent
876
- verbose, // --verbose
877
- runtimeName, // --runtimeName
878
- logFormatting = DefaultLogFormatter, // --log-formtter
879
- valuesFile, // --values
880
- setValue, // --set-value
881
- setFile, // --set-file
882
- dryRun,
883
- bypassDownload,
884
- }) {
885
- const binLocation = await downloadVeonona(undefined, bypassDownload);
886
- const componentRunner = new Runner(binLocation);
887
- const cmd = [
888
- 'attach',
889
- '--kube-context-name',
890
- kubeContextName,
891
- '--kube-namespace',
892
- kubeNamespace,
893
- '--runtime-name',
894
- runtimeName,
895
- '--log-formtter',
896
- logFormatting,
897
- ];
898
-
899
- if (kubeServiceAccount) {
900
- cmd.push(`--kube-service-account=${kubeServiceAccount}`);
901
- }
902
-
903
- if (kubeConfigPath) {
904
- cmd.push(`--kube-config-path=${kubeConfigPath}`);
905
- }
906
- if (agentKubeContextName) {
907
- cmd.push(`--kube-context-name-agent=${agentKubeContextName}`);
908
- }
909
- if (agentKubeNamespace) {
910
- cmd.push(`--kube-namespace-agent=${agentKubeNamespace}`);
911
- }
912
- if (agentKubeConfigPath) {
913
- cmd.push(`--kube-config-path-agent=${agentKubeConfigPath}`);
914
- }
915
- if (verbose) {
916
- cmd.push('--verbose');
917
- }
918
- if (restartAgent) {
919
- cmd.push('--restart-agent');
920
- }
921
- if (logFormatting) {
922
- cmd.push(`--log-formtter=${logFormatting}`);
923
- }
924
-
925
- if (valuesFile) {
926
- cmd.push(`--values=${valuesFile}`);
927
- }
928
- if (setValue) {
929
- if (_.isArray(setValue)) {
930
- setValue.forEach(sv => cmd.push(`--set-value=${sv}`));
931
- } else {
932
- cmd.push(`--set-value=${setValue}`);
933
- }
934
- }
935
- if (setFile) {
936
- cmd.push(`--set-file=${setFile}`);
937
- }
938
- if (dryRun) {
939
- cmd.push('--dry-run');
940
- }
941
- await componentRunner.run(components.venona, cmd);
942
- }
943
-
944
- async function newRuntimeName(kubeContextName, kubeNamespace) {
945
- const defaultName = `${kubeContextName}/${kubeNamespace}`.slice(0, maxRuntimeNameLength);
946
- const runtimes = await sdk.runtimeEnvs.list({ });
947
- let name;
948
-
949
- if (!_.isArray(runtimes) || !_.find(runtimes, re => _.get(re, 'metadata.name') === defaultName)) {
950
- name = defaultName; // use the default name if there are no collisions
951
- } else {
952
- const reNames = new Set(_.map(runtimes, re => _.get(re, 'metadata.name'))); // for fast lookup
953
- let i = 1;
954
- let suggestName;
955
- // eslint-disable-next-line no-constant-condition
956
- while (true) {
957
- suggestName = `${defaultName.slice(0, maxRuntimeNameLength - 1 - i.toString().length)}_${i}`;
958
- if (!reNames.has(suggestName)) {
959
- break;
960
- }
961
- i += 1;
962
- }
963
- name = suggestName;
964
- }
965
-
966
- return name;
967
- }
968
-
969
- async function newAgentName(kubeContextName, kubeNamespace, agents) {
970
- const defaultName = `${kubeContextName}_${kubeNamespace}`;
971
- if (!agents) {
972
- // eslint-disable-next-line no-param-reassign
973
- agents = await sdk.agents.list({ });
974
- }
975
- let name;
976
-
977
- if (!_.isArray(agents) || !_.find(agents, a => a.name === defaultName)) {
978
- name = defaultName; // use the default name if there are no collisions
979
- } else {
980
- const agentsNames = new Set(_.map(agents, a => a.name)); // for fast lookup
981
- let i = 1;
982
- while (agentsNames.has(`${defaultName}_${i}`)) {
983
- i += 1;
984
- }
985
- name = `${defaultName}_${i}`;
986
- }
987
-
988
- return name;
989
- }
990
-
991
- function keyValueAsStringToObject(nodeSelectorStr) {
992
- if (_.isString(nodeSelectorStr)) {
993
- const kubeNodeSelectorObj = {};
994
- const nsSplitParts = nodeSelectorStr.split(',');
995
- nsSplitParts.forEach((nsPart) => {
996
- const nsRecordSplit = nsPart.split('=');
997
- if (nsRecordSplit.length !== 2) {
998
- throw new Error('invalid kube-node-selector parameter');
999
- }
1000
- // eslint-disable-next-line prefer-destructuring
1001
- kubeNodeSelectorObj[nsRecordSplit[0]] = nsRecordSplit[1];
1002
- });
1003
- return kubeNodeSelectorObj;
1004
- }
1005
- return nodeSelectorStr;
1006
- }
1007
-
1008
- function objectToKeyValueArray(obj) {
1009
- return Object.keys(obj).reduce((acc, key) => {
1010
- acc.push(`${key}=${obj[key]}`);
1011
- return acc;
1012
- }, []);
1013
- }
1014
-
1015
- function serealizeToKeyValuePairs(obj) {
1016
- return _.keys(obj).reduce((acc, key) => {
1017
- if (acc) {
1018
- return `${acc},${key}=${obj[key]}`;
1019
- }
1020
- return `${key}=${obj[key]}`;
1021
- }, '');
1022
- }
1023
-
1024
- function getRuntimeImagesWithRegistryUrl(registry) {
1025
- return Object.keys(RUNTIME_IMAGES).reduce((acc, cur) => {
1026
- acc[cur] = `${registry}/${RUNTIME_IMAGES[cur]}`;
1027
- return acc;
1028
- }, {});
1029
- }
1030
-
1031
- function mergeValuesFromValuesFile(argv, valuesFile, handleError) {
1032
- const valuesFileStr = fs.readFileSync(valuesFile, 'utf8');
1033
- const valuesObj = YAML.parse(valuesFileStr);
1034
- const _argv = _.cloneDeep(argv);
1035
-
1036
- _argv.yes = true; // don't ask any questions
1037
-
1038
- if (!_.has(_argv, 'kube-config-path') && _.has(valuesObj, 'ConfigPath')) {
1039
- _.set(_argv, 'kube-config-path', valuesObj.ConfigPath);
1040
- }
1041
- if (!_.has(_argv, 'kube-context-name') && _.has(valuesObj, 'Context')) {
1042
- _.set(_argv, 'kube-context-name', valuesObj.Context);
1043
- }
1044
- if (!_.has(_argv, 'kube-namespace') && _.has(valuesObj, 'Namespace')) {
1045
- _.set(_argv, 'kube-namespace', valuesObj.Namespace);
1046
- }
1047
- if (!_.has(_argv, 'url') && _.has(valuesObj, 'CodefreshHost')) {
1048
- _.set(_argv, 'url', valuesObj.CodefreshHost);
1049
- }
1050
- if (!_.has(_argv, 'token') && _.has(valuesObj, 'Token')) {
1051
- _.set(_argv, 'token', valuesObj.Token);
1052
- }
1053
- if (!_.has(_argv, 'name') && _.has(valuesObj, 'AgentId')) {
1054
- _.set(_argv, 'name', valuesObj.AgentId);
1055
- }
1056
- if (!_.has(_argv, 'install-monitor') && _.has(valuesObj, 'Monitor.Enabled')) {
1057
- _.set(_argv, 'install-monitor', valuesObj.Monitor.Enabled);
1058
- }
1059
- if (_.get(valuesObj, 'AppProxy')) {
1060
- _.set(_argv, 'app-proxy', true);
1061
- }
1062
- if (!_.has(_argv, 'app-proxy-host') && _.get(valuesObj, 'AppProxy.Ingress.Host')) {
1063
- _.set(_argv, 'app-proxy-host', valuesObj.AppProxy.Ingress.Host);
1064
- }
1065
- if (_argv.appProxy && !_argv['app-proxy-host']) {
1066
- handleError(new Error('no hostname provided'), 'cannot install app-proxy component without a hostname', undefined, undefined, true);
1067
- }
1068
- if (!_.has(_argv, 'app-proxy-path-prefix') && _.get(valuesObj, 'AppProxy.Ingress.PathPrefix')) {
1069
- _.set(_argv, 'app-proxy-path-prefix', valuesObj.AppProxy.Ingress.PathPrefix);
1070
- }
1071
- if (!_.has(_argv, 'docker-daemon-access') && _.has(valuesObj, 'dockerDaemonScheduler.userAccess')) {
1072
- _.set(_argv, 'docker-daemon-access', valuesObj.dockerDaemonScheduler.userAccess);
1073
- }
1074
- if (_.get(_argv, 'envVars.length') === 0 && _.has(valuesObj, 'EnvVars')) {
1075
- _argv.envVars.push(...objectToKeyValueArray(_.get(valuesObj, 'EnvVars')));
1076
- }
1077
- if (!_.has(_argv, 'docker-registry') && _.has(valuesObj, 'DockerRegistry')) {
1078
- _.set(_argv, 'docker-registry', valuesObj.DockerRegistry);
1079
- }
1080
- if (!_.has(_argv, 'skip-cluster-test') && _.has(valuesObj, 'SkipClusterTest')) {
1081
- _.set(_argv, 'skip-cluster-test', valuesObj.SkipClusterTest);
1082
- }
1083
- if (_.has(valuesObj, 'RuntimeEnvironmentName')) {
1084
- _.set(_argv, 'runtimeName', valuesObj.RuntimeEnvironmentName);
1085
- }
1086
- if (_.has(valuesObj, 'Runtime.AdditionalEnvVars')) {
1087
- _.set(_argv, 'reEnvVars', valuesObj.Runtime.AdditionalEnvVars);
1088
- }
1089
- if (_.has(valuesObj, 'Runtime.NodeSelector')) {
1090
- _.set(_argv, 'build-node-selector', valuesObj.Runtime.NodeSelector);
1091
- }
1092
- if (_.has(valuesObj, 'Runtime.resources')) {
1093
- _.set(_argv, 'reResources', valuesObj.Runtime.resources);
1094
- }
1095
- if (_.has(valuesObj, 'Runtime.tolerations')) {
1096
- _.set(_argv, 'reTolerations', valuesObj.Runtime.tolerations);
1097
- }
1098
- if (_.has(valuesObj, 'Runtime.userVolumeMounts')) {
1099
- _.set(_argv, 'userVolumeMounts', valuesObj.Runtime.userVolumeMounts);
1100
- }
1101
- if (_.has(valuesObj, 'Runtime.userVolumes')) {
1102
- _.set(_argv, 'userVolumes', valuesObj.Runtime.userVolumes);
1103
- }
1104
- if (!_.has(_argv, 'storage-class-name') && _.has(valuesObj, 'StorageClass')) {
1105
- _.set(_argv, 'storage-class-name', valuesObj.StorageClass);
1106
- }
1107
- if (!_.has(_argv, 'skip-cluster-integration') && _.has(valuesObj, 'SkipClusterIntegration')) {
1108
- _.set(_argv, 'skip-cluster-integration', valuesObj.SkipClusterIntegration);
1109
- }
1110
-
1111
- return _argv;
1112
- }
1113
-
1114
265
  module.exports = {
1115
- getRelatedAgents,
1116
266
  createErrorHandler,
1117
- getRelatedNamespaces,
1118
- getRuntimesWithVersions,
1119
- getRuntimeVersion,
1120
267
  createTestPipeline,
1121
- getTestPipeline,
1122
268
  updateTestPipelineRuntime,
1123
269
  executeTestPipeline,
1124
- createProgressBar,
1125
270
  getTestPipelineLink,
1126
- drawCodefreshFiglet,
1127
- getDefaultRuntime,
1128
- getRecommendedKubeNamespace,
1129
- runClusterAcceptanceTests,
1130
- installAgent,
1131
- installRuntime,
1132
- attachRuntime,
1133
- newRuntimeName,
1134
- newAgentName,
1135
- keyValueAsStringToObject,
1136
- objectToKeyValueArray,
1137
271
  downloadRelatedComponents: downloadHybridComponents,
1138
272
  downloadComponents,
1139
273
  downloadSteveDore,
1140
- downloadVeonona,
1141
- downloadProvider,
1142
- runUpgrade,
1143
- serealizeToKeyValuePairs,
1144
- getRuntimeImagesWithRegistryUrl,
1145
- installAppProxy,
1146
- unInstallAppProxy,
1147
- upgradeAppProxy,
1148
- mergeValuesFromValuesFile,
1149
274
  INSTALLATION_DEFAULTS,
1150
- DefaultLogFormatter,
1151
275
  };