@@ -232,10 +232,13 @@ func (o *CommonOptions) completeInventory(inventory *kkcorev1.Inventory) {
232
232
}
233
233
}
234
234
235
- // setValue set key: val in config.
236
- // If val is json string. convert to map or slice
237
- // If val is TRUE,YES,Y. convert to bool type true.
238
- // If val is FALSE,NO,N. convert to bool type false.
235
+ // setValue sets a value in the config based on a key-value pair.
236
+ // It supports different value types:
237
+ // - JSON objects (starting with '{' and ending with '}')
238
+ // - JSON arrays (starting with '[' and ending with ']')
239
+ // - Boolean values (true/false, yes/no, y/n - case insensitive)
240
+ // - String values (default case)
241
+ // The key can contain dots to indicate nested fields.
239
242
func setValue (config * kkcorev1.Config , key , val string ) error {
240
243
switch {
241
244
case strings .HasPrefix (val , "{" ) && strings .HasSuffix (val , "{" ):
@@ -245,7 +248,7 @@ func setValue(config *kkcorev1.Config, key, val string) error {
245
248
return errors .Wrapf (err , "failed to unmarshal json object value for \" --set %s\" " , key )
246
249
}
247
250
248
- return errors .Wrapf (unstructured .SetNestedMap (config .Value (), value , key ),
251
+ return errors .Wrapf (unstructured .SetNestedMap (config .Value (), value , strings . Split ( key , "." ) ... ),
249
252
"failed to set \" --set %s\" to config" , key )
250
253
case strings .HasPrefix (val , "[" ) && strings .HasSuffix (val , "]" ):
251
254
var value []any
@@ -254,16 +257,16 @@ func setValue(config *kkcorev1.Config, key, val string) error {
254
257
return errors .Wrapf (err , "failed to unmarshal json array value for \" --set %s\" " , key )
255
258
}
256
259
257
- return errors .Wrapf (unstructured .SetNestedSlice (config .Value (), value , key ),
260
+ return errors .Wrapf (unstructured .SetNestedSlice (config .Value (), value , strings . Split ( key , "." ) ... ),
258
261
"failed to set \" --set %s\" to config" , key )
259
262
case strings .EqualFold (val , "TRUE" ) || strings .EqualFold (val , "YES" ) || strings .EqualFold (val , "Y" ):
260
- return errors .Wrapf (unstructured .SetNestedField (config .Value (), true , key ),
263
+ return errors .Wrapf (unstructured .SetNestedField (config .Value (), true , strings . Split ( key , "." ) ... ),
261
264
"failed to set \" --set %s\" to config" , key )
262
265
case strings .EqualFold (val , "FALSE" ) || strings .EqualFold (val , "NO" ) || strings .EqualFold (val , "N" ):
263
- return errors .Wrapf (unstructured .SetNestedField (config .Value (), false , key ),
266
+ return errors .Wrapf (unstructured .SetNestedField (config .Value (), false , strings . Split ( key , "." ) ... ),
264
267
"failed to set \" --set %s\" to config" , key )
265
268
default :
266
- return errors .Wrapf (unstructured .SetNestedField (config .Value (), val , key ),
269
+ return errors .Wrapf (unstructured .SetNestedField (config .Value (), val , strings . Split ( key , "." ) ... ),
267
270
"failed to set \" --set %s\" to config" , key )
268
271
}
269
272
}
0 commit comments