Fix download of images provided via user overrides

This commit fixes a bug that was causing container images provided via
user overrides not to be downloaded when applying StarlingX
applications. The problem was caused by two issues:

  * The way the chart override filename was assembled in the image
    download method got outdated due to a previous commit [1]. The
    global namespace once present in the filename is not mandatory
    anymore as it represents the namespace of FluxCD resources and not
    necessarily the namespace of all underlying resources. In order to
    fix this the download method now uses a helper function, created on
    the same referenced commit, which aims to standardize how override
    filenames are assembled.
  * The implementation assumed that override files loaded using ruamel
    always have a "data:values" section, which is not the case for
    every supported app. This was causing the overrides parsing
    function to receive an empty dictionary, thus returning no images
    to override. That assumption was removed and the whole file is now
    being parsed given that image tags can be present in different
    subsections of the yaml file.

[1] https://review.opendev.org/c/starlingx/config/+/887430

Test plan:
PASS: build-pkgs -a && build-image
PASS: AIO-SX fresh install
PASS: Override vault-manager image using "system helm-override-update".
      Apply vault app.
      Confirm that sysinv attempted to download the image provided via
      user overrides.
PASS: Apply vault app.
      Confirm that default images were correctly downloaded.
PASS: Override ceph_config_helper image using
      "system helm-override-update".
      Apply platform-integ-apps.
      Confirm that sysinv attempted to download the image provided via
      user overrides.
PASS: Apply platform-integ-apps app.
      Confirm that default images were correctly downloaded.

Closes-bug: 2065699

Change-Id: I9cc6b8522aaf2624377814b2249e3c00da9ec424
Signed-off-by: Igor Soares <Igor.PiresSoares@windriver.com>
This commit is contained in:
Igor Soares 2024-05-09 16:58:47 -03:00
parent 69e075e250
commit e692da31a2
1 changed files with 5 additions and 8 deletions

View File

@ -616,7 +616,6 @@ class AppOperator(object):
# get namespace
with io.open(root_kustomization_path, 'r', encoding='utf-8') as f:
root_kustomization_yaml = next(yaml.safe_load_all(f))
global_namespace = AppOperator.get_global_namespace(root_kustomization_yaml)
charts_groups = root_kustomization_yaml["resources"]
for chart_group in charts_groups:
@ -627,9 +626,6 @@ class AppOperator(object):
if not os.path.isfile(chart_kustomization_path) or \
not os.path.isfile(helmrelease_path):
continue
with io.open(chart_kustomization_path, 'r', encoding='utf-8') as f:
chart_kustomization_yaml = next(yaml.safe_load_all(f))
chart_namespace = chart_kustomization_yaml.get("namespace", global_namespace)
with io.open(helmrelease_path, 'r', encoding='utf-8') as f:
helmrelease_yaml = next(yaml.safe_load_all(f))
chart_name = helmrelease_yaml["metadata"]["name"]
@ -640,15 +636,16 @@ class AppOperator(object):
helm_chart_imgs = images_file[chart_name]
# Get the image tags from the chart overrides file
overrides = chart_namespace + '-' + chart_name + '.yaml'
overrides = helm_utils.build_overrides_filename(chart_name)
app_overrides_file = os.path.join(overrides_dir, overrides)
overrides_file = {}
if os.path.exists(app_overrides_file):
with io.open(app_overrides_file, 'r', encoding='utf-8') as f:
overrides_file = yaml.safe_load(f)
else:
LOG.warn("Cannot find overrides file {}".format(app_overrides_file))
override_imgs = self._image.find_images_in_dict(
overrides_file.get('data', {}).get('values', {}))
override_imgs = self._image.find_images_in_dict(overrides_file)
override_imgs_copy = copy.deepcopy(override_imgs)
# Get the image tags from the fluxcd static overrides file
@ -1341,7 +1338,7 @@ class AppOperator(object):
def _write_fluxcd_overrides(self, charts, helm_files):
for chart in charts:
override_file = chart.name + '.yaml'
override_file = helm_utils.build_overrides_filename(chart.name)
for f in os.listdir(chart.chart_os_path):
if f.endswith("system-overrides.yaml"):