3
3
*/
4
4
5
5
import paths from 'path' ;
6
+ import path from 'path' ;
6
7
import { MissingArgumentError , SoloError } from '../core/errors.js' ;
7
8
import { ShellRunner } from '../core/shell_runner.js' ;
8
9
import { type LeaseManager } from '../core/lease/lease_manager.js' ;
@@ -17,11 +18,12 @@ import {type Opts} from '../types/command_types.js';
17
18
import { type CommandFlag } from '../types/flag_types.js' ;
18
19
import { type Lease } from '../core/lease/lease.js' ;
19
20
import { Listr } from 'listr2' ;
20
- import path from 'path' ;
21
21
import * as constants from '../core/constants.js' ;
22
22
import fs from 'fs' ;
23
23
import { Task } from '../core/task.js' ;
24
24
import { ConsensusNode } from '../core/model/consensus_node.js' ;
25
+ import { type ClusterRef , type ClusterRefs } from '../core/config/remote/types.js' ;
26
+ import { Flags } from './flags.js' ;
25
27
26
28
export interface CommandHandlers {
27
29
parent : BaseCommand ;
@@ -72,6 +74,7 @@ export abstract class BaseCommand extends ShellRunner {
72
74
return `${ chartRepo } /${ chartReleaseName } ` ;
73
75
}
74
76
77
+ // FIXME @Deprecated . Use prepareValuesFilesMap instead to support multi-cluster
75
78
public prepareValuesFiles ( valuesFile : string ) {
76
79
let valuesArg = '' ;
77
80
if ( valuesFile ) {
@@ -85,6 +88,80 @@ export abstract class BaseCommand extends ShellRunner {
85
88
return valuesArg ;
86
89
}
87
90
91
+ /**
92
+ * Prepare the values files map for each cluster
93
+ *
94
+ * <p> Order of precedence:
95
+ * <ol>
96
+ * <li> Chart's default values file (if chartDirectory is set) </li>
97
+ * <li> Profile values file </li>
98
+ * <li> User's values file </li>
99
+ * </ol>
100
+ * @param contextRefs - the map of cluster references
101
+ * @param valuesFileInput - the values file input string
102
+ * @param chartDirectory - the chart directory
103
+ * @param profileValuesFile - the profile values file
104
+ */
105
+ static prepareValuesFilesMap (
106
+ contextRefs : ClusterRefs ,
107
+ chartDirectory ?: string ,
108
+ profileValuesFile ?: string ,
109
+ valuesFileInput ?: string ,
110
+ ) : Record < ClusterRef , string > {
111
+ // initialize the map with an empty array for each cluster-ref
112
+ const valuesFiles : Record < ClusterRef , string > = { } ;
113
+ Object . entries ( contextRefs ) . forEach ( ( [ clusterRef ] ) => {
114
+ valuesFiles [ clusterRef ] = '' ;
115
+ } ) ;
116
+
117
+ // add the chart's default values file for each cluster-ref if chartDirectory is set
118
+ // this should be the first in the list of values files as it will be overridden by user's input
119
+ if ( chartDirectory ) {
120
+ const chartValuesFile = path . join ( chartDirectory , 'solo-deployment' , 'values.yaml' ) ;
121
+ for ( const clusterRef in valuesFiles ) {
122
+ valuesFiles [ clusterRef ] += ` --values ${ chartValuesFile } ` ;
123
+ }
124
+ }
125
+
126
+ if ( profileValuesFile ) {
127
+ const parsed = Flags . parseValuesFilesInput ( profileValuesFile ) ;
128
+ Object . entries ( parsed ) . forEach ( ( [ clusterRef , files ] ) => {
129
+ let vf = '' ;
130
+ files . forEach ( file => {
131
+ vf += ` --values ${ file } ` ;
132
+ } ) ;
133
+
134
+ if ( clusterRef === Flags . KEY_COMMON ) {
135
+ Object . entries ( valuesFiles ) . forEach ( ( [ cf ] ) => {
136
+ valuesFiles [ cf ] += vf ;
137
+ } ) ;
138
+ } else {
139
+ valuesFiles [ clusterRef ] += vf ;
140
+ }
141
+ } ) ;
142
+ }
143
+
144
+ if ( valuesFileInput ) {
145
+ const parsed = Flags . parseValuesFilesInput ( valuesFileInput ) ;
146
+ Object . entries ( parsed ) . forEach ( ( [ clusterRef , files ] ) => {
147
+ let vf = '' ;
148
+ files . forEach ( file => {
149
+ vf += ` --values ${ file } ` ;
150
+ } ) ;
151
+
152
+ if ( clusterRef === Flags . KEY_COMMON ) {
153
+ Object . entries ( valuesFiles ) . forEach ( ( [ clusterRef ] ) => {
154
+ valuesFiles [ clusterRef ] += vf ;
155
+ } ) ;
156
+ } else {
157
+ valuesFiles [ clusterRef ] += vf ;
158
+ }
159
+ } ) ;
160
+ }
161
+
162
+ return valuesFiles ;
163
+ }
164
+
88
165
public getConfigManager ( ) : ConfigManager {
89
166
return this . configManager ;
90
167
}
@@ -104,6 +181,7 @@ export abstract class BaseCommand extends ShellRunner {
104
181
// build the dynamic class that will keep track of which properties are used
105
182
const NewConfigClass = class {
106
183
private usedConfigs : Map < string , number > ;
184
+
107
185
constructor ( ) {
108
186
// the map to keep track of which properties are used
109
187
this . usedConfigs = new Map ( ) ;
@@ -255,18 +333,20 @@ export abstract class BaseCommand extends ShellRunner {
255
333
const consensusNodes : ConsensusNode [ ] = [ ] ;
256
334
257
335
// using the remoteConfigManager to get the consensus nodes
258
- Object . values ( this . getRemoteConfigManager ( ) . components . consensusNodes ) . forEach ( node => {
259
- consensusNodes . push (
260
- new ConsensusNode (
261
- node . name ,
262
- node . nodeId ,
263
- node . namespace ,
264
- node . cluster ,
265
- // use local config to get the context
266
- this . getLocalConfig ( ) . clusterRefs [ node . cluster ] ,
267
- ) ,
268
- ) ;
269
- } ) ;
336
+ if ( this . getRemoteConfigManager ( ) ?. components ?. consensusNodes ) {
337
+ Object . values ( this . getRemoteConfigManager ( ) . components . consensusNodes ) . forEach ( node => {
338
+ consensusNodes . push (
339
+ new ConsensusNode (
340
+ node . name ,
341
+ node . nodeId ,
342
+ node . namespace ,
343
+ node . cluster ,
344
+ // use local config to get the context
345
+ this . getLocalConfig ( ) . clusterRefs [ node . cluster ] ,
346
+ ) ,
347
+ ) ;
348
+ } ) ;
349
+ }
270
350
271
351
// return the consensus nodes
272
352
return consensusNodes ;
0 commit comments