Skip to content

Commit ddbbd45

Browse files
committed
node-add: updated to set the secret prior to adding the node
Signed-off-by: Jeromy Cannon <[email protected]>
1 parent 9fee4db commit ddbbd45

File tree

2 files changed

+93
-32
lines changed

2 files changed

+93
-32
lines changed

src/commands/node.mjs

Lines changed: 52 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,6 +1623,58 @@ export class NodeCommand extends BaseCommand {
16231623
await this.freezeUpgradeNetworkNodes(config.freezeAdminPrivateKey, ctx.upgradeZipHash, config.nodeClient)
16241624
}
16251625
},
1626+
{
1627+
title: 'Prepare staging directory',
1628+
task: async (ctx, parentTask) => {
1629+
const subTasks = [
1630+
{
1631+
title: 'Copy Gossip keys to staging',
1632+
task: async (ctx, _) => {
1633+
const config = /** @type {NodeAddConfigClass} **/ ctx.config
1634+
1635+
await this.keyManager.copyGossipKeysToStaging(config.keyFormat, config.keysDir, config.stagingKeysDir, config.allNodeIds)
1636+
}
1637+
},
1638+
{
1639+
title: 'Copy gRPC TLS keys to staging',
1640+
task: async (ctx, _) => {
1641+
const config = /** @type {NodeAddConfigClass} **/ ctx.config
1642+
for (const nodeId of config.allNodeIds) {
1643+
const tlsKeyFiles = self.keyManager.prepareTLSKeyFilePaths(nodeId, config.keysDir)
1644+
await self.keyManager.copyNodeKeysToStaging(tlsKeyFiles, config.stagingKeysDir)
1645+
}
1646+
}
1647+
}
1648+
]
1649+
1650+
return parentTask.newListr(subTasks, {
1651+
concurrent: false,
1652+
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION
1653+
})
1654+
}
1655+
},
1656+
{
1657+
title: 'Copy node keys to secrets',
1658+
task: async (ctx, parentTask) => {
1659+
const config = /** @type {NodeAddConfigClass} **/ ctx.config
1660+
1661+
const subTasks = []
1662+
for (const nodeId of config.allNodeIds) {
1663+
const podName = config.podNames[nodeId]
1664+
subTasks.push({
1665+
title: `Node: ${chalk.yellow(nodeId)}`,
1666+
task: () =>
1667+
self.platformInstaller.copyNodeKeys(podName, config.stagingDir, config.allNodeIds, config.keyFormat)
1668+
})
1669+
}
1670+
1671+
// set up the sub-tasks
1672+
return parentTask.newListr(subTasks, {
1673+
concurrent: true,
1674+
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION
1675+
})
1676+
}
1677+
},
16261678
{
16271679
title: 'Check network nodes are frozen',
16281680
task: (ctx, task) => {
@@ -1669,7 +1721,6 @@ export class NodeCommand extends BaseCommand {
16691721
valuesArg += this.prepareValuesFiles(this.profileValuesFile)
16701722
}
16711723

1672-
// TODO: update the secrets with the new/updated key(s), platform installer: copyGossipKeys & copyTLSKeys
16731724
await self.chartManager.upgrade(
16741725
config.namespace,
16751726
constants.FULLSTACK_DEPLOYMENT_CHART,
@@ -1718,36 +1769,6 @@ export class NodeCommand extends BaseCommand {
17181769
})
17191770
}
17201771
},
1721-
{
1722-
title: 'Prepare staging directory',
1723-
task: async (ctx, parentTask) => {
1724-
const subTasks = [
1725-
{
1726-
title: 'Copy Gossip keys to staging',
1727-
task: async (ctx, _) => {
1728-
const config = /** @type {NodeAddConfigClass} **/ ctx.config
1729-
1730-
await this.keyManager.copyGossipKeysToStaging(config.keyFormat, config.keysDir, config.stagingKeysDir, config.allNodeIds)
1731-
}
1732-
},
1733-
{
1734-
title: 'Copy gRPC TLS keys to staging',
1735-
task: async (ctx, _) => {
1736-
const config = /** @type {NodeAddConfigClass} **/ ctx.config
1737-
for (const nodeId of config.allNodeIds) {
1738-
const tlsKeyFiles = self.keyManager.prepareTLSKeyFilePaths(nodeId, config.keysDir)
1739-
await self.keyManager.copyNodeKeysToStaging(tlsKeyFiles, config.stagingKeysDir)
1740-
}
1741-
}
1742-
}
1743-
]
1744-
1745-
return parentTask.newListr(subTasks, {
1746-
concurrent: false,
1747-
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION
1748-
})
1749-
}
1750-
},
17511772
{
17521773
title: 'Fetch platform software into all network nodes',
17531774
task:

src/core/platform_installer.mjs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export class PlatformInstaller {
139139
}
140140
}
141141

142-
// TODO: update to copy the keys to the k8s secrets
142+
// TODO: update to remove the copyTo the nodes
143143
async copyGossipKeys (podName, stagingDir, nodeIds, keyFormat = constants.KEY_FORMAT_PEM) {
144144
const self = this
145145

@@ -302,4 +302,44 @@ export class PlatformInstaller {
302302
}
303303
)
304304
}
305+
306+
/**
307+
* Return a list of task to copy the node keys to the staging directory
308+
*
309+
* It assumes the staging directory has the following files and resources:
310+
* ${staging}/keys/s-<nodeId>.key: signing key for a node
311+
* ${staging}/keys/s-<nodeId>.crt: signing cert for a node
312+
* ${staging}/keys/a-<nodeId>.key: agreement key for a node
313+
* ${staging}/keys/a-<nodeId>.crt: agreement cert for a node
314+
* ${staging}/keys/hedera-<nodeId>.key: gRPC TLS key for a node
315+
* ${staging}/keys/hedera-<nodeId>.crt: gRPC TLS cert for a node
316+
*
317+
* @param podName name of the pod
318+
* @param stagingDir staging directory path
319+
* @param nodeIds list of node ids
320+
* @param keyFormat key format (pfx or pem)
321+
* @returns {Listr<ListrContext, ListrPrimaryRendererValue, ListrSecondaryRendererValue>}
322+
*/
323+
copyNodeKeys (podName, stagingDir, nodeIds, keyFormat = constants.KEY_FORMAT_PEM) {
324+
const self = this
325+
return new Listr([
326+
{
327+
title: 'Copy Gossip keys',
328+
task: (_, task) =>
329+
self.copyGossipKeys(podName, stagingDir, nodeIds, keyFormat)
330+
},
331+
{
332+
title: 'Copy TLS keys',
333+
task: (_, task) =>
334+
self.copyTLSKeys(podName, stagingDir, keyFormat)
335+
}
336+
],
337+
{
338+
concurrent: false,
339+
rendererOptions: {
340+
collapseSubtasks: false
341+
}
342+
}
343+
)
344+
}
305345
}

0 commit comments

Comments
 (0)