Skip to content

Commit

Permalink
refactor: update solo node start to support multiple clusters (#1385)
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 Feb 14, 2025
1 parent 49ee4f8 commit 23e17aa
Show file tree
Hide file tree
Showing 20 changed files with 331 additions and 95 deletions.
25 changes: 21 additions & 4 deletions src/commands/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {sleep} from '../core/helpers.js';
import {resolveNamespaceFromDeployment} from '../core/resolvers.js';
import {Duration} from '../core/time/duration.js';
import {type NamespaceName} from '../core/kube/resources/namespace/namespace_name.js';
import {type DeploymentName} from '../core/config/remote/types.js';

export class AccountCommand extends BaseCommand {
private readonly accountManager: AccountManager;
Expand Down Expand Up @@ -178,7 +179,11 @@ export class AccountCommand extends BaseCommand {

self.logger.debug('Initialized config', {config});

await self.accountManager.loadNodeClient(ctx.config.namespace);
await self.accountManager.loadNodeClient(
ctx.config.namespace,
self.getClusterRefs(),
self.configManager.getFlag<DeploymentName>(flags.deployment),
);
},
},
{
Expand Down Expand Up @@ -345,7 +350,11 @@ export class AccountCommand extends BaseCommand {

self.logger.debug('Initialized config', {config});

await self.accountManager.loadNodeClient(ctx.config.namespace);
await self.accountManager.loadNodeClient(
ctx.config.namespace,
self.getClusterRefs(),
self.configManager.getFlag<DeploymentName>(flags.deployment),
);

return ListrLease.newAcquireLeaseTask(lease, task);
},
Expand Down Expand Up @@ -421,7 +430,11 @@ export class AccountCommand extends BaseCommand {
// set config in the context for later tasks to use
ctx.config = config;

await self.accountManager.loadNodeClient(config.namespace);
await self.accountManager.loadNodeClient(
config.namespace,
self.getClusterRefs(),
self.configManager.getFlag<DeploymentName>(flags.deployment),
);

self.logger.debug('Initialized config', {config});
},
Expand Down Expand Up @@ -503,7 +516,11 @@ export class AccountCommand extends BaseCommand {
// set config in the context for later tasks to use
ctx.config = config;

await self.accountManager.loadNodeClient(config.namespace);
await self.accountManager.loadNodeClient(
config.namespace,
self.getClusterRefs(),
self.configManager.getFlag<DeploymentName>(flags.deployment),
);

self.logger.debug('Initialized config', {config});
},
Expand Down
29 changes: 25 additions & 4 deletions src/commands/mirror_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import chalk from 'chalk';
import {type CommandFlag} from '../types/flag_types.js';
import {PvcRef} from '../core/kube/resources/pvc/pvc_ref.js';
import {PvcName} from '../core/kube/resources/pvc/pvc_name.js';
import {type DeploymentName} from '../core/config/remote/types.js';

interface MirrorNodeDeployConfigClass {
chartDirectory: string;
Expand Down Expand Up @@ -243,7 +244,11 @@ export class MirrorNodeCommand extends BaseCommand {
// user defined values later to override predefined values
ctx.config.valuesArg += await self.prepareValuesArg(ctx.config);

await self.accountManager.loadNodeClient(ctx.config.namespace);
await self.accountManager.loadNodeClient(
ctx.config.namespace,
self.getClusterRefs(),
self.configManager.getFlag<DeploymentName>(flags.deployment),
);

if (ctx.config.pinger) {
const startAccId = constants.HEDERA_NODE_ACCOUNT_ID_START;
Expand Down Expand Up @@ -459,8 +464,20 @@ export class MirrorNodeCommand extends BaseCommand {
const exchangeRatesFileIdNum = 112;
const timestamp = Date.now();

const fees = await this.accountManager.getFileContents(namespace, feesFileIdNum);
const exchangeRates = await this.accountManager.getFileContents(namespace, exchangeRatesFileIdNum);
const clusterRefs = this.getClusterRefs();
const deployment = this.configManager.getFlag<DeploymentName>(flags.deployment);
const fees = await this.accountManager.getFileContents(
namespace,
feesFileIdNum,
clusterRefs,
deployment,
);
const exchangeRates = await this.accountManager.getFileContents(
namespace,
exchangeRatesFileIdNum,
clusterRefs,
deployment,
);

const importFeesQuery = `INSERT INTO public.file_data(file_data, consensus_timestamp, entity_id,
transaction_type)
Expand Down Expand Up @@ -616,7 +633,11 @@ export class MirrorNodeCommand extends BaseCommand {
isChartInstalled,
};

await self.accountManager.loadNodeClient(ctx.config.namespace);
await self.accountManager.loadNodeClient(
ctx.config.namespace,
self.getClusterRefs(),
self.configManager.getFlag<DeploymentName>(flags.deployment),
);

return ListrLease.newAcquireLeaseTask(lease, task);
},
Expand Down
47 changes: 38 additions & 9 deletions src/commands/node/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {type NamespaceName} from '../../core/kube/resources/namespace/namespace_
import {type PodRef} from '../../core/kube/resources/pod/pod_ref.js';
import {type K8Factory} from '../../core/kube/k8_factory.js';
import {type ConsensusNode} from '../../core/model/consensus_node.js';
import {type DeploymentName} from '../../core/config/remote/types.js';

export const PREPARE_UPGRADE_CONFIGS_NAME = 'prepareUpgradeConfig';
export const DOWNLOAD_GENERATED_FILES_CONFIGS_NAME = 'downloadGeneratedFilesConfig';
Expand Down Expand Up @@ -64,7 +65,11 @@ export const prepareUpgradeConfigBuilder = async function (argv, ctx, task) {
config.namespace = await resolveNamespaceFromDeployment(this.parent.localConfig, this.configManager, task);

await initializeSetup(config, this.k8Factory);
config.nodeClient = await this.accountManager.loadNodeClient(config.namespace);
config.nodeClient = await this.accountManager.loadNodeClient(
config.namespace,
this.parent.getClusterRefs(),
config.deployment,
);

const accountKeys = await this.accountManager.getAccountKeysFromSecret(FREEZE_ADMIN_ACCOUNT, config.namespace);
config.freezeAdminPrivateKey = accountKeys.privateKey;
Expand Down Expand Up @@ -119,7 +124,11 @@ export const upgradeConfigBuilder = async function (argv, ctx, task, shouldLoadN
constants.SOLO_DEPLOYMENT_CHART,
);
if (shouldLoadNodeClient) {
ctx.config.nodeClient = await this.accountManager.loadNodeClient(ctx.config.namespace);
ctx.config.nodeClient = await this.accountManager.loadNodeClient(
ctx.config.namespace,
this.parent.getClusterRefs(),
config.deployment,
);
}

const accountKeys = await this.accountManager.getAccountKeysFromSecret(FREEZE_ADMIN_ACCOUNT, config.namespace);
Expand Down Expand Up @@ -160,7 +169,11 @@ export const updateConfigBuilder = async function (argv, ctx, task, shouldLoadNo
);

if (shouldLoadNodeClient) {
ctx.config.nodeClient = await this.accountManager.loadNodeClient(ctx.config.namespace);
ctx.config.nodeClient = await this.accountManager.loadNodeClient(
ctx.config.namespace,
this.parent.getClusterRefs(),
config.deployment,
);
}

const accountKeys = await this.accountManager.getAccountKeysFromSecret(FREEZE_ADMIN_ACCOUNT, config.namespace);
Expand Down Expand Up @@ -207,7 +220,11 @@ export const deleteConfigBuilder = async function (argv, ctx, task, shouldLoadNo
);

if (shouldLoadNodeClient) {
ctx.config.nodeClient = await this.accountManager.loadNodeClient(ctx.config.namespace);
ctx.config.nodeClient = await this.accountManager.loadNodeClient(
ctx.config.namespace,
this.parent.getClusterRefs(),
config.deployment,
);
}

const accountKeys = await this.accountManager.getAccountKeysFromSecret(FREEZE_ADMIN_ACCOUNT, config.namespace);
Expand Down Expand Up @@ -260,7 +277,11 @@ export const addConfigBuilder = async function (argv, ctx, task, shouldLoadNodeC
);

if (shouldLoadNodeClient) {
ctx.config.nodeClient = await this.accountManager.loadNodeClient(ctx.config.namespace);
ctx.config.nodeClient = await this.accountManager.loadNodeClient(
ctx.config.namespace,
this.parent.getClusterRefs(),
config.deployment,
);
}

const accountKeys = await this.accountManager.getAccountKeysFromSecret(FREEZE_ADMIN_ACCOUNT, config.namespace);
Expand All @@ -270,7 +291,11 @@ export const addConfigBuilder = async function (argv, ctx, task, shouldLoadNodeC
const treasuryAccountPrivateKey = treasuryAccount.privateKey;
config.treasuryKey = PrivateKey.fromStringED25519(treasuryAccountPrivateKey);

config.serviceMap = await this.accountManager.getNodeServiceMap(config.namespace);
config.serviceMap = await this.accountManager.getNodeServiceMap(
config.namespace,
this.parent.getClusterRefs(),
config.deployment,
);

config.consensusNodes = this.parent.getConsensusNodes();
config.contexts = this.parent.getContexts();
Expand Down Expand Up @@ -373,9 +398,13 @@ export const startConfigBuilder = async function (argv, ctx, task) {
'contexts',
]) as NodeStartConfigClass;
config.namespace = await resolveNamespaceFromDeployment(this.parent.localConfig, this.configManager, task);
config.consensusNodes = this.parent.getConsensusNodes();

if (!(await this.k8Factory.default().namespaces().has(config.namespace))) {
throw new SoloError(`namespace ${config.namespace} does not exist`);
for (const consensusNode of config.consensusNodes) {
const k8 = this.k8Factory.getK8(consensusNode.context);
if (!(await k8.namespaces().has(config.namespace))) {
throw new SoloError(`namespace ${config.namespace} does not exist`);
}
}

config.nodeAliases = helpers.parseNodeAliases(config.nodeAliasesUnparsed);
Expand Down Expand Up @@ -445,14 +474,14 @@ export interface NodeKeysConfigClass {
export interface NodeStartConfigClass {
app: string;
cacheDir: string;
consensusNodes: ConsensusNode[];
debugNodeAlias: NodeAlias;
namespace: NamespaceName;
deployment: string;
nodeAliases: NodeAliases;
stagingDir: string;
podRefs: Record<NodeAlias, PodRef>;
nodeAliasesUnparsed: string;
consensusNodes: ConsensusNode[];
contexts: string[];
}

Expand Down
Loading

0 comments on commit 23e17aa

Please sign in to comment.