Skip to content

Commit b9f6d10

Browse files
committed
removed final todo for network deploy
Signed-off-by: Jeromy Cannon <[email protected]>
1 parent 03ad78f commit b9f6d10

File tree

3 files changed

+58
-45
lines changed

3 files changed

+58
-45
lines changed

src/commands/network.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -697,10 +697,13 @@ export class NetworkCommand extends BaseCommand {
697697
const config = ctx.config;
698698

699699
// set up the subtasks
700-
return parentTask.newListr(self.platformInstaller.copyNodeKeys(config.stagingDir, config.nodeAliases), {
701-
concurrent: true,
702-
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION,
703-
});
700+
return parentTask.newListr(
701+
self.platformInstaller.copyNodeKeys(config.stagingDir, config.consensusNodes, config.contexts),
702+
{
703+
concurrent: true,
704+
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION,
705+
},
706+
);
704707
},
705708
},
706709
{

src/commands/node/tasks.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1486,7 +1486,11 @@ export class NodeCommandTasks {
14861486

14871487
copyNodeKeysToSecrets() {
14881488
return new Task('Copy node keys to secrets', (ctx: any, task: ListrTaskWrapper<any, any, any>) => {
1489-
const subTasks = this.platformInstaller.copyNodeKeys(ctx.config.stagingDir, ctx.config.allNodeAliases);
1489+
const subTasks = this.platformInstaller.copyNodeKeys(
1490+
ctx.config.stagingDir,
1491+
ctx.config.allNodeAliases,
1492+
ctx.config.contexts,
1493+
);
14901494

14911495
// set up the sub-tasks for copying node keys to staging directory
14921496
return task.newListr(subTasks, {

src/core/platform_installer.ts

Lines changed: 46 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@ import * as Base64 from 'js-base64';
1414
import chalk from 'chalk';
1515

1616
import {type SoloLogger} from './logging.js';
17-
import {type NodeAlias, type NodeAliases} from '../types/aliases.js';
17+
import {type NodeAlias} from '../types/aliases.js';
1818
import {Duration} from './time/duration.js';
1919
import {sleep} from './helpers.js';
2020
import {inject, injectable} from 'tsyringe-neo';
2121
import {patchInject} from './dependency_injection/container_helper.js';
22-
import {type NamespaceName} from './kube/resources/namespace/namespace_name.js';
22+
import {NamespaceName} from './kube/resources/namespace/namespace_name.js';
2323
import {type PodRef} from './kube/resources/pod/pod_ref.js';
2424
import {ContainerRef} from './kube/resources/container/container_ref.js';
2525
import {SecretType} from './kube/resources/secret/secret_type.js';
2626
import {InjectTokens} from './dependency_injection/inject_tokens.js';
27+
import {type ConsensusNode} from './model/consensus_node.js';
2728

2829
/** PlatformInstaller install platform code in the root-container of a network pod */
2930
@injectable()
@@ -144,20 +145,24 @@ export class PlatformInstaller {
144145
}
145146
}
146147

147-
async copyGossipKeys(nodeAlias: NodeAlias, stagingDir: string, nodeAliases: NodeAliases) {
148-
if (!nodeAlias) throw new MissingArgumentError('nodeAlias is required');
148+
async copyGossipKeys(consensusNode: ConsensusNode, stagingDir: string, consensusNodes: ConsensusNode[]) {
149+
if (!consensusNode) throw new MissingArgumentError('consensusNode is required');
149150
if (!stagingDir) throw new MissingArgumentError('stagingDir is required');
150-
if (!nodeAliases || nodeAliases.length <= 0) throw new MissingArgumentError('nodeAliases cannot be empty');
151+
if (!consensusNodes || consensusNodes.length <= 0) throw new MissingArgumentError('consensusNodes cannot be empty');
151152

152153
try {
153154
const srcFiles = [];
154155

155156
// copy private keys for the node
156-
srcFiles.push(path.join(stagingDir, 'keys', Templates.renderGossipPemPrivateKeyFile(nodeAlias)));
157+
srcFiles.push(
158+
path.join(stagingDir, 'keys', Templates.renderGossipPemPrivateKeyFile(consensusNode.name as NodeAlias)),
159+
);
157160

158161
// copy all public keys for all nodes
159-
nodeAliases.forEach(nodeAlias => {
160-
srcFiles.push(path.join(stagingDir, 'keys', Templates.renderGossipPemPublicKeyFile(nodeAlias)));
162+
consensusNodes.forEach(consensusNode => {
163+
srcFiles.push(
164+
path.join(stagingDir, 'keys', Templates.renderGossipPemPublicKeyFile(consensusNode.name as NodeAlias)),
165+
);
161166
});
162167

163168
const data = {};
@@ -168,44 +173,42 @@ export class PlatformInstaller {
168173
data[fileName] = Base64.encode(fileContents);
169174
}
170175

171-
// TODO: @Lenin, will need to run for each cluster
172176
const secretCreated = await this.k8Factory
173-
.default()
177+
.getK8(consensusNode.context)
174178
.secrets()
175179
.createOrReplace(
176-
this._getNamespace(),
177-
Templates.renderGossipKeySecretName(nodeAlias),
180+
NamespaceName.of(consensusNode.namespace),
181+
Templates.renderGossipKeySecretName(consensusNode.name as NodeAlias),
178182
SecretType.OPAQUE,
179183
data,
180-
Templates.renderGossipKeySecretLabelObject(nodeAlias),
184+
Templates.renderGossipKeySecretLabelObject(consensusNode.name as NodeAlias),
181185
);
182186

183187
if (!secretCreated) {
184-
throw new SoloError(`failed to create secret for gossip keys for node '${nodeAlias}'`);
188+
throw new SoloError(`failed to create secret for gossip keys for node '${consensusNode.name}'`);
185189
}
186190
} catch (e: Error | any) {
187-
this.logger.error(
188-
`failed to copy gossip keys to secret '${Templates.renderGossipKeySecretName(nodeAlias)}': ${e.message}`,
189-
e,
190-
);
191-
throw new SoloError(
192-
`failed to copy gossip keys to secret '${Templates.renderGossipKeySecretName(nodeAlias)}': ${e.message}`,
193-
e,
194-
);
191+
const message = `failed to copy gossip keys to secret '${Templates.renderGossipKeySecretName(consensusNode.name as NodeAlias)}': ${e.message}`;
192+
this.logger.error(message, e);
193+
throw new SoloError(message, e);
195194
}
196195
}
197196

198-
async copyTLSKeys(nodeAliases: NodeAliases, stagingDir: string) {
199-
if (!nodeAliases || nodeAliases.length <= 0) throw new MissingArgumentError('nodeAliases cannot be empty');
197+
async copyTLSKeys(consensusNodes: ConsensusNode[], stagingDir: string, contexts: string[]) {
198+
if (!consensusNodes || consensusNodes.length <= 0) throw new MissingArgumentError('consensusNodes cannot be empty');
200199
if (!stagingDir) throw new MissingArgumentError('stagingDir is required');
201200

202201
try {
203202
const data = {};
204203

205-
for (const nodeAlias of nodeAliases) {
204+
for (const consensusNode of consensusNodes) {
206205
const srcFiles = [];
207-
srcFiles.push(path.join(stagingDir, 'keys', Templates.renderTLSPemPrivateKeyFile(nodeAlias)));
208-
srcFiles.push(path.join(stagingDir, 'keys', Templates.renderTLSPemPublicKeyFile(nodeAlias)));
206+
srcFiles.push(
207+
path.join(stagingDir, 'keys', Templates.renderTLSPemPrivateKeyFile(consensusNode.name as NodeAlias)),
208+
);
209+
srcFiles.push(
210+
path.join(stagingDir, 'keys', Templates.renderTLSPemPublicKeyFile(consensusNode.name as NodeAlias)),
211+
);
209212

210213
for (const srcFile of srcFiles) {
211214
const fileContents = fs.readFileSync(srcFile);
@@ -214,14 +217,16 @@ export class PlatformInstaller {
214217
data[fileName] = Base64.encode(fileContents);
215218
}
216219
}
217-
// TODO: @Lenin, will need to run for each cluster
218-
const secretCreated = await this.k8Factory
219-
.default()
220-
.secrets()
221-
.createOrReplace(this._getNamespace(), 'network-node-hapi-app-secrets', SecretType.OPAQUE, data, undefined);
222220

223-
if (!secretCreated) {
224-
throw new SoloError('failed to create secret for TLS keys');
221+
for (const context of contexts) {
222+
const secretCreated = await this.k8Factory
223+
.getK8(context)
224+
.secrets()
225+
.createOrReplace(this._getNamespace(), 'network-node-hapi-app-secrets', SecretType.OPAQUE, data, undefined);
226+
227+
if (!secretCreated) {
228+
throw new SoloError('failed to create secret for TLS keys');
229+
}
225230
}
226231
} catch (e: Error | any) {
227232
this.logger.error('failed to copy TLS keys to secret', e);
@@ -324,25 +329,26 @@ export class PlatformInstaller {
324329
* <li>${staging}/keys/hedera-<nodeAlias>.crt: gRPC TLS cert for a node</li>
325330
*
326331
* @param stagingDir staging directory path
327-
* @param nodeAliases list of node ids
332+
* @param consensusNodes list of consensus nodes
333+
* @param contexts list of k8s contexts
328334
*/
329-
copyNodeKeys(stagingDir: string, nodeAliases: NodeAliases) {
335+
copyNodeKeys(stagingDir: string, consensusNodes: ConsensusNode[], contexts: string[]) {
330336
const self = this;
331337
const subTasks = [];
332338
subTasks.push({
333339
title: 'Copy TLS keys',
334-
task: async () => await self.copyTLSKeys(nodeAliases, stagingDir),
340+
task: async () => await self.copyTLSKeys(consensusNodes, stagingDir, contexts),
335341
});
336342

337-
for (const nodeAlias of nodeAliases) {
343+
for (const consensusNode of consensusNodes) {
338344
subTasks.push({
339-
title: `Node: ${chalk.yellow(nodeAlias)}`,
345+
title: `Node: ${chalk.yellow(consensusNode.name)}, cluster: ${chalk.yellow(consensusNode.context)}`,
340346
task: () =>
341347
new Listr(
342348
[
343349
{
344350
title: 'Copy Gossip keys',
345-
task: async () => await self.copyGossipKeys(nodeAlias, stagingDir, nodeAliases),
351+
task: async () => await self.copyGossipKeys(consensusNode, stagingDir, consensusNodes),
346352
},
347353
],
348354
{

0 commit comments

Comments
 (0)