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,9 +74,7 @@ export abstract class BaseCommand extends ShellRunner {
72
74
return `${ chartRepo } /${ chartReleaseName } ` ;
73
75
}
74
76
75
- // TODO @Lenin , this is in the base so it will be used by everyone, which might be good because they won't have to duplicate the code
76
- // perhaps we should clone this method and have the new method return an object Record<ClusterRef, valuesFileArg>
77
- // need to support: --values-file aws-cluster=aws/solo-values.yaml,aws-cluster=aws/solo-values2.yaml,gcp-cluster=gcp/solo-values.yaml,gcp-cluster=gcp/solo-values2.yaml
77
+ // FIXME @Deprecated . Use prepareValuesFilesMap instead to support multi-cluster
78
78
public prepareValuesFiles ( valuesFile : string ) {
79
79
let valuesArg = '' ;
80
80
if ( valuesFile ) {
@@ -88,6 +88,80 @@ export abstract class BaseCommand extends ShellRunner {
88
88
return valuesArg ;
89
89
}
90
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
+
91
165
public getConfigManager ( ) : ConfigManager {
92
166
return this . configManager ;
93
167
}
@@ -107,6 +181,7 @@ export abstract class BaseCommand extends ShellRunner {
107
181
// build the dynamic class that will keep track of which properties are used
108
182
const NewConfigClass = class {
109
183
private usedConfigs : Map < string , number > ;
184
+
110
185
constructor ( ) {
111
186
// the map to keep track of which properties are used
112
187
this . usedConfigs = new Map ( ) ;
0 commit comments