Skip to content

Commit

Permalink
wiring
Browse files Browse the repository at this point in the history
Signed-off-by: instamenta <[email protected]>
  • Loading branch information
instamenta committed Dec 11, 2024
1 parent 7b11550 commit 1948c26
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
19 changes: 10 additions & 9 deletions src/commands/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {ConsensusNodeComponent} from '../core/config/remote/components/consensus
import {ConsensusNodeStates} from '../core/config/remote/enumerations.js';
import {EnvoyProxyComponent} from '../core/config/remote/components/envoy_proxy_component.js';
import {HaProxyComponent} from '../core/config/remote/components/ha_proxy_component.js';
import {GenesisNetworkDataConstructor} from '../core/models/genesisNetworkDataConstructor.js';

export interface NetworkDeployConfigClass {
applicationEnv: string;
Expand All @@ -61,7 +62,7 @@ export interface NetworkDeployConfigClass {
grpcWebTlsCertificatePath: string;
grpcTlsKeyPath: string;
grpcWebTlsKeyPath: string;
genesisNetworkJson: string;
genesisNetworkData: GenesisNetworkDataConstructor;
getUnusedConfigs: () => string[];
haproxyIps: string;
envoyIps: string;
Expand Down Expand Up @@ -135,16 +136,16 @@ export class NetworkCommand extends BaseCommand {
config: {
chartDirectory?: string;

Check failure on line 137 in src/commands/network.ts

View workflow job for this annotation

GitHub Actions / Code Style / Standard

Delete `··`
app?: string;

Check failure on line 138 in src/commands/network.ts

View workflow job for this annotation

GitHub Actions / Code Style / Standard

Replace `······` with `····`
nodeAliases?: string[];
nodeAliases: string[];

Check failure on line 139 in src/commands/network.ts

View workflow job for this annotation

GitHub Actions / Code Style / Standard

Delete `··`
debugNodeAlias?: NodeAlias;

Check failure on line 140 in src/commands/network.ts

View workflow job for this annotation

GitHub Actions / Code Style / Standard

Replace `······` with `····`
enablePrometheusSvcMonitor?: boolean;

Check failure on line 141 in src/commands/network.ts

View workflow job for this annotation

GitHub Actions / Code Style / Standard

Delete `··`
releaseTag?: string;

Check failure on line 142 in src/commands/network.ts

View workflow job for this annotation

GitHub Actions / Code Style / Standard

Replace `······` with `····`
persistentVolumeClaims?: string;

Check failure on line 143 in src/commands/network.ts

View workflow job for this annotation

GitHub Actions / Code Style / Standard

Delete `··`
valuesFile?: string;

Check failure on line 144 in src/commands/network.ts

View workflow job for this annotation

GitHub Actions / Code Style / Standard

Replace `······` with `····`
haproxyIpsParsed?: Record<NodeAlias, IP>;

Check failure on line 145 in src/commands/network.ts

View workflow job for this annotation

GitHub Actions / Code Style / Standard

Delete `··`
envoyIpsParsed?: Record<NodeAlias, IP>;
genesisNetworkJson?: string;
} = {},
genesisNetworkData: GenesisNetworkDataConstructor;
}
) {
let valuesArg = config.chartDirectory
? `-f ${path.join(config.chartDirectory, 'solo-deployment', 'values.yaml')}`
Expand All @@ -162,7 +163,7 @@ export class NetworkCommand extends BaseCommand {
}

const profileName = this.configManager.getFlag<string>(flags.profileName) as string;
this.profileValuesFile = await this.profileManager.prepareValuesForSoloChart(profileName);
this.profileValuesFile = await this.profileManager.prepareValuesForSoloChart(profileName, config.genesisNetworkData);
if (this.profileValuesFile) {
valuesArg += this.prepareValuesFiles(this.profileValuesFile);
}
Expand All @@ -179,7 +180,7 @@ export class NetworkCommand extends BaseCommand {

// Iterate over each node and set static IPs for HAProxy
if (config.haproxyIpsParsed) {
config.nodeAliases?.forEach((nodeAlias, index) => {
config.nodeAliases.forEach((nodeAlias, index) => {
const ip = config.haproxyIpsParsed?.[nodeAlias];

if (ip) valuesArg += ` --set "hedera.nodes[${index}].haproxyStaticIP=${ip}"`;
Expand All @@ -188,7 +189,7 @@ export class NetworkCommand extends BaseCommand {

// Iterate over each node and set static IPs for Envoy Proxy
if (config.envoyIpsParsed) {
config.nodeAliases?.forEach((nodeAlias, index) => {
config.nodeAliases.forEach((nodeAlias, index) => {
const ip = config.envoyIpsParsed?.[nodeAlias];

if (ip) valuesArg += ` --set "hedera.nodes[${index}].envoyProxyStaticIP=${ip}"`;
Expand All @@ -199,7 +200,7 @@ export class NetworkCommand extends BaseCommand {
valuesArg += this.prepareValuesFiles(config.valuesFile);
}

valuesArg += `--set "hedera.configMaps.genesisNetworkJson=${config.genesisNetworkJson}"`
valuesArg += `--set "hedera.configMaps.genesisNetworkJson=${config.genesisNetworkData.toJSON()}"`

this.logger.debug('Prepared helm chart values', {valuesArg});
return valuesArg;
Expand Down Expand Up @@ -261,7 +262,7 @@ export class NetworkCommand extends BaseCommand {
constants.SOLO_DEPLOYMENT_CHART,
);

config.genesisNetworkJson = this.prepareGenesisNetworkJson(config)
config.genesisNetworkData = new GenesisNetworkDataConstructor(config.nodeAliases);

config.valuesArg = await this.prepareValuesArg(config);

Expand Down
10 changes: 7 additions & 3 deletions src/core/models/genesisNetworkDataConstructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import {KeyManager} from '../key_manager.js';

import crypto from 'node:crypto';
import {PrivateKey} from '@hashgraph/sdk';
import {constants} from '../index.js';
import * as constants from '../constants.js';

export class GenesisNetworkDataConstructor {
public readonly nodes: Record<NodeAlias, GenesisNetworkNodeDataWrapper>;

constructor (public readonly nodeAliases: NodeAliases) {
public constructor (public readonly nodeAliases: NodeAliases) {
this.nodeAliases.forEach(nodeAlias => {
this.nodes[nodeAlias] = new GenesisNetworkNodeDataWrapper(Templates.nodeIdFromNodeAlias(nodeAlias))

Expand All @@ -39,7 +39,7 @@ export class GenesisNetworkDataConstructor {
* @param keyManager
* @param keysDir - !!! config.keysDir !!!
*/
async load (keyManager: KeyManager, keysDir: string) {
public async load (keyManager: KeyManager, keysDir: string) {
await Promise.all(this.nodeAliases.map(async nodeAlias => {
const nodeKeys = await keyManager.loadSigningKey(nodeAlias, keysDir);

Expand All @@ -54,4 +54,8 @@ export class GenesisNetworkDataConstructor {
this.nodes[nodeAlias].grpcCertificateHash = hash;
}))
}

public toJSON (): string {
return JSON.stringify(this.nodes);
}
}
8 changes: 5 additions & 3 deletions src/core/profile_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export class ProfileManager {
}
}

resourcesForConsensusPod(profile: any, nodeAliases: NodeAliases, yamlRoot: object): object {
resourcesForConsensusPod(profile: any, nodeAliases: NodeAliases, yamlRoot: object, genesisNetworkData: GenesisNetworkDataConstructor): object {
if (!profile) throw new MissingArgumentError('profile is required');

const accountMap = getNodeAccountMap(nodeAliases);
Expand All @@ -198,6 +198,7 @@ export class ProfileManager {
this.configManager.getFlag(flags.releaseTag),
this.configManager.getFlag(flags.app),
this.configManager.getFlag(flags.chainId),
genesisNetworkData
);

for (const flag of flags.nodeConfigFileFlags.values()) {
Expand Down Expand Up @@ -301,9 +302,10 @@ export class ProfileManager {
/**
* Prepare a values file for Solo Helm chart
* @param profileName resource profile name
* @param genesisNetworkData
* @returns return the full path to the values file
*/
prepareValuesForSoloChart(profileName: string) {
prepareValuesForSoloChart(profileName: string, genesisNetworkData: GenesisNetworkDataConstructor) {
if (!profileName) throw new MissingArgumentError('profileName is required');
const profile = this.getProfile(profileName);

Expand All @@ -312,7 +314,7 @@ export class ProfileManager {

// generate the YAML
const yamlRoot = {};
this.resourcesForConsensusPod(profile, nodeAliases, yamlRoot);
this.resourcesForConsensusPod(profile, nodeAliases, yamlRoot, genesisNetworkData);
this.resourcesForHaProxyPod(profile, yamlRoot);
this.resourcesForEnvoyProxyPod(profile, yamlRoot);
this.resourcesForMinioTenantPod(profile, yamlRoot);
Expand Down

0 comments on commit 1948c26

Please sign in to comment.