Skip to content

Commit

Permalink
feat: Update solo to load remote config near entry point (#1176)
Browse files Browse the repository at this point in the history
Signed-off-by: Ivo Yankov <ivo@devlabs.bg>
  • Loading branch information
Ivo-Yankov authored Jan 18, 2025
1 parent fe42edd commit 473a650
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 50 deletions.
2 changes: 0 additions & 2 deletions src/commands/mirror_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,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 @@ -624,7 +623,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 @@ -238,7 +238,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 @@ -369,7 +368,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 @@ export class RemoteConfigManager {
/* ---------- 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;
}

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')
}

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

// 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);

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

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;

await self.save();
return {
title: 'Load remote config',
task: async (_, task): Promise<void> => {
await self.loadAndValidate(argv);
},
};
}
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

0 comments on commit 473a650

Please sign in to comment.