Skip to content

Commit

Permalink
fix: Bug when running solo cluster connect after fresh install (#1123)
Browse files Browse the repository at this point in the history
Signed-off-by: Ivo Yankov <[email protected]>
  • Loading branch information
Ivo-Yankov authored Jan 7, 2025
1 parent 04d5806 commit 1cd0e28
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 29 deletions.
31 changes: 31 additions & 0 deletions src/commands/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import {type CommandFlag} from '../types/flag_types.js';
import {type Lease} from '../core/lease/lease.js';
import {Listr} from 'listr2';
import path from 'path';
import * as constants from '../core/constants.js';
import fs from 'fs';

export interface CommandHandlers {
parent: BaseCommand;
Expand Down Expand Up @@ -220,4 +222,33 @@ export abstract class BaseCommand extends ShellRunner {
}
};
}

/**
* Setup home directories
* @param dirs a list of directories that need to be created in sequence
*/
setupHomeDirectory(
dirs: string[] = [
constants.SOLO_HOME_DIR,
constants.SOLO_LOGS_DIR,
constants.SOLO_CACHE_DIR,
constants.SOLO_VALUES_DIR,
],
) {
const self = this;

try {
dirs.forEach(dirPath => {
if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath, {recursive: true});
}
self.logger.debug(`OK: setup directory: ${dirPath}`);
});
} catch (e: Error | any) {
this.logger.error(e);
throw new SoloError(`failed to create directory: ${e.message}`, e);
}

return dirs;
}
}
1 change: 1 addition & 0 deletions src/commands/cluster/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class ClusterCommandHandlers implements CommandHandlers {
const action = this.parent.commandActionBuilder(
[
this.tasks.initialize(argv, connectConfigBuilder.bind(this)),
this.tasks.setupHomeDirectory(),
this.parent.getLocalConfig().promptLocalConfigTask(this.parent.getK8()),
this.tasks.selectContext(argv),
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
Expand Down
6 changes: 6 additions & 0 deletions src/commands/cluster/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,10 @@ export class ClusterCommandTasks {
ctx => !ctx.isChartInstalled,
);
}

setupHomeDirectory() {
return new Task('Setup home directory', async () => {
this.parent.setupHomeDirectory();
});
}
}
29 changes: 0 additions & 29 deletions src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,6 @@ import chalk from 'chalk';
* Defines the core functionalities of 'init' command
*/
export class InitCommand extends BaseCommand {
/**
* Setup home directories
* @param dirs a list of directories that need to be created in sequence
*/
setupHomeDirectory(
dirs: string[] = [
constants.SOLO_HOME_DIR,
constants.SOLO_LOGS_DIR,
constants.SOLO_CACHE_DIR,
constants.SOLO_VALUES_DIR,
],
) {
const self = this;

try {
dirs.forEach(dirPath => {
if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath, {recursive: true});
}
self.logger.debug(`OK: setup directory: ${dirPath}`);
});
} catch (e: Error | any) {
this.logger.error(e);
throw new SoloError(`failed to create directory: ${e.message}`, e);
}

return dirs;
}

/** Executes the init CLI command */
async init(argv: any) {
const self = this;
Expand Down

0 comments on commit 1cd0e28

Please sign in to comment.