Skip to content

Commit 93a40ed

Browse files
Cr 4249 fix2 (#662)
* fixing helm-chart-generation
1 parent 0062178 commit 93a40ed

File tree

4 files changed

+52
-63
lines changed

4 files changed

+52
-63
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const command = new Command({
2323
handler: async (argv) => {
2424
console.log('Updating components');
2525
const { location, bypassDownload } = argv;
26-
await helper.downloadRelatedComponents(location, bypassDownload);
26+
await helper.downloadRelatedComponents(location, bypassDownload);
2727
},
2828
});
2929

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

Lines changed: 37 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const INSTALLATION_DEFAULTS = {
3434
COMPONENTS_FOLDER: 'components',
3535
KUBECONFIG_PATH: path.join(homedir(), '.kube', 'config'),
3636
SAAS_RUNTIME: 'SAAS runtime',
37+
HELM_FILE_PATH: path.join(process.cwd(), 'generated_values.yaml'),
3738
};
3839

3940
const RUNTIME_IMAGES = {
@@ -349,18 +350,33 @@ async function getRecommendedKubeNamespace(kubeconfigPath, kubeContextName) {
349350
return name;
350351
}
351352

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;
353+
async function getComponent(location = CODEFRESH_PATH, component, bypassDownload) {
354+
const componentName = component.name || 'component';
355+
const localBinLocation = path.join(
356+
process.cwd(),
357+
INSTALLATION_DEFAULTS.COMPONENTS_FOLDER,
358+
_.get(component, 'local.dir', ''),
359+
_.get(component, 'local.bin', ''),
360+
);
361+
362+
const downloadedBinLocation = path.join(
363+
process.cwd(),
364+
location,
365+
_.get(component, 'local.dir', ''),
366+
_.get(component, 'local.bin', ''),
367+
);
368+
369+
if (bypassDownload) {
370+
if (await pathExists(localBinLocation)) {
371+
return path.join(process.cwd(), INSTALLATION_DEFAULTS.COMPONENTS_FOLDER);
372+
}
373+
if (await pathExists(downloadedBinLocation)) {
374+
return location;
357375
}
376+
377+
throw new Error(`cannot bypass download, ${componentName} not found, aborting.`);
358378
}
359-
return false;
360-
}
361379

362-
async function attemptDownload(location, component) {
363-
console.log('Downloading installer');
364380
const downloader = new Downloader({
365381
progress: new cliProgress.SingleBar(
366382
{
@@ -372,61 +388,30 @@ async function attemptDownload(location, component) {
372388
location,
373389
});
374390

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-
}
391+
const [err] = await to(downloader.download(component));
392+
if (err) {
393+
if (await pathExists(localBinLocation)) {
394+
console.log(`failed to download ${componentName}, using local binary instead`);
382395

383-
const [error] = await attemptDownload(location, components.venona);
384-
if (error) {
385-
if (await bypassDownloadSuccess(!bypassDownload, components.venona.local.dir, components.venona.local.binary)) {
386396
return path.resolve(process.cwd(), INSTALLATION_DEFAULTS.COMPONENTS_FOLDER);
387397
}
388398

389-
console.log('Failed to find component, aborting');
390-
throw error;
399+
throw new Error(`failed to download ${componentName}, aborting.`);
391400
}
392401

393402
return location;
394403
}
395404

396-
async function downloadProvider({ provider, location = CODEFRESH_PATH }, bypassDownload = false) {
397-
const localSettings = components.gitops[provider].local;
398-
399-
if (await bypassDownloadSuccess(bypassDownload, localSettings.dir, localSettings.binary)) {
400-
return path.resolve(process.cwd(), INSTALLATION_DEFAULTS.COMPONENTS_FOLDER);
401-
}
402-
403-
const [error] = await attemptDownload(location, components.gitops[provider]);
404-
if (error) {
405-
if (await bypassDownloadSuccess(!bypassDownload, localSettings.dir, localSettings.binary)) {
406-
return path.resolve(process.cwd(), INSTALLATION_DEFAULTS.COMPONENTS_FOLDER);
407-
}
408-
409-
console.log('Failed to find component, aborting');
410-
throw error;
411-
}
412-
return location;
405+
async function downloadVeonona(location, bypassDownload = false) {
406+
return await getComponent(location, components.venona, bypassDownload);
413407
}
414408

415-
async function downloadSteveDore(location = CODEFRESH_PATH, bypassDownload = false) {
416-
if (await bypassDownloadSuccess(bypassDownload, components.stevedore.local.dir, components.stevedore.local.binary)) {
417-
return path.resolve(process.cwd(), INSTALLATION_DEFAULTS.COMPONENTS_FOLDER);
418-
}
419-
420-
const [error] = await attemptDownload(location, components.stevedore);
421-
if (error) {
422-
if (await bypassDownloadSuccess(!bypassDownload, components.stevedore.local.dir, components.stevedore.local.binary)) {
423-
return path.resolve(process.cwd(), INSTALLATION_DEFAULTS.COMPONENTS_FOLDER);
424-
}
409+
async function downloadProvider({ provider, location }, bypassDownload = false) {
410+
return await await getComponent(location, components.gitops[provider], bypassDownload);
411+
}
425412

426-
console.log('Failed to find component, aborting');
427-
throw error;
428-
}
429-
return location;
413+
async function downloadSteveDore(location, bypassDownload = false) {
414+
return await getComponent(location, components.stevedore, bypassDownload);
430415
}
431416

432417
async function downloadHybridComponents(location, bypassDownload = false) {

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ const initCmd = new Command({
257257
const {
258258
'kube-node-selector': kubeNodeSelector,
259259
'build-node-selector': buildNodeSelector,
260-
'generate-helm-values-file': helmValuesFile,
261260
tolerations,
262261
'kube-config-path': kubeConfigPath,
263262
'storage-class-name': storageClassName,
@@ -287,9 +286,8 @@ const initCmd = new Command({
287286
'bypass-download': bypassDownload,
288287
} = _argv;
289288

290-
const shouldUseHelm = !!helmValuesFile;
291-
292289
let {
290+
'generate-helm-values-file': helmValuesFile,
293291
'kube-context-name': kubeContextName,
294292
'kube-namespace': kubeNamespace,
295293
'set-default-runtime': shouldMakeDefaultRe,
@@ -305,6 +303,13 @@ const initCmd = new Command({
305303
url = DEFAULTS.URL;
306304
}
307305

306+
if (helmValuesFile === '') {
307+
// if the user specified the --generate-helm-values-file flag
308+
// but did not specify file path, use a default path
309+
helmValuesFile = INSTALLATION_DEFAULTS.HELM_FILE_PATH;
310+
}
311+
const shouldUseHelm = !!helmValuesFile;
312+
308313
if (_.get(sdk, 'config.context.isNoAuth') && !token) {
309314
console.log('Not authenticated as a Codefresh account: ');
310315
console.log('In order to install a Codefresh Runner you need to provide ' +
@@ -944,12 +949,11 @@ const initCmd = new Command({
944949
await drawCodefreshFiglet();
945950

946951
if (shouldUseHelm) {
947-
console.log('\nTo install helm run:\n');
948-
console.log('helm repo add cf-runtime https://h.cfcr.io/codefresh-inc/runtime');
949-
console.log(`kubectl create ns ${kubeNamespace}`);
950-
console.log(`helm install cf-runtime cf-runtime/cf-runtime -f ${helmValuesFile} --namespace ${kubeNamespace}\n`);
951-
console.log('In order to test your runner helm based installation please execute\n' +
952-
'codefresh runner execute-test-pipeline');
952+
console.log(colors.blue('\nTo complete helm installation run: '));
953+
console.log(' helm repo add cf-runtime https://h.cfcr.io/codefresh-inc/runtime');
954+
console.log(` helm install cf-runtime cf-runtime/cf-runtime -f ${helmValuesFile} --create-namespace --namespace ${kubeNamespace}`);
955+
console.log(colors.blue('\nIn order to test your runner helm based installation please execute:\n'));
956+
console.log(' codefresh runner execute-test-pipeline\n');
953957
}
954958

955959
process.exit(); // TODO : This is not needed - needed to be fixed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codefresh",
3-
"version": "0.75.17",
3+
"version": "0.75.18",
44
"description": "Codefresh command line utility",
55
"main": "index.js",
66
"preferGlobal": true,

0 commit comments

Comments
 (0)