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

feat: Update solo to load remote config near entry point #1176

Merged
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
2 changes: 0 additions & 2 deletions src/commands/mirror_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ export class MirrorNodeCommand extends BaseCommand {
return ListrLease.newAcquireLeaseTask(lease, task);
},
},
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
{
title: 'Enable mirror-node',
task: (_, parentTask) => {
Expand Down Expand Up @@ -597,7 +596,6 @@ export class MirrorNodeCommand extends BaseCommand {
return ListrLease.newAcquireLeaseTask(lease, task);
},
},
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
{
title: 'Destroy mirror-node',
task: async ctx => {
Expand Down
1 change: 0 additions & 1 deletion src/commands/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,6 @@ export class NetworkCommand extends BaseCommand {
return ListrLease.newAcquireLeaseTask(lease, task);
},
},
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
{
title: 'Copy gRPC TLS Certificates',
task: (ctx, parentTask) =>
Expand Down
23 changes: 1 addition & 22 deletions src/commands/node/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ export class NodeCommandHandlers implements CommandHandlers {
deletePrepareTaskList(argv: any, lease: Lease) {
return [
this.tasks.initialize(argv, deleteConfigBuilder.bind(this), lease),
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
this.validateSingleNodeState({excludedStates: []}),
this.tasks.identifyExistingNodes(),
this.tasks.loadAdminKey(),
Expand Down Expand Up @@ -148,7 +147,6 @@ export class NodeCommandHandlers implements CommandHandlers {
addPrepareTasks(argv: any, lease: Lease) {
return [
this.tasks.initialize(argv, addConfigBuilder.bind(this), lease),
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
this.validateSingleNodeState({excludedStates: []}),
this.tasks.checkPVCsEnabled(),
this.tasks.identifyExistingNodes(),
Expand Down Expand Up @@ -201,7 +199,6 @@ export class NodeCommandHandlers implements CommandHandlers {
updatePrepareTasks(argv, lease: Lease) {
return [
this.tasks.initialize(argv, updateConfigBuilder.bind(this), lease),
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
this.validateSingleNodeState({excludedStates: []}),
this.tasks.identifyExistingNodes(),
this.tasks.loadAdminKey(),
Expand Down Expand Up @@ -246,7 +243,6 @@ export class NodeCommandHandlers implements CommandHandlers {
upgradePrepareTasks(argv, lease: Lease) {
return [
this.tasks.initialize(argv, upgradeConfigBuilder.bind(this), lease),
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
this.validateSingleNodeState({excludedStates: []}),
this.tasks.identifyExistingNodes(),
this.tasks.loadAdminKey(),
Expand Down Expand Up @@ -282,7 +278,6 @@ export class NodeCommandHandlers implements CommandHandlers {
const action = this.parent.commandActionBuilder(
[
this.tasks.initialize(argv, prepareUpgradeConfigBuilder.bind(this), lease),
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
this.tasks.prepareUpgradeZip(),
this.tasks.sendPrepareUpgradeTransaction(),
],
Expand All @@ -304,7 +299,6 @@ export class NodeCommandHandlers implements CommandHandlers {
const action = this.parent.commandActionBuilder(
[
this.tasks.initialize(argv, prepareUpgradeConfigBuilder.bind(this), null),
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
this.tasks.prepareUpgradeZip(),
this.tasks.sendFreezeUpgradeTransaction(),
],
Expand All @@ -328,7 +322,6 @@ export class NodeCommandHandlers implements CommandHandlers {
const action = this.parent.commandActionBuilder(
[
this.tasks.initialize(argv, downloadGeneratedFilesConfigBuilder.bind(this), lease),
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
this.tasks.identifyExistingNodes(),
this.tasks.downloadNodeGeneratedFiles(),
],
Expand Down Expand Up @@ -394,7 +387,6 @@ export class NodeCommandHandlers implements CommandHandlers {
const action = this.parent.commandActionBuilder(
[
this.tasks.initialize(argv, updateConfigBuilder.bind(this), lease),
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
this.tasks.loadContextData(argv, NodeCommandHandlers.UPDATE_CONTEXT_FILE, NodeHelper.updateLoadContextParser),
...this.updateSubmitTransactionsTasks(argv),
],
Expand All @@ -416,7 +408,6 @@ export class NodeCommandHandlers implements CommandHandlers {
const action = this.parent.commandActionBuilder(
[
this.tasks.initialize(argv, updateConfigBuilder.bind(this), lease, false),
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
this.tasks.loadContextData(argv, NodeCommandHandlers.UPDATE_CONTEXT_FILE, NodeHelper.updateLoadContextParser),
...this.updateExecuteTasks(argv),
],
Expand Down Expand Up @@ -457,7 +448,6 @@ export class NodeCommandHandlers implements CommandHandlers {
const action = this.parent.commandActionBuilder(
[
this.tasks.initialize(argv, upgradeConfigBuilder.bind(this), lease),
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
this.tasks.loadContextData(argv, NodeCommandHandlers.UPGRADE_CONTEXT_FILE, NodeHelper.upgradeLoadContextParser),
...this.upgradeSubmitTransactionsTasks(argv),
],
Expand All @@ -479,7 +469,6 @@ export class NodeCommandHandlers implements CommandHandlers {
const action = this.parent.commandActionBuilder(
[
this.tasks.initialize(argv, upgradeConfigBuilder.bind(this), lease, false),
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
this.tasks.loadContextData(argv, NodeCommandHandlers.UPGRADE_CONTEXT_FILE, NodeHelper.upgradeLoadContextParser),
...this.upgradeExecuteTasks(argv),
],
Expand Down Expand Up @@ -654,7 +643,6 @@ export class NodeCommandHandlers implements CommandHandlers {
const action = this.parent.commandActionBuilder(
[
this.tasks.initialize(argv, addConfigBuilder.bind(this), lease),
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
this.tasks.loadContextData(argv, NodeCommandHandlers.ADD_CONTEXT_FILE, helpers.addLoadContextParser),
...this.addSubmitTransactionsTasks(argv),
],
Expand All @@ -678,7 +666,6 @@ export class NodeCommandHandlers implements CommandHandlers {
const action = this.parent.commandActionBuilder(
[
this.tasks.initialize(argv, addConfigBuilder.bind(this), lease, false),
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
this.tasks.identifyExistingNodes(),
this.tasks.loadContextData(argv, NodeCommandHandlers.ADD_CONTEXT_FILE, helpers.addLoadContextParser),
...this.addExecuteTasks(argv),
Expand All @@ -698,11 +685,7 @@ export class NodeCommandHandlers implements CommandHandlers {
async logs(argv: any) {
argv = helpers.addFlagsToArgv(argv, NodeFlags.LOGS_FLAGS);
const action = this.parent.commandActionBuilder(
[
this.tasks.initialize(argv, logsConfigBuilder.bind(this), null),
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
this.tasks.getNodeLogsAndConfigs(),
],
[this.tasks.initialize(argv, logsConfigBuilder.bind(this), null), this.tasks.getNodeLogsAndConfigs()],
{
concurrent: false,
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION,
Expand Down Expand Up @@ -740,7 +723,6 @@ export class NodeCommandHandlers implements CommandHandlers {
const action = this.parent.commandActionBuilder(
[
this.tasks.initialize(argv, refreshConfigBuilder.bind(this), lease),
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
this.validateAllNodeStates({
acceptedStates: [ConsensusNodeStates.STARTED, ConsensusNodeStates.SETUP, ConsensusNodeStates.INITIALIZED],
}),
Expand Down Expand Up @@ -794,7 +776,6 @@ export class NodeCommandHandlers implements CommandHandlers {
const action = this.parent.commandActionBuilder(
[
this.tasks.initialize(argv, stopConfigBuilder.bind(this), lease),
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
this.validateAllNodeStates({
acceptedStates: [ConsensusNodeStates.STARTED, ConsensusNodeStates.SETUP],
}),
Expand Down Expand Up @@ -822,7 +803,6 @@ export class NodeCommandHandlers implements CommandHandlers {
const action = this.parent.commandActionBuilder(
[
this.tasks.initialize(argv, startConfigBuilder.bind(this), lease),
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
this.validateAllNodeStates({acceptedStates: [ConsensusNodeStates.SETUP]}),
this.tasks.identifyExistingNodes(),
this.tasks.uploadStateFiles((ctx: any) => ctx.config.stateFile.length === 0),
Expand Down Expand Up @@ -853,7 +833,6 @@ export class NodeCommandHandlers implements CommandHandlers {
const action = this.parent.commandActionBuilder(
[
this.tasks.initialize(argv, setupConfigBuilder.bind(this), lease),
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
this.validateAllNodeStates({
acceptedStates: [ConsensusNodeStates.INITIALIZED],
}),
Expand Down
2 changes: 0 additions & 2 deletions src/commands/relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ export class RelayCommand extends BaseCommand {
return ListrLease.newAcquireLeaseTask(lease, task);
},
},
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
{
title: 'Prepare chart values',
task: async ctx => {
Expand Down Expand Up @@ -350,7 +349,6 @@ export class RelayCommand extends BaseCommand {
return ListrLease.newAcquireLeaseTask(lease, task);
},
},
RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
{
title: 'Destroy JSON RPC Relay',
task: async ctx => {
Expand Down
55 changes: 33 additions & 22 deletions src/core/config/remote/remote_config_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,39 +184,50 @@
/* ---------- Listr Task Builders ---------- */

/**
* Builds a task for loading the remote configuration, intended for use with Listr task management.
* Performs the loading of the remote configuration.
* Checks if the configuration is already loaded, otherwise loads and adds the command to history.
*
* @param argv - arguments containing command input for historical reference.
* @returns a Listr task which loads the remote configuration.
*/
public buildLoadTask(argv: {_: string[]}): SoloListrTask<EmptyContextConfig> {
public async loadAndValidate(argv: {_: string[]}) {
const self = this;
try {
self.setDefaultNamespaceIfNotSet();
self.setDefaultContextIfNotSet();
} catch (e) {
self.logger.showUser(chalk.red(e.message));
return;
}

Check warning on line 200 in src/core/config/remote/remote_config_manager.ts

View check run for this annotation

Codecov / codecov/patch

src/core/config/remote/remote_config_manager.ts#L194-L200

Added lines #L194 - L200 were not covered by tests

return {
title: 'Load remote config',
task: async (_, task): Promise<void> => {
try {
self.setDefaultNamespaceIfNotSet();
self.setDefaultContextIfNotSet();
} catch {
return; // TODO
}
if (!(await self.load())) {
self.logger.showUser(chalk.red('remote config not found'));

// TODO see if this should be disabled to make it an optional feature
return;
// throw new SoloError('Failed to load remote config')
}

Check warning on line 208 in src/core/config/remote/remote_config_manager.ts

View check run for this annotation

Codecov / codecov/patch

src/core/config/remote/remote_config_manager.ts#L202-L208

Added lines #L202 - L208 were not covered by tests

if (!(await self.load())) {
task.title = `${task.title} - ${chalk.red('remote config not found')}`;
await RemoteConfigValidator.validateComponents(self.remoteConfig.components, self.k8);

Check warning on line 210 in src/core/config/remote/remote_config_manager.ts

View check run for this annotation

Codecov / codecov/patch

src/core/config/remote/remote_config_manager.ts#L210

Added line #L210 was not covered by tests

// TODO see if this should be disabled to make it an optional feature
return;
// throw new SoloError('Failed to load remote config')
}
const currentCommand = argv._.join(' ');
self.remoteConfig!.addCommandToHistory(currentCommand);

Check warning on line 213 in src/core/config/remote/remote_config_manager.ts

View check run for this annotation

Codecov / codecov/patch

src/core/config/remote/remote_config_manager.ts#L212-L213

Added lines #L212 - L213 were not covered by tests

await RemoteConfigValidator.validateComponents(self.remoteConfig.components, self.k8);
await self.save();
}

Check warning on line 216 in src/core/config/remote/remote_config_manager.ts

View check run for this annotation

Codecov / codecov/patch

src/core/config/remote/remote_config_manager.ts#L215-L216

Added lines #L215 - L216 were not covered by tests

const currentCommand = argv._.join(' ');
self.remoteConfig!.addCommandToHistory(currentCommand);
/**
* Builds a listr task for loading the remote configuration.
*
* @param argv - arguments containing command input for historical reference.
* @returns a Listr task which loads the remote configuration.
*/
public buildLoadTask(argv: {_: string[]}): SoloListrTask<EmptyContextConfig> {
const self = this;

Check warning on line 225 in src/core/config/remote/remote_config_manager.ts

View check run for this annotation

Codecov / codecov/patch

src/core/config/remote/remote_config_manager.ts#L225

Added line #L225 was not covered by tests

await self.save();
return {
title: 'Load remote config',
task: async (_, task): Promise<void> => {
await self.loadAndValidate(argv);

Check warning on line 230 in src/core/config/remote/remote_config_manager.ts

View check run for this annotation

Codecov / codecov/patch

src/core/config/remote/remote_config_manager.ts#L227-L230

Added lines #L227 - L230 were not covered by tests
},
};
}
Expand Down
19 changes: 18 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,23 @@ export function main(argv: any) {
return argv;
};

const loadRemoteConfig = async (argv: any, yargs: any): Promise<any> => {
const command = argv._[0];
const subCommand = argv._[1];
const skip =
command === 'init' ||
(command === 'node' && subCommand === 'keys') ||
(command === 'cluster' && subCommand === 'connect') ||
(command === 'cluster' && subCommand === 'info') ||
(command === 'cluster' && subCommand === 'list') ||
(command === 'deployment' && subCommand === 'create');
if (!skip) {
await remoteConfigManager.loadAndValidate(argv);
}

return argv;
};

return (
yargs(hideBin(argv))
.scriptName('')
Expand All @@ -146,7 +163,7 @@ export function main(argv: any) {
.wrap(120)
.demand(1, 'Select a command')
// @ts-ignore
.middleware(processArguments, false) // applyBeforeValidate = false as otherwise middleware is called twice
.middleware([processArguments, loadRemoteConfig], false) // applyBeforeValidate = false as otherwise middleware is called twice
.parse()
);
} catch (e: Error | any) {
Expand Down
Loading