Skip to content

Commit 7077622

Browse files
added bypass-download flag (#651)
* bump * for cr * after cr * for approval * without resolveDemoStepImage function * without resolveDemoStepImage function * fixed parameter * bump * added bypass-download flag * added bypass-download flag * changed the description * removed redundant comment * fixing CR-4318 * fixed * correction in cluster acceptance tests * for review * removed redundant line * binLocation corrections * after review Co-authored-by: roi.kramer <roi.kramer@codefresh.io>
1 parent 9cffb3d commit 7077622

File tree

12 files changed

+111
-70
lines changed

12 files changed

+111
-70
lines changed

lib/binary/downloader.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ class Downloader {
120120
}
121121
logger.debug(`${component.name} component upgrade is required, downloading.`);
122122

123-
124123
const binary = `${name}_${remoteVersion}_${osType}`;
125124
const version = component.version.prefix ? `${component.version.prefix}${remoteVersion}` : remoteVersion;
126125
const url = _buildDownloadURL({ name, version, binary });

lib/interface/cli/commands/cluster/create.cmd.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const command = new Command({
4545
serviceaccount,
4646
'kube-context': contextName,
4747
'behind-firewall': behindFirewall,
48+
'bypass-download': bypassDownload,
4849
name,
4950
} = argv;
5051
let {
@@ -53,7 +54,7 @@ const command = new Command({
5354
if (terminateProcess === undefined) {
5455
terminateProcess = true;
5556
}
56-
const binLocation = await downloadSteveDore();
57+
const binLocation = await downloadSteveDore(undefined, bypassDownload);
5758
const componentRunner = new Runner(binLocation);
5859
const commands = [
5960
'create',

lib/interface/cli/commands/components/update.cmd.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@ const command = new Command({
1414
.env('CF_ARG_') // this means that every process.env.CF_ARG_* will be passed to argv
1515
.option('location', {
1616
describe: 'Override download folder location',
17+
})
18+
.option('bypass-download', {
19+
describe: 'Will bypass the attempt to download the installer. Instead, will immediately attempt to use the binary from the components folder',
20+
default: false,
21+
type: 'boolean',
1722
}),
1823
handler: async (argv) => {
1924
console.log('Updating components');
20-
const { location } = argv;
21-
await helper.downloadRelatedComponents(location);
25+
const { location, bypassDownload } = argv;
26+
await helper.downloadRelatedComponents(location, bypassDownload);
2227
},
2328
});
2429

lib/interface/cli/commands/gitops/common/install.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ class GitopsInstaller {
77
// eslint-disable-next-line class-methods-use-this
88
async install(argv) {
99
let { httpProxy, httpsProxy } = argv;
10-
const { kubeConfigPath, provider, argoHost, argoUsername, argoPassword } = argv;
10+
const { kubeConfigPath, provider, argoHost, argoUsername, argoPassword, bypassDownload } = argv;
1111

12-
const binLocation = await downloadProvider({ provider });
12+
const binLocation = await downloadProvider({ provider }, bypassDownload);
1313
const componentRunner = new Runner(binLocation);
1414

1515
const commands = [

lib/interface/cli/commands/gitops/common/uninstall.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ const _ = require('lodash');
55
class GitopsUninstaller {
66
// eslint-disable-next-line class-methods-use-this
77
async uninstall(provider, argv) {
8-
const { 'kube-config-path': kubeConfigPath } = argv;
9-
const binLocation = await downloadProvider({ provider });
8+
const { 'kube-config-path': kubeConfigPath, 'bypass-download': bypassDownload } = argv;
9+
const binLocation = await downloadProvider({ provider }, bypassDownload);
1010
const componentRunner = new Runner(binLocation);
1111

1212
const commands = [

lib/interface/cli/commands/gitops/common/upgrade.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ class GitopsUpgrader {
1111
'kube-namespace': kubeNamespace,
1212
'kube-context-name': kubeContextName,
1313
'in-cluster': inCluster,
14+
'bypass-download': bypassDownload,
1415
} = argv;
1516

16-
const binLocation = await downloadProvider({ provider });
17+
const binLocation = await downloadProvider({ provider }, bypassDownload);
1718
const componentRunner = new Runner(binLocation);
1819

1920
const commands = [

lib/interface/cli/commands/hybrid/InstallationPlan.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class InstallationPlan {
6565
exitOnError = true,
6666
condition = true,
6767
executeOnDryRun = false,
68+
bypassDownload,
6869
}) {
6970
if (!this.completedSteps[name]) {
7071
this.state.pendingSteps.push({
@@ -78,6 +79,7 @@ class InstallationPlan {
7879
exitOnError,
7980
condition,
8081
executeOnDryRun,
82+
bypassDownload,
8183
status: STEP_STATUSES.PENDING,
8284
});
8385
}

lib/interface/cli/commands/hybrid/helper.js

Lines changed: 64 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,18 @@ async function getRecommendedKubeNamespace(kubeconfigPath, kubeContextName) {
349349
return name;
350350
}
351351

352-
async function downloadVeonona(location = CODEFRESH_PATH) {
352+
async function bypassDownloadSuccess(shouldBypass, localDir, localBin) {
353+
if (shouldBypass) {
354+
const newLocation = path.join(process.cwd(), INSTALLATION_DEFAULTS.COMPONENTS_FOLDER, localDir, localBin);
355+
if (await pathExists(newLocation)) {
356+
return true;
357+
}
358+
}
359+
return false;
360+
}
361+
362+
async function attemptDownload(location, component) {
363+
console.log('Downloading installer');
353364
const downloader = new Downloader({
354365
progress: new cliProgress.SingleBar(
355366
{
@@ -360,76 +371,66 @@ async function downloadVeonona(location = CODEFRESH_PATH) {
360371
),
361372
location,
362373
});
363-
const [error] = await to(downloader.download(components.venona));
374+
375+
return await to(downloader.download(component));
376+
}
377+
378+
async function downloadVeonona(location = CODEFRESH_PATH, bypassDownload = false) {
379+
if (await bypassDownloadSuccess(bypassDownload, components.venona.local.dir, components.venona.local.binary)) {
380+
return path.resolve(process.cwd(), INSTALLATION_DEFAULTS.COMPONENTS_FOLDER);
381+
}
382+
383+
const [error] = await attemptDownload(location, components.venona);
364384
if (error) {
365-
const newLocation = path.join(process.cwd(), INSTALLATION_DEFAULTS.COMPONENTS_FOLDER, components.venona.local.dir, components.venona.local.binary);
366-
if (await pathExists(newLocation)) {
367-
console.log('Failed to download installer, using binary from components folder');
385+
if (await bypassDownloadSuccess(!bypassDownload, components.venona.local.dir, components.venona.local.binary)) {
368386
return path.resolve(process.cwd(), INSTALLATION_DEFAULTS.COMPONENTS_FOLDER);
369387
}
370-
console.log('Failed to download component, aborting');
388+
389+
console.log('Failed to find component, aborting');
371390
throw error;
372391
}
392+
373393
return location;
374394
}
375395

376-
async function downloadProvider({ provider, location = CODEFRESH_PATH }) {
377-
const downloader = new Downloader({
378-
progress: new cliProgress.SingleBar(
379-
{
380-
stopOnComplete: true,
381-
format: CommonProgressFormat,
382-
},
383-
cliProgress.Presets.shades_classic,
384-
),
385-
location,
386-
});
387-
const [error] = await to(downloader.download(components.gitops[provider]));
396+
async function downloadProvider({ provider, location = CODEFRESH_PATH }, bypassDownload = false) {
397+
if (await bypassDownloadSuccess(bypassDownload, localSettings.dir, localSettings.binary)) {
398+
return path.resolve(process.cwd(), INSTALLATION_DEFAULTS.COMPONENTS_FOLDER);
399+
}
400+
401+
const [error] = await attemptDownload(location, components.gitops[provider]);
388402
if (error) {
389-
const localSettings = components.gitops[provider].local;
390-
const newLocation = path.join(process.cwd(), INSTALLATION_DEFAULTS.COMPONENTS_FOLDER, localSettings.dir, localSettings.binary);
391-
if (await pathExists(newLocation)) {
392-
console.log('Failed to download installer, using binary from components folder');
403+
if (await bypassDownloadSuccess(!bypassDownload, localSettings.dir, localSettings.binary)) {
393404
return path.resolve(process.cwd(), INSTALLATION_DEFAULTS.COMPONENTS_FOLDER);
394405
}
395-
console.log('Failed to download component, aborting');
406+
407+
console.log('Failed to find component, aborting');
396408
throw error;
397409
}
398410
return location;
399411
}
400412

401-
async function downloadSteveDore(location = CODEFRESH_PATH) {
402-
const downloader = new Downloader({
403-
progress: new cliProgress.SingleBar(
404-
{
405-
stopOnComplete: true,
406-
format: CommonProgressFormat,
407-
},
408-
cliProgress.Presets.shades_classic,
409-
),
410-
location,
411-
});
412-
const [error] = await to(downloader.download(components.stevedore));
413+
async function downloadSteveDore(location = CODEFRESH_PATH, bypassDownload = false) {
414+
if (await bypassDownloadSuccess(bypassDownload, components.stevedore.local.dir, components.stevedore.local.binary)) {
415+
return path.resolve(process.cwd(), INSTALLATION_DEFAULTS.COMPONENTS_FOLDER);
416+
}
417+
418+
const [error] = await attemptDownload(location, components.stevedore);
413419
if (error) {
414-
const newLocation = path.join(
415-
process.cwd(),
416-
INSTALLATION_DEFAULTS.COMPONENTS_FOLDER,
417-
components.stevedore.local.dir, components.stevedore.local.binary,
418-
);
419-
if (await pathExists(newLocation)) {
420-
console.log('Failed to download installer, using binary from components folder');
420+
if (await bypassDownloadSuccess(!bypassDownload, components.stevedore.local.dir, components.stevedore.local.binary)) {
421421
return path.resolve(process.cwd(), INSTALLATION_DEFAULTS.COMPONENTS_FOLDER);
422422
}
423-
console.log('Failed to download component, aborting');
423+
424+
console.log('Failed to find component, aborting');
424425
throw error;
425426
}
426427
return location;
427428
}
428429

429-
async function downloadHybridComponents(location) {
430-
await downloadVeonona(location);
430+
async function downloadHybridComponents(location, bypassDownload = false) {
431+
await downloadVeonona(location, bypassDownload);
431432
console.log(`Kubernetes components installer downloaded successfully to ${location} `);
432-
await downloadSteveDore(location);
433+
await downloadSteveDore(location, bypassDownload);
433434
console.log(`Kubernetes registrator installer downloaded successfully ${location}`);
434435
}
435436

@@ -444,8 +445,9 @@ async function runClusterAcceptanceTests({
444445
valuesFile, // --values
445446
setValue, // --set-value
446447
setFile, // --set-file
448+
bypassDownload, // --bypass-download
447449
}) {
448-
const binLocation = await downloadVeonona();
450+
const binLocation = await downloadVeonona(undefined, bypassDownload);
449451
const componentRunner = new Runner(binLocation);
450452
const cmd = ['test', '--log-formtter', DefaultLogFormatter];
451453
if (apiHost) {
@@ -491,7 +493,7 @@ async function runClusterAcceptanceTests({
491493
}
492494

493495
async function runUpgrade({ kubeNamespace, kubeContextName }) {
494-
const binLocation = await downloadVeonona();
496+
const binLocation = await downloadVeonona(undefined, bypassDownload);
495497
const componentRunner = new Runner(binLocation);
496498
const cmd = ['upgrade', '--log-formtter', DefaultLogFormatter];
497499
if (kubeNamespace) {
@@ -514,6 +516,7 @@ async function installAgent({
514516
token, // --agentToken
515517
kubeNodeSelector, // --kube-node-selector
516518
dryRun, // --dryRun
519+
bypassDownload, // --bypass-download
517520
inCluster, // -inCluster
518521
tolerations, // --tolerations
519522
venonaVersion, // --venona-version
@@ -526,7 +529,7 @@ async function installAgent({
526529
setValue, // --set-value
527530
setFile, // --set-file
528531
}) {
529-
const binLocation = await downloadVeonona();
532+
const binLocation = await downloadVeonona(undefined, bypassDownload);
530533
const componentRunner = new Runner(binLocation);
531534
const cmd = [
532535
'install',
@@ -557,6 +560,11 @@ async function installAgent({
557560
if (dryRun) {
558561
cmd.push('--dry-run');
559562
}
563+
564+
if (bypassDownload) {
565+
cmd.push(`--bypass-download=${bypassDownload}`);
566+
}
567+
560568
if (inCluster) {
561569
cmd.push('--in-cluster');
562570
}
@@ -600,6 +608,7 @@ async function installRuntime({
600608
kubeNamespace, // --kube-namespace
601609
dockerRegistry, // --docker-registry
602610
dryRun, // --dryRun
611+
bypassDownload, // --bypass-download
603612
inCluster, // -inCluster
604613
kubeConfigPath, // --kube-config-path
605614
verbose, // --verbose
@@ -612,7 +621,7 @@ async function installRuntime({
612621
storageClassName, // --storage-class
613622
logFormatting = DefaultLogFormatter, // --log-formtter
614623
}) {
615-
const binLocation = await downloadVeonona();
624+
const binLocation = await downloadVeonona(undefined, bypassDownload);
616625
const componentRunner = new Runner(binLocation);
617626
const cmd = [
618627
'install',
@@ -693,7 +702,7 @@ async function installAppProxy({
693702
envVars, // --envVars
694703
dryRun, // --dry-run
695704
}) {
696-
const binLocation = await downloadVeonona();
705+
const binLocation = await downloadVeonona(undefined, bypassDownload);
697706
const componentRunner = new Runner(binLocation);
698707
const cmd = [
699708
'install',
@@ -764,7 +773,7 @@ async function unInstallAppProxy({
764773
valuesFile, // --values
765774
setValue, // --set-value
766775
}) {
767-
const binLocation = await downloadVeonona();
776+
const binLocation = await downloadVeonona(undefined, bypassDownload);
768777
const componentRunner = new Runner(binLocation);
769778
const cmd = [
770779
'uninstall',
@@ -805,7 +814,7 @@ async function upgradeAppProxy({
805814
valuesFile, // --values
806815
setValue, // --set-value
807816
}) {
808-
const binLocation = await downloadVeonona();
817+
const binLocation = await downloadVeonona(undefined, bypassDownload);
809818
const componentRunner = new Runner(binLocation);
810819
const cmd = [
811820
'upgrade',
@@ -853,8 +862,9 @@ async function attachRuntime({
853862
setValue, // --set-value
854863
setFile, // --set-file
855864
dryRun,
865+
bypassDownload,
856866
}) {
857-
const binLocation = await downloadVeonona();
867+
const binLocation = await downloadVeonona(undefined, bypassDownload);
858868
const componentRunner = new Runner(binLocation);
859869
const cmd = [
860870
'attach',

lib/interface/cli/commands/hybrid/init.cmd.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ const initCmd = new Command({
208208
describe: 'Will save all of the manifests to be deployed on the cluster to: ./manifests/',
209209
default: false,
210210
type: 'boolean',
211+
})
212+
.option('bypass-download', {
213+
describe: 'Will bypass the attempt to download the installer. Instead, will immediately attempt to use the binary from the components folder',
214+
default: false,
215+
type: 'boolean',
211216
})
212217
.example('codefresh runner init --values values.yaml (see values file example here: '
213218
+ 'https://github.com/codefresh-io/venona/blob/release-1.0/venonactl/example/values-example.yaml)'),
@@ -267,6 +272,7 @@ const initCmd = new Command({
267272
userVolumeMounts,
268273
userVolumes,
269274
'dry-run': dryRun,
275+
'bypass-download': bypassDownload
270276
} = _argv;
271277
let {
272278
'kube-context-name': kubeContextName,
@@ -474,6 +480,7 @@ const initCmd = new Command({
474480
valuesFile,
475481
setValue,
476482
setFile,
483+
bypassDownload,
477484
},
478485
installationEvent: installationProgress.events.ACCEPTANCE_TESTS_RAN,
479486
condition: !skipClusterTest,
@@ -526,6 +533,7 @@ const initCmd = new Command({
526533
setValue, // --set-value
527534
setFile, // --set-file
528535
dryRun,
536+
bypassDownload,
529537
});
530538
},
531539
installationEvent: installationProgress.events.AGENT_INSTALLED,
@@ -696,6 +704,7 @@ const initCmd = new Command({
696704
setFile,
697705
storageClassName,
698706
dryRun,
707+
bypassDownload,
699708
});
700709
},
701710
installationEvent: installationProgress.events.RUNTIME_INSTALLED,
@@ -785,6 +794,7 @@ const initCmd = new Command({
785794
verbose, // --verbose
786795
runtimeName: installationPlan.getContext('runtimeName'), // --runtimeName
787796
dryRun,
797+
bypassDownload,
788798
valuesFile,
789799
setValue,
790800
setFile,
@@ -808,6 +818,7 @@ const initCmd = new Command({
808818
'set-value': setValue,
809819
'set-file': setFile,
810820
'dry-run': dryRun,
821+
'bypass-download': bypassDownload,
811822
token: _.get(sdk, 'config.context.token'),
812823
verbose,
813824
noExit: true, // to prevent if from calling inner: process.exit()

0 commit comments

Comments
 (0)