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: create the v059x node-override.yaml via solo #1192

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
11 changes: 5 additions & 6 deletions src/commands/node/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class NodeCommandHandlers implements CommandHandlers {
this.tasks.checkNodePodsAreRunning(),
this.tasks.populateServiceMap(),
this.tasks.fetchPlatformSoftware('allNodeAliases'),
this.tasks.setupNetworkNodes('allNodeAliases'),
this.tasks.setupNetworkNodes('allNodeAliases', true),
this.tasks.startNodes('allNodeAliases'),
this.tasks.enablePortForwarding(),
this.tasks.checkAllNodesAreActive('allNodeAliases'),
Expand Down Expand Up @@ -171,7 +171,7 @@ export class NodeCommandHandlers implements CommandHandlers {
this.tasks.fetchPlatformSoftware('allNodeAliases'),
this.tasks.downloadLastState(),
this.tasks.uploadStateToNewNode(),
this.tasks.setupNetworkNodes('allNodeAliases'),
this.tasks.setupNetworkNodes('allNodeAliases', true),
this.tasks.startNodes('allNodeAliases'),
this.tasks.enablePortForwarding(),
this.tasks.checkAllNodesAreActive('allNodeAliases'),
Expand Down Expand Up @@ -216,7 +216,7 @@ export class NodeCommandHandlers implements CommandHandlers {
this.tasks.killNodesAndUpdateConfigMap(),
this.tasks.checkNodePodsAreRunning(),
this.tasks.fetchPlatformSoftware('allNodeAliases'),
this.tasks.setupNetworkNodes('allNodeAliases'),
this.tasks.setupNetworkNodes('allNodeAliases', true),
this.tasks.startNodes('allNodeAliases'),
this.tasks.enablePortForwarding(),
this.tasks.checkAllNodesAreActive('allNodeAliases'),
Expand Down Expand Up @@ -715,7 +715,7 @@ export class NodeCommandHandlers implements CommandHandlers {
this.tasks.identifyNetworkPods(),
this.tasks.dumpNetworkNodesSaveState(),
this.tasks.fetchPlatformSoftware('nodeAliases'),
this.tasks.setupNetworkNodes('nodeAliases'),
this.tasks.setupNetworkNodes('nodeAliases', true),
this.tasks.startNodes('nodeAliases'),
this.tasks.checkAllNodesAreActive('nodeAliases'),
this.tasks.checkNodeProxiesAreActive(),
Expand Down Expand Up @@ -824,8 +824,7 @@ export class NodeCommandHandlers implements CommandHandlers {
}),
this.tasks.identifyNetworkPods(),
this.tasks.fetchPlatformSoftware('nodeAliases'),
// TODO: change to isGenesis: true once we are ready to use genesis-network.json: this.tasks.setupNetworkNodes('nodeAliases', true),
this.tasks.setupNetworkNodes('nodeAliases', false),
this.tasks.setupNetworkNodes('nodeAliases', true),
this.changeAllNodeStates(ConsensusNodeStates.SETUP),
],
{
Expand Down
14 changes: 13 additions & 1 deletion src/commands/node/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import {type BaseCommand} from '../base.js';
import {type NodeAddConfigClass} from './node_add_config.js';
import {GenesisNetworkDataConstructor} from '../../core/genesis_network_models/genesis_network_data_constructor.js';
import {NodeOverridesModel} from '../../core/network_overrides_model.js';

export class NodeCommandTasks {
private readonly accountManager: AccountManager;
Expand Down Expand Up @@ -907,7 +908,7 @@
});
}

setupNetworkNodes(nodeAliasesProperty: string, isGenesis: boolean = false) {
setupNetworkNodes(nodeAliasesProperty: string, isGenesis: boolean) {
return new Task('Setup network nodes', async (ctx: any, task: ListrTaskWrapper<any, any, any>) => {
if (isGenesis) {
await this.generateGenesisNetworkJson(
Expand All @@ -918,6 +919,8 @@
);
}

await this.generateNetworksOverridesJson(ctx.config.namespace, ctx.config.nodeAliases, ctx.config.stagingDir);

const subTasks = [];
for (const nodeAlias of ctx.config[nodeAliasesProperty]) {
const podName = ctx.config.podNames[nodeAlias];
Expand All @@ -935,6 +938,15 @@
});
}

private async generateNetworksOverridesJson(namespace: string, nodeAliases: NodeAliases, stagingDir: string) {
const networkNodeServiceMap = await this.accountManager.getNodeServiceMap(namespace);

const networkOverridesModel = new NodeOverridesModel(nodeAliases, networkNodeServiceMap);

const genesisNetworkJson = path.join(stagingDir, 'node-overrides.yaml');

Check warning on line 946 in src/commands/node/tasks.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/commands/node/tasks.ts#L946

Detected possible user input going into a `path.join` or `path.resolve` function.
fs.writeFileSync(genesisNetworkJson, networkOverridesModel.toYAML());

Check warning on line 947 in src/commands/node/tasks.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/commands/node/tasks.ts#L947

The application dynamically constructs file or path information.
}

/**
* Generate genesis network json file
* @private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,17 @@ export class GenesisNetworkDataConstructor implements ToJSON {
) {
nodeAliases.forEach(nodeAlias => {
const genesisPrivateKey = PrivateKey.fromStringED25519(constants.GENESIS_KEY);
const adminPubKey = PublicKey.fromStringED25519(adminPublicKeyMap[nodeAlias])
? adminPublicKeyMap[nodeAlias]
: genesisPrivateKey.publicKey;

let adminPubKey: PublicKey;
try {
if (PublicKey.fromStringED25519(adminPublicKeyMap[nodeAlias])) {
adminPubKey = adminPublicKeyMap[nodeAlias];
}
} catch {
// Ignore error
}

if (!adminPubKey) adminPubKey = genesisPrivateKey.publicKey;

const nodeDataWrapper = new GenesisNetworkNodeDataWrapper(
+networkNodeServiceMap.get(nodeAlias).nodeId,
Expand Down
54 changes: 54 additions & 0 deletions src/core/network_overrides_model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* SPDX-License-Identifier: Apache-2.0
*/
import * as yaml from 'yaml';
import * as constants from './constants.js';
import {Templates} from './templates.js';
import {type NodeAliases} from '../types/aliases.js';
import {type NetworkNodeServices} from './network_node_services.js';
import {type GossipEndpoint} from '../types/index.js';

export class NodeOverridesModel {
private readonly interfaceBindings: GossipEndpoint[] = [];
private readonly endpointOverrides: GossipEndpoint[] = [];

public constructor(nodeAliases: NodeAliases, networkNodeServiceMap: Map<string, NetworkNodeServices>) {
nodeAliases.forEach(nodeAlias => {
const namespace = networkNodeServiceMap.get(nodeAlias).namespace;
const nodeId = +networkNodeServiceMap.get(nodeAlias).nodeId;

const localClusterPort = +constants.HEDERA_NODE_EXTERNAL_GOSSIP_PORT;
const localClusterHostName = Templates.renderFullyQualifiedNetworkSvcName(namespace, nodeAlias);

this.interfaceBindings.push({nodeId, hostname: localClusterHostName, port: localClusterPort});
// TODO future, add endpointOverrides for addresses external to cluster in multi-cluster support situation
// this.endpointOverrides.push({nodeId, hostname: externalHostname, port: externalPort});
});
}

/**
* Converts the model to YAML as expected to be consumed inside node
* @returns the raw YAML as string
*
* @example
* gossip:
* interfaceBindings:
* - { "nodeId": 0, "hostname": "10.10.10.1", "port": 1234 }
* - { "nodeId": 3, "hostname": "2001:db8:3333:4444:5555:6666:7777:8888", "port": 1237 }
* endpointOverrides:
* - { "nodeId": 5, "hostname": "10.10.10.11", "port": 1238 }
*/
public toYAML(): string {
const gossipData: {interfaceBindings?: string[]; endpointOverrides?: string[]} = {};

if (this.interfaceBindings.length) {
gossipData.interfaceBindings = this.interfaceBindings.map(d => JSON.stringify(d));
}

if (this.endpointOverrides.length) {
gossipData.endpointOverrides = this.endpointOverrides.map(d => JSON.stringify(d));
}

return yaml.stringify({gossip: gossipData}).replaceAll(/'/g, '');
}
}
4 changes: 4 additions & 0 deletions src/core/platform_installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,12 @@
private async copyConfigurationFiles(stagingDir: string, podName: `network-node${number}-0`, isGenesis: boolean) {
if (isGenesis) {
const genesisNetworkJson = [path.join(stagingDir, 'genesis-network.json')];

await this.copyFiles(podName, genesisNetworkJson, `${constants.HEDERA_HAPI_PATH}/data/config`);
}

const networkOverridesYaml = [path.join(stagingDir, 'node-overrides.yaml')];

Check warning on line 304 in src/core/platform_installer.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/core/platform_installer.ts#L304

Detected possible user input going into a `path.join` or `path.resolve` function.
await this.copyFiles(podName, networkOverridesYaml, `${constants.HEDERA_HAPI_PATH}/data/config`);
}

/**
Expand Down
11 changes: 11 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,14 @@ export interface GenesisNetworkRosterStructure {
gossipEndpoint: ServiceEndpoint[];
gossipCaCertificate: string;
}

export interface GossipEndpoint {
nodeId: number;
hostname: string;
port: number;
}

export interface NetworkOverridesStructure {
interfaceBindings: GossipEndpoint[];
endpointOverrides: GossipEndpoint[];
}
Loading