@@ -20,9 +20,8 @@ import { FullstackTestingError, IllegalArgumentError, MissingArgumentError } fro
20
20
import * as yaml from 'js-yaml'
21
21
import { flags } from '../commands/index.mjs'
22
22
import { constants , helpers } from './index.mjs'
23
+ import dot from 'dot-object'
23
24
24
- const resourceRequestTypes = [ 'requests' , 'limits' ]
25
- const hardwareTypes = [ 'cpu' , 'memory' ]
26
25
const consensusSidecars = [
27
26
'recordStreamUploader' , 'eventStreamUploader' , 'backupUploader' , 'accountBalanceUploader' , 'otelCollector' ]
28
27
@@ -126,27 +125,22 @@ export class ProfileManager {
126
125
}
127
126
128
127
/**
129
- * Set resources for the chart
130
- * @param itemPath item path in the yaml
131
- * @param itemResources item resources object
132
- * @param yamlRoot root of the yaml object
128
+ * Set items for the chart
129
+ * @param itemPath item path in the yaml, if empty then root of the yaml object will be used
130
+ * @param items the element object
131
+ * @param yamlRoot root of the yaml object to update
133
132
* @private
134
133
*/
135
- _setChartResources ( itemPath , itemResources , yamlRoot ) {
136
- if ( ! itemResources || ! itemResources . resources ) return
137
-
138
- for ( const resourceRequestType of resourceRequestTypes ) {
139
- if ( itemResources && itemResources . resources [ resourceRequestType ] ) {
140
- const resources = itemResources . resources [ resourceRequestType ]
141
- for ( const hardware of hardwareTypes ) {
142
- if ( resources [ hardware ] !== undefined ) {
143
- if ( itemPath ) {
144
- this . _setValue ( `${ itemPath } .resources.${ resourceRequestType } .${ hardware } ` , resources [ hardware ] , yamlRoot )
145
- } else {
146
- this . _setValue ( `resources.${ resourceRequestType } .${ hardware } ` , resources [ hardware ] , yamlRoot )
147
- }
148
- }
149
- }
134
+ _setChartItems ( itemPath , items , yamlRoot ) {
135
+ if ( ! items ) return
136
+
137
+ const dotItems = dot . dot ( items )
138
+
139
+ for ( const key in dotItems ) {
140
+ if ( itemPath ) {
141
+ this . _setValue ( `${ itemPath } .${ key } ` , dotItems [ key ] , yamlRoot )
142
+ } else {
143
+ this . _setValue ( key , dotItems [ key ] , yamlRoot )
150
144
}
151
145
}
152
146
}
@@ -163,16 +157,16 @@ export class ProfileManager {
163
157
for ( let nodeIndex = 0 ; nodeIndex < nodeIds . length ; nodeIndex ++ ) {
164
158
this . _setValue ( `hedera.nodes.${ nodeIndex } .name` , nodeIds [ nodeIndex ] , yamlRoot )
165
159
this . _setValue ( `hedera.nodes.${ nodeIndex } .accountId` , `${ realm } .${ shard } .${ accountId ++ } ` , yamlRoot )
166
- this . _setChartResources ( `hedera.nodes.${ nodeIndex } ` , profile . consensus , yamlRoot )
160
+ this . _setChartItems ( `hedera.nodes.${ nodeIndex } ` , profile . consensus , yamlRoot )
167
161
}
168
162
169
163
if ( profile . consensus ) {
170
164
// set default for consensus pod
171
- this . _setChartResources ( 'defaults.root' , profile . consensus . root , yamlRoot )
165
+ this . _setChartItems ( 'defaults.root' , profile . consensus . root , yamlRoot )
172
166
173
167
// set sidecar resources
174
168
for ( const sidecar of consensusSidecars ) {
175
- this . _setChartResources ( `defaults.sidecars.${ sidecar } ` , profile . consensus [ sidecar ] , yamlRoot )
169
+ this . _setChartItems ( `defaults.sidecars.${ sidecar } ` , profile . consensus [ sidecar ] , yamlRoot )
176
170
}
177
171
}
178
172
@@ -183,19 +177,19 @@ export class ProfileManager {
183
177
if ( ! profile ) throw new MissingArgumentError ( 'profile is required' )
184
178
if ( ! profile . haproxy ) return // use chart defaults
185
179
186
- return this . _setChartResources ( 'defaults.haproxy' , profile . haproxy , yamlRoot )
180
+ return this . _setChartItems ( 'defaults.haproxy' , profile . haproxy , yamlRoot )
187
181
}
188
182
189
183
resourcesForEnvoyProxyPod ( profile , yamlRoot ) {
190
184
if ( ! profile ) throw new MissingArgumentError ( 'profile is required' )
191
185
if ( ! profile . envoyProxy ) return // use chart defaults
192
- return this . _setChartResources ( 'defaults.envoyProxy' , profile . envoyProxy , yamlRoot )
186
+ return this . _setChartItems ( 'defaults.envoyProxy' , profile . envoyProxy , yamlRoot )
193
187
}
194
188
195
189
resourcesForHederaExplorerPod ( profile , yamlRoot ) {
196
190
if ( ! profile ) throw new MissingArgumentError ( 'profile is required' )
197
191
if ( ! profile . explorer ) return
198
- return this . _setChartResources ( 'hedera-explorer' , profile . explorer , yamlRoot )
192
+ return this . _setChartItems ( 'hedera-explorer' , profile . explorer , yamlRoot )
199
193
}
200
194
201
195
resourcesForMinioTenantPod ( profile , yamlRoot ) {
@@ -210,7 +204,7 @@ export class ProfileManager {
210
204
}
211
205
}
212
206
213
- this . _setChartResources ( `minio-server.tenant.pools.${ poolIndex } ` , pool , yamlRoot )
207
+ this . _setChartItems ( `minio-server.tenant.pools.${ poolIndex } ` , pool , yamlRoot )
214
208
}
215
209
216
210
return yamlRoot
@@ -260,7 +254,7 @@ export class ProfileManager {
260
254
261
255
// generate the yaml
262
256
const yamlRoot = { }
263
- this . _setChartResources ( '' , profile . rpcRelay , yamlRoot )
257
+ this . _setChartItems ( '' , profile . rpcRelay , yamlRoot )
264
258
265
259
// write the yaml
266
260
const cachedValuesFile = path . join ( this . cacheDir , `rpcRelay-${ profileName } .yaml` )
@@ -292,14 +286,14 @@ export class ProfileManager {
292
286
this . _setValue ( 'hedera-mirror-node.postgresql.persistence.size' , profile . mirror . postgresql . persistence . size , yamlRoot )
293
287
}
294
288
295
- this . _setChartResources ( 'hedera-mirror-node.postgresql.postgresql' , profile . mirror . postgresql . postgresql , yamlRoot )
289
+ this . _setChartItems ( 'hedera-mirror-node.postgresql.postgresql' , profile . mirror . postgresql . postgresql , yamlRoot )
296
290
}
297
291
298
- this . _setChartResources ( 'hedera-mirror-node.importer' , profile . mirror . importer , yamlRoot )
299
- this . _setChartResources ( 'hedera-mirror-node.rest' , profile . mirror . rest , yamlRoot )
300
- this . _setChartResources ( 'hedera-mirror-node.web3' , profile . mirror . web3 , yamlRoot )
301
- this . _setChartResources ( 'hedera-mirror-node.grpc' , profile . mirror . grpc , yamlRoot )
302
- this . _setChartResources ( 'hedera-mirror-node.monitor' , profile . mirror . monitor , yamlRoot )
292
+ this . _setChartItems ( 'hedera-mirror-node.importer' , profile . mirror . importer , yamlRoot )
293
+ this . _setChartItems ( 'hedera-mirror-node.rest' , profile . mirror . rest , yamlRoot )
294
+ this . _setChartItems ( 'hedera-mirror-node.web3' , profile . mirror . web3 , yamlRoot )
295
+ this . _setChartItems ( 'hedera-mirror-node.grpc' , profile . mirror . grpc , yamlRoot )
296
+ this . _setChartItems ( 'hedera-mirror-node.monitor' , profile . mirror . monitor , yamlRoot )
303
297
this . resourcesForHederaExplorerPod ( profile , yamlRoot )
304
298
305
299
// write the yaml
0 commit comments