@@ -512,19 +512,33 @@ def build_images(prefix, images, tag=None, push=False, force_push=False, force_b
512
512
513
513
def _update_values_file_with_modifications (name , modifications ):
514
514
"""
515
- Update <name>/values.yaml file with a dictionary of modifications.
515
+ Update <name>/values.yaml file with a dictionary of modifications with its
516
+ root level keys representing a path within the values.yaml file.
517
+
518
+ Example of a modifications dictionary:
519
+
520
+ {
521
+ "server.image": {
522
+ "repository": "my-docker-org/server",
523
+ "tag": "v1.0.0",
524
+ },
525
+ "server.initContainers.0.image": {
526
+ "repository": "my-docker-org/server-init",
527
+ "tag": "v1.0.0",
528
+ }
529
+ }
516
530
"""
517
531
values_file = os .path .join (name , 'values.yaml' )
518
532
519
533
with open (values_file ) as f :
520
534
values = yaml .load (f )
521
535
522
- for key , value in modifications .items ():
523
- if not isinstance (value , dict ) or set (value .keys ()) != {'repository' , 'tag' }:
524
- raise ValueError (f"I only understand image updates with 'repository', 'tag', not: { value !r} " )
525
- parts = key . split ( '.' )
536
+ for path_key , path_value in modifications .items ():
537
+ if not isinstance (path_value , dict ) or set (path_value .keys ()) != {'repository' , 'tag' }:
538
+ raise ValueError (f"I only understand image updates with 'repository', 'tag', not: { path_value !r} " )
539
+
526
540
mod_obj = parent = values
527
- for p in parts :
541
+ for p in path_key . split ( '.' ) :
528
542
if p .isdigit ():
529
543
# integers are indices in lists
530
544
p = int (p )
@@ -537,32 +551,32 @@ def _update_values_file_with_modifications(name, modifications):
537
551
if keys :
538
552
for repo_key in keys :
539
553
before = mod_obj .get (repo_key , None )
540
- if before != value ['repository' ]:
541
- _log (f"Updating { values_file } : { key } .{ repo_key } : { value } " )
542
- mod_obj [repo_key ] = value ['repository' ]
554
+ if before != path_value ['repository' ]:
555
+ _log (f"Updating { values_file } : { path_key } .{ repo_key } : { path_value } " )
556
+ mod_obj [repo_key ] = path_value ['repository' ]
543
557
else :
544
558
possible_keys = ' or ' .join (IMAGE_REPOSITORY_KEYS )
545
559
raise KeyError (
546
- f'Could not find { possible_keys } in { values_file } :{ key } '
560
+ f'Could not find { possible_keys } in { values_file } :{ path_key } '
547
561
)
548
562
549
563
before = mod_obj .get ('tag' , None )
550
- if before != value ['tag' ]:
551
- _log (f"Updating { values_file } : { key } .tag: { value } " )
552
- mod_obj ['tag' ] = value ['tag' ]
564
+ if before != path_value ['tag' ]:
565
+ _log (f"Updating { values_file } : { path_key } .tag: { path_value } " )
566
+ mod_obj ['tag' ] = path_value ['tag' ]
553
567
elif isinstance (mod_obj , str ):
554
568
# scalar image string, not dict with separate repository, tag keys
555
- image = "{repository}:{tag}" .format (** value )
569
+ image = "{repository}:{tag}" .format (** path_value )
556
570
try :
557
571
before = parent [last_part ]
558
572
except (KeyError , IndexError ):
559
573
before = None
560
574
if before != image :
561
- _log (f"Updating { values_file } : { key } : { image } " )
575
+ _log (f"Updating { values_file } : { path_key } : { image } " )
562
576
parent [last_part ] = image
563
577
else :
564
578
raise TypeError (
565
- f'The key { key } in { values_file } must be a mapping or string, not { type (mod_obj )} .'
579
+ f'{ path_key } in { values_file } must be a mapping or string, not { type (mod_obj )} .'
566
580
)
567
581
568
582
with open (values_file , 'w' ) as f :
0 commit comments