Skip to content

Commit 502aba0

Browse files
committed
enhance to use secret mounts
Signed-off-by: Jeromy Cannon <[email protected]>
1 parent 7c9ef3f commit 502aba0

File tree

7 files changed

+166
-192
lines changed

7 files changed

+166
-192
lines changed

src/commands/network.mjs

Lines changed: 93 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,25 @@ import { Listr } from 'listr2'
2020
import { FullstackTestingError, IllegalArgumentError, MissingArgumentError } from '../core/errors.mjs'
2121
import { BaseCommand } from './base.mjs'
2222
import * as flags from './flags.mjs'
23-
import { constants } from '../core/index.mjs'
23+
import { constants, Templates } from '../core/index.mjs'
2424
import * as prompts from './prompts.mjs'
2525
import * as helpers from '../core/helpers.mjs'
2626
import path from 'path'
27+
import { validatePath } from '../core/helpers.mjs'
28+
import fs from 'fs'
2729

2830
export class NetworkCommand extends BaseCommand {
2931
constructor (opts) {
3032
super(opts)
3133

34+
if (!opts || !opts.k8) throw new Error('An instance of core/K8 is required')
35+
if (!opts || !opts.keyManager) throw new IllegalArgumentError('An instance of core/KeyManager is required', opts.keyManager)
36+
if (!opts || !opts.platformInstaller) throw new IllegalArgumentError('An instance of core/PlatformInstaller is required', opts.platformInstaller)
3237
if (!opts || !opts.profileManager) throw new MissingArgumentError('An instance of core/ProfileManager is required', opts.downloader)
3338

39+
this.k8 = opts.k8
40+
this.keyManager = opts.keyManager
41+
this.platformInstaller = opts.platformInstaller
3442
this.profileManager = opts.profileManager
3543
}
3644

@@ -45,6 +53,7 @@ export class NetworkCommand extends BaseCommand {
4553
flags.applicationEnv,
4654
flags.applicationProperties,
4755
flags.bootstrapProperties,
56+
flags.cacheDir,
4857
flags.chainId,
4958
flags.chartDirectory,
5059
flags.deployHederaExplorer,
@@ -54,6 +63,7 @@ export class NetworkCommand extends BaseCommand {
5463
flags.fstChartVersion,
5564
flags.hederaExplorerTlsHostName,
5665
flags.hederaExplorerTlsLoadBalancerIp,
66+
flags.keyFormat,
5767
flags.log4j2Xml,
5868
flags.namespace,
5969
flags.nodeIDs,
@@ -143,10 +153,12 @@ export class NetworkCommand extends BaseCommand {
143153
flags.applicationEnv,
144154
flags.applicationProperties,
145155
flags.bootstrapProperties,
156+
flags.cacheDir,
146157
flags.chainId,
147158
flags.deployHederaExplorer,
148159
flags.deployMirrorNode,
149160
flags.hederaExplorerTlsLoadBalancerIp,
161+
flags.keyFormat,
150162
flags.log4j2Xml,
151163
flags.persistentVolumeClaims,
152164
flags.profileName,
@@ -160,6 +172,7 @@ export class NetworkCommand extends BaseCommand {
160172
* @typedef {Object} NetworkDeployConfigClass
161173
* -- flags --
162174
* @property {string} applicationEnv
175+
* @property {string} cacheDir
163176
* @property {string} chartDirectory
164177
* @property {boolean} deployHederaExplorer
165178
* @property {boolean} deployMirrorNode
@@ -168,6 +181,7 @@ export class NetworkCommand extends BaseCommand {
168181
* @property {string} fstChartVersion
169182
* @property {string} hederaExplorerTlsHostName
170183
* @property {string} hederaExplorerTlsLoadBalancerIp
184+
* @property {string} keyFormat
171185
* @property {string} namespace
172186
* @property {string} nodeIDs
173187
* @property {string} persistentVolumeClaims
@@ -176,8 +190,11 @@ export class NetworkCommand extends BaseCommand {
176190
* @property {string} releaseTag
177191
* @property {string} tlsClusterIssuerType
178192
* -- extra args --
179-
* @property {string[]} nodeIds
180193
* @property {string} chartPath
194+
* @property {string} keysDir
195+
* @property {string[]} nodeIds
196+
* @property {string} stagingDir
197+
* @property {string} stagingKeysDir
181198
* @property {string} valuesArg
182199
* -- methods --
183200
* @property {getUnusedConfigs} getUnusedConfigs
@@ -189,7 +206,14 @@ export class NetworkCommand extends BaseCommand {
189206

190207
// create a config object for subsequent steps
191208
const config = /** @type {NetworkDeployConfigClass} **/ this.getConfig(NetworkCommand.DEPLOY_CONFIGS_NAME, NetworkCommand.DEPLOY_FLAGS_LIST,
192-
['nodeIds', 'chartPath', 'valuesArg'])
209+
[
210+
'chartPath',
211+
'keysDir',
212+
'nodeIds',
213+
'stagingDir',
214+
'stagingKeysDir',
215+
'valuesArg'
216+
])
193217

194218
config.nodeIds = helpers.parseNodeIds(config.nodeIDs)
195219

@@ -199,6 +223,28 @@ export class NetworkCommand extends BaseCommand {
199223

200224
config.valuesArg = await this.prepareValuesArg(config)
201225

226+
// compute other config parameters
227+
config.keysDir = path.join(validatePath(config.cacheDir), 'keys')
228+
config.stagingDir = Templates.renderStagingDir(
229+
config.cacheDir,
230+
config.releaseTag
231+
)
232+
config.stagingKeysDir = path.join(validatePath(config.stagingDir), 'keys')
233+
234+
if (!await this.k8.hasNamespace(config.namespace)) {
235+
await this.k8.createNamespace(config.namespace)
236+
}
237+
238+
// prepare staging keys directory
239+
if (!fs.existsSync(config.stagingKeysDir)) {
240+
fs.mkdirSync(config.stagingKeysDir, { recursive: true })
241+
}
242+
243+
// create cached keys dir if it does not exist yet
244+
if (!fs.existsSync(config.keysDir)) {
245+
fs.mkdirSync(config.keysDir)
246+
}
247+
202248
this.logger.debug('Prepared config', {
203249
config,
204250
cachedConfig: this.configManager.config
@@ -221,7 +267,50 @@ export class NetworkCommand extends BaseCommand {
221267
ctx.config = /** @type {NetworkDeployConfigClass} **/ await self.prepareConfig(task, argv)
222268
}
223269
},
224-
// TODO create node keys and secrets
270+
{
271+
title: 'Prepare staging directory',
272+
task: async (ctx, parentTask) => {
273+
const subTasks = [
274+
{
275+
title: 'Copy Gossip keys to staging',
276+
task: async (ctx, _) => {
277+
const config = /** @type {NetworkDeployConfigClass} **/ ctx.config
278+
279+
await this.keyManager.copyGossipKeysToStaging(config.keyFormat, config.keysDir, config.stagingKeysDir, config.nodeIds)
280+
}
281+
},
282+
{
283+
title: 'Copy gRPC TLS keys to staging',
284+
task: async (ctx, _) => {
285+
const config = /** @type {NetworkDeployConfigClass} **/ ctx.config
286+
for (const nodeId of config.nodeIds) {
287+
const tlsKeyFiles = self.keyManager.prepareTLSKeyFilePaths(nodeId, config.keysDir)
288+
await self.keyManager.copyNodeKeysToStaging(tlsKeyFiles, config.stagingKeysDir)
289+
}
290+
}
291+
}
292+
]
293+
294+
return parentTask.newListr(subTasks, {
295+
concurrent: false,
296+
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION
297+
})
298+
}
299+
},
300+
{
301+
title: 'Copy node keys to secrets',
302+
task: async (ctx, parentTask) => {
303+
const config = /** @type {NetworkDeployConfigClass} **/ ctx.config
304+
305+
const subTasks = self.platformInstaller.copyNodeKeys(config.stagingDir, config.nodeIds, config.keyFormat)
306+
307+
// set up the sub-tasks
308+
return parentTask.newListr(subTasks, {
309+
concurrent: true,
310+
rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION
311+
})
312+
}
313+
},
225314
{
226315
title: `Install chart '${constants.FULLSTACK_DEPLOYMENT_CHART}'`,
227316
task: async (ctx, _) => {

0 commit comments

Comments
 (0)