Apply Helm Overrides to initially disabled charts.

The previous implementation of the _get_list_of_charts
method would not take into account whether or not a
particular application chart was enabled or disabled.

This change now only includes charts that are enabled, or
if the function caller asks for all of them with the
include_disabled override set.  The override is set as a
part of the perform_app_upload routine to ensure overrides
are generated and applied to all charts, including those
which are initially disabled.

This change also seeks to handle issues where the
kustomize-orig.yaml file is not created by the time the
perform_app_upload routine runs _get_list_of_charts by
including an extra check.

Finally, the override generation in the perform_app_apply
function is moved to happen first in the sequence of events
such that the app object is populated with overrides prior
to any other operations occuring.  This must be done to
ensure the correct chart list is used.

This fix ensures that:

1. When all charts are needed then an option can be specified
   (i.e. when determining all the container images needed for
   the application) This is done with include_disabled flag.
2. All possible charts, as filtered by the metadata/user
   driven and DB stored enabled status, are consistently
   returned regardless of the current state of the top-level
   application kustomization.yaml.
3. A final check for kustomization-orig.yaml is performed and
   the file is created, if missing, before
   _get_list_of_charts executes with include_disabled=True

Test Plan:
PASS: build-pkgs -a && build-image
PASS: AIO-SX full install with clean bootstrap
PASS: Enable the cms-replication chart on the dell-storage app
PASS: Use system helm-override-update to pass
      --set config.clusterID=ClusterA
PASS: system application-apply dell-storage
PASS: Check the YAML structure of the
      configmap/dell-replication-controller-config
      for ClusterA and properly formatted.
PASS: Additional check to ensure that stx-openstack application
      successfully uploads and applies.
PASS: Check that a helm override are generated even for an
      application that doesn't have a kustomize operator.  This
      was done for the metrics-server app.  A helm override was
      created and the subsequent metrics-server.yaml file in
      /opt/platform/helm contained the override after the
      system applciation-apply command was run.

Relates to previous attempt at a fix:
https://review.opendev.org/c/starlingx/config/+/890570

Closes-Bug: 2029303

Change-Id: I4c501b982e4061e5067ca0e8e43f37a9eecfcb68
Signed-off-by: Joshua Reed <joshua.reed@windriver.com>
This commit is contained in:
Joshua Reed 2024-04-09 14:11:59 -06:00
parent 7299fa6118
commit 967eedadb7
1 changed files with 51 additions and 25 deletions

View File

@ -731,7 +731,7 @@ class AppOperator(object):
# Extract the list of images from the charts and overrides where
# applicable. Save the list to the same location as the fluxcd manifest
# so it can be sync'ed.
app.charts = self._get_list_of_charts(app)
app.charts = self._get_list_of_charts(app, include_disabled=True)
self._plugins.activate_plugins(app)
LOG.info("Generating application overrides to discover required images.")
@ -1231,13 +1231,27 @@ class AppOperator(object):
else:
app_root_kustomize_file = constants.APP_ROOT_KUSTOMIZE_FILE
root_kustomization_path = os.path.join(
manifest, app_root_kustomize_file)
root_kustomization_path = \
os.path.join(manifest, app_root_kustomize_file)
# In the event include_disabed is set to True, make sure the file exists.
# Possible that the file has not yet been created yet.
if not os.path.exists(root_kustomization_path) and include_disabled:
LOG.info(
"_get_list_of_charts: Function called with include_disabled=True, "
"but the kustomize-orig.yaml file does not exist yet. Creating it "
"now."
)
original_root_kustomization_path = os.path.join(
manifest, constants.APP_ROOT_KUSTOMIZE_FILE
)
shutil.copy(original_root_kustomization_path, root_kustomization_path)
for f in (helmrepo_path, root_kustomization_path):
if not os.path.isfile(f):
raise exception.SysinvException(_(
"Mandatory FluxCD yaml file doesn't exist "
"%s" % helmrepo_path))
"%s" % f))
# get global namespace
with io.open(root_kustomization_path, 'r', encoding='utf-8') as f:
@ -1282,19 +1296,25 @@ class AppOperator(object):
# Dunno if we need to return these in order respecting dependsOn?
# dependencies = [dep["name"] for dep in helmrelease_yaml["spec"].
# get(["dependsOn"], [])]
chart_obj = FluxCDChart(
metadata_name=metadata_name,
name=metadata_name,
namespace=namespace,
location=location,
filesystem_location=filesystem_location,
release=release,
chart_os_path=chart_path,
chart_label=chart_name,
chart_version=chart_version,
helm_repo_name=helm_repo_name
)
charts.append(chart_obj)
if (include_disabled or
cutils.is_chart_enabled(self._dbapi,
app.name,
metadata_name,
namespace)):
chart_obj = FluxCDChart(
metadata_name=metadata_name,
name=metadata_name,
namespace=namespace,
location=location,
filesystem_location=filesystem_location,
release=release,
chart_os_path=chart_path,
chart_label=chart_name,
chart_version=chart_version,
helm_repo_name=helm_repo_name
)
LOG.info(f"_get_list_of_charts: Adding Chart: {chart_name}")
charts.append(chart_obj)
return charts
def _get_overrides_files(self, app):
@ -2650,6 +2670,18 @@ class AppOperator(object):
ready = True
try:
# Helm Applciation overrides must be generated first so that any
# helm overrides, such as enabling a chart will be added to the app
# object.
LOG.info("Generating application overrides...")
self._update_app_status(
app, new_progress=constants.APP_PROGRESS_GENERATE_OVERRIDES)
helm_files = self._helm.generate_helm_application_overrides(
app.sync_overrides_dir, app.name, mode, cnamespace=None,
chart_info=app.charts, combined=True)
app.charts = self._get_list_of_charts(app)
if AppOperator.is_app_aborted(app.name):
@ -2668,21 +2700,15 @@ class AppOperator(object):
lifecycle_hook_info_app_apply.lifecycle_type = constants.APP_LIFECYCLE_TYPE_RBD
self.app_lifecycle_actions(None, None, rpc_app, lifecycle_hook_info_app_apply)
self._update_app_status(
app, new_progress=constants.APP_PROGRESS_GENERATE_OVERRIDES)
if AppOperator.is_app_aborted(app.name):
raise exception.KubeAppAbort()
LOG.info("Generating application overrides...")
helm_files = self._helm.generate_helm_application_overrides(
app.sync_overrides_dir, app.name, mode, cnamespace=None,
chart_info=app.charts, combined=True)
if helm_files:
LOG.info("Application overrides generated.")
LOG.info("Writing fluxcd overrides...")
# put the helm_overrides in the chart's system-overrides.yaml
self._write_fluxcd_overrides(app.charts, helm_files)
LOG.info("Fluxcd overrides generated.")
self._update_app_status(
app, new_progress=constants.APP_PROGRESS_DOWNLOAD_IMAGES)