Preserve quotes in building helm charts

RoundTripLoader in ruamel.yaml will omit quotation marks. In some
cases, the result by loading a yaml with RoundTripLoader and
dumping it out will be unreadable by PYYAML. For example, the
pattern:
  hosts: ["mon-logstash:port"]
will be transformed to:
  hosts: [mon-logstash:port]
Currently, the Armada project is using PYYAML. It's better to keep
the  quotes to allow the following process have to use PYYAML.

Tested with rebuild the helm chart with the yaml has the pattern
in the example, and the quotation marks are preserved.

Change-Id: I7375a1ad498336baa337cca5af8f90028b753110
Partial-Bug: 1896530
Signed-off-by: Yuxing Jiang <yuxing.jiang@windriver.com>
This commit is contained in:
Yuxing Jiang 2020-09-26 09:53:34 -04:00
parent e5f5b25e95
commit e9fbe29f11
2 changed files with 3 additions and 2 deletions

View File

@ -315,7 +315,7 @@ def merge_yaml(yaml_merged, yaml_new):
yaml_out = collections.OrderedDict()
for yaml_file in yaml_files:
print 'Merging yaml from file: %s' % yaml_file
for document in yaml.load_all(open(yaml_file), Loader=yaml.RoundTripLoader):
for document in yaml.load_all(open(yaml_file), Loader=yaml.RoundTripLoader, preserve_quotes=True):
document_name = (document['schema'], document['metadata']['schema'], document['metadata']['name'])
if document_name in yaml_out:
merge_yaml(yaml_out[document_name], document)

View File

@ -159,7 +159,8 @@ def main(argv):
new_image_dict[name] = image
# Load chart into dictionary(s) and then modify any image locations/tags if required
for document in yaml.load_all(open(yaml_file), Loader=yaml.RoundTripLoader):
for document in yaml.load_all(
open(yaml_file), Loader=yaml.RoundTripLoader, preserve_quotes=True):
document_name = (document['schema'],
document['metadata']['schema'],
document['metadata']['name'])