From 7d0a555e7a2cb0d0182dd7f36cba580389102894 Mon Sep 17 00:00:00 2001 From: Imadzuma Date: Thu, 31 Oct 2024 08:21:23 +0300 Subject: [PATCH] add KME error if unexpected content is returned for helm chart --- kubemarine/core/errors.py | 4 ++++ kubemarine/plugins/__init__.py | 15 +++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/kubemarine/core/errors.py b/kubemarine/core/errors.py index b720d1c07..13c803597 100644 --- a/kubemarine/core/errors.py +++ b/kubemarine/core/errors.py @@ -89,6 +89,10 @@ def get_kme_dictionary() -> dict: "in cluster.yaml{previous_version_spec}, " "but not present in procedure inventory{next_version_spec}. " "Please, specify required 'sandbox_image' explicitly in procedure inventory." + }, + 'KME0014': { + "name": "Provided helm chart url {url} returns not a {type} content. Please check, that is returned in " + "{destination} file" } } diff --git a/kubemarine/plugins/__init__.py b/kubemarine/plugins/__init__.py index 3582cc7ee..3b68c4696 100755 --- a/kubemarine/plugins/__init__.py +++ b/kubemarine/plugins/__init__.py @@ -36,6 +36,7 @@ from kubemarine.core.cluster import KubernetesCluster, EnrichmentStage, enrichment from kubemarine import jinja, thirdparties from kubemarine.core import utils, static, errors, os as kos, log +from kubemarine.core.errors import FailException, KME from kubemarine.core.yaml_merger import default_merger from kubemarine.core.group import NodeGroup from kubemarine.kubernetes.daemonset import DaemonSet @@ -916,12 +917,18 @@ def get_local_chart_path(logger: log.EnhancedLogger, config: dict) -> str: extension = destination.split('.')[-1] if extension == 'zip': logger.verbose('Unzip will be used for unpacking') - with zipfile.ZipFile(destination, 'r') as zf: - zf.extractall(local_chart_folder) + try: + with zipfile.ZipFile(destination, 'r') as zf: + zf.extractall(local_chart_folder) + except zipfile.BadZipFile: + raise KME(code="KME0014", url=chart_path, type=extension, destination=destination) else: logger.verbose('Tar will be used for unpacking') - with tarfile.open(destination, "r:gz") as tf: - tf.extractall(local_chart_folder) + try: + with tarfile.open(destination, "r:gz") as tf: + tf.extractall(local_chart_folder) + except tarfile.ReadError: + raise KME(code="KME0014", url=chart_path, type="tar:gz", destination=destination) else: logger.debug("Create copy of chart to work with") shutil.copytree(chart_path, local_chart_folder, dirs_exist_ok=True)