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 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
67ad483
implemented copying mechanism and created the initial data wrapper fo…
instamenta Jan 20, 2025
82d0a8f
apply recommended changes
instamenta Jan 21, 2025
0ca31f0
updated to latest version of hedera-service main branch
jeromy-cannon Jan 21, 2025
0441417
Merge remote-tracking branch 'origin/main' into 01151-create-the-v059…
instamenta Jan 22, 2025
74d1c16
merge with main and ran npm i
instamenta Jan 23, 2025
401ebac
Merge remote-tracking branch 'origin/main' into 01151-create-the-v059…
instamenta Jan 24, 2025
91329f1
Merge remote-tracking branch 'origin/main' into 01151-create-the-v059…
instamenta Jan 27, 2025
03f86ba
Merge branch 'main' into 01151-create-the-v059x-network-overrideyml-v…
jeromy-cannon Jan 27, 2025
0dccc4d
switch to new structure for the NetworkOverridesModel.toYaml() method…
instamenta Jan 28, 2025
d4511e6
add functionality to turn json string inside the node overrides to js…
instamenta Jan 29, 2025
bef5aa0
Merge remote-tracking branch 'origin/main' into 01151-create-the-v059…
instamenta Jan 31, 2025
ff069c8
swith all calls to the setupNetworkNode method to true on the isGenes…
instamenta Feb 3, 2025
ea50860
fix lint errors
instamenta Feb 3, 2025
219af9a
add try catch when trying to get the admin pub key fromStringED25519 …
instamenta Feb 3, 2025
941af82
revert to stable hedera platform version
instamenta Feb 3, 2025
294256e
rename from NetworkOverridesModel to NodeOverridesModel
instamenta Feb 3, 2025
8fc07f5
Merge commit '04b616e16ee224772ac5a1d181d814713400984d' into 01151-cr…
JeffreyDallas Feb 5, 2025
fab250b
Update src/commands/node/handlers.ts
JeffreyDallas Feb 5, 2025
444614a
Update src/commands/node/handlers.ts
JeffreyDallas Feb 5, 2025
f87b07c
Update src/commands/node/handlers.ts
JeffreyDallas Feb 5, 2025
f1035e9
add constant
JeffreyDallas Feb 5, 2025
218eddf
generate new key if not found
JeffreyDallas Feb 5, 2025
badbaaf
fix constructor
JeffreyDallas Feb 5, 2025
8a6bfbf
save
JeffreyDallas Feb 5, 2025
1f53f30
Merge branch 'main' into 01151-create-the-v059x-network-overrideyml-v…
JeffreyDallas Feb 5, 2025
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),
JeffreyDallas marked this conversation as resolved.
Show resolved Hide resolved
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),
JeffreyDallas marked this conversation as resolved.
Show resolved Hide resolved
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),
JeffreyDallas marked this conversation as resolved.
Show resolved Hide resolved
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.
JeffreyDallas marked this conversation as resolved.
Show resolved Hide resolved
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if not provided by the user then we generate one and then store it in k8s secrets, but DO NOT set it to GENESIS

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the logic create new key and save to k8 if no one is available

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.
JeffreyDallas marked this conversation as resolved.
Show resolved Hide resolved
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