Skip to content

Commit

Permalink
add KME error if unexpected content is returned for helm chart
Browse files Browse the repository at this point in the history
  • Loading branch information
Imadzuma committed Oct 31, 2024
1 parent 809d979 commit 7d0a555
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 4 additions & 0 deletions kubemarine/core/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

Expand Down
15 changes: 11 additions & 4 deletions kubemarine/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7d0a555

Please sign in to comment.