Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Bug when running solo cluster connect after fresh install #1123

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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 @@
}
};
}

/**
* 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)) {

Check warning on line 242 in src/commands/base.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/commands/base.ts#L242

The application dynamically constructs file or path information.
fs.mkdirSync(dirPath, {recursive: true});

Check warning on line 243 in src/commands/base.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/commands/base.ts#L243

The application dynamically constructs file or path information.
}

Check warning on line 244 in src/commands/base.ts

View check run for this annotation

Codecov / codecov/patch

src/commands/base.ts#L243-L244

Added lines #L243 - L244 were not covered by tests
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);
}

Check warning on line 250 in src/commands/base.ts

View check run for this annotation

Codecov / codecov/patch

src/commands/base.ts#L248-L250

Added lines #L248 - L250 were not covered by tests

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 @@
const action = this.parent.commandActionBuilder(
[
this.tasks.initialize(argv, connectConfigBuilder.bind(this)),
this.tasks.setupHomeDirectory(),

Check warning on line 46 in src/commands/cluster/handlers.ts

View check run for this annotation

Codecov / codecov/patch

src/commands/cluster/handlers.ts#L46

Added line #L46 was not covered by tests
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 @@
ctx => !ctx.isChartInstalled,
);
}

setupHomeDirectory() {
return new Task('Setup home directory', async () => {
this.parent.setupHomeDirectory();
});
}

Check warning on line 339 in src/commands/cluster/tasks.ts

View check run for this annotation

Codecov / codecov/patch

src/commands/cluster/tasks.ts#L336-L339

Added lines #L336 - L339 were not covered by tests
}
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
Loading