@@ -14,16 +14,17 @@ import * as Base64 from 'js-base64';
14
14
import chalk from 'chalk' ;
15
15
16
16
import { type SoloLogger } from './logging.js' ;
17
- import { type NodeAlias , type NodeAliases } from '../types/aliases.js' ;
17
+ import { type NodeAlias } from '../types/aliases.js' ;
18
18
import { Duration } from './time/duration.js' ;
19
19
import { sleep } from './helpers.js' ;
20
20
import { inject , injectable } from 'tsyringe-neo' ;
21
21
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' ;
23
23
import { type PodRef } from './kube/resources/pod/pod_ref.js' ;
24
24
import { ContainerRef } from './kube/resources/container/container_ref.js' ;
25
25
import { SecretType } from './kube/resources/secret/secret_type.js' ;
26
26
import { InjectTokens } from './dependency_injection/inject_tokens.js' ;
27
+ import { type ConsensusNode } from './model/consensus_node.js' ;
27
28
28
29
/** PlatformInstaller install platform code in the root-container of a network pod */
29
30
@injectable ( )
@@ -144,20 +145,24 @@ export class PlatformInstaller {
144
145
}
145
146
}
146
147
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' ) ;
149
150
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' ) ;
151
152
152
153
try {
153
154
const srcFiles = [ ] ;
154
155
155
156
// 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
+ ) ;
157
160
158
161
// 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
+ ) ;
161
166
} ) ;
162
167
163
168
const data = { } ;
@@ -168,44 +173,42 @@ export class PlatformInstaller {
168
173
data [ fileName ] = Base64 . encode ( fileContents ) ;
169
174
}
170
175
171
- // TODO: @Lenin , will need to run for each cluster
172
176
const secretCreated = await this . k8Factory
173
- . default ( )
177
+ . getK8 ( consensusNode . context )
174
178
. secrets ( )
175
179
. createOrReplace (
176
- this . _getNamespace ( ) ,
177
- Templates . renderGossipKeySecretName ( nodeAlias ) ,
180
+ NamespaceName . of ( consensusNode . namespace ) ,
181
+ Templates . renderGossipKeySecretName ( consensusNode . name as NodeAlias ) ,
178
182
SecretType . OPAQUE ,
179
183
data ,
180
- Templates . renderGossipKeySecretLabelObject ( nodeAlias ) ,
184
+ Templates . renderGossipKeySecretLabelObject ( consensusNode . name as NodeAlias ) ,
181
185
) ;
182
186
183
187
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 } '` ) ;
185
189
}
186
190
} 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 ) ;
195
194
}
196
195
}
197
196
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' ) ;
200
199
if ( ! stagingDir ) throw new MissingArgumentError ( 'stagingDir is required' ) ;
201
200
202
201
try {
203
202
const data = { } ;
204
203
205
- for ( const nodeAlias of nodeAliases ) {
204
+ for ( const consensusNode of consensusNodes ) {
206
205
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
+ ) ;
209
212
210
213
for ( const srcFile of srcFiles ) {
211
214
const fileContents = fs . readFileSync ( srcFile ) ;
@@ -214,14 +217,16 @@ export class PlatformInstaller {
214
217
data [ fileName ] = Base64 . encode ( fileContents ) ;
215
218
}
216
219
}
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 ) ;
222
220
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
+ }
225
230
}
226
231
} catch ( e : Error | any ) {
227
232
this . logger . error ( 'failed to copy TLS keys to secret' , e ) ;
@@ -324,25 +329,26 @@ export class PlatformInstaller {
324
329
* <li>${staging}/keys/hedera-<nodeAlias>.crt: gRPC TLS cert for a node</li>
325
330
*
326
331
* @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
328
334
*/
329
- copyNodeKeys ( stagingDir : string , nodeAliases : NodeAliases ) {
335
+ copyNodeKeys ( stagingDir : string , consensusNodes : ConsensusNode [ ] , contexts : string [ ] ) {
330
336
const self = this ;
331
337
const subTasks = [ ] ;
332
338
subTasks . push ( {
333
339
title : 'Copy TLS keys' ,
334
- task : async ( ) => await self . copyTLSKeys ( nodeAliases , stagingDir ) ,
340
+ task : async ( ) => await self . copyTLSKeys ( consensusNodes , stagingDir , contexts ) ,
335
341
} ) ;
336
342
337
- for ( const nodeAlias of nodeAliases ) {
343
+ for ( const consensusNode of consensusNodes ) {
338
344
subTasks . push ( {
339
- title : `Node: ${ chalk . yellow ( nodeAlias ) } ` ,
345
+ title : `Node: ${ chalk . yellow ( consensusNode . name ) } , cluster: ${ chalk . yellow ( consensusNode . context ) } ` ,
340
346
task : ( ) =>
341
347
new Listr (
342
348
[
343
349
{
344
350
title : 'Copy Gossip keys' ,
345
- task : async ( ) => await self . copyGossipKeys ( nodeAlias , stagingDir , nodeAliases ) ,
351
+ task : async ( ) => await self . copyGossipKeys ( consensusNode , stagingDir , consensusNodes ) ,
346
352
} ,
347
353
] ,
348
354
{
0 commit comments