Skip to content

Commit 3bb0469

Browse files
MK8S-25: Add saltenv directory cleanup to parent RedHat ISO task
Modify _package_mkdir_redhat_iso_root task to include cleanup of the saltenv directory structure (metalk8s-{VERSION}) created by repository index files. This prevents cleanup failures in higher-level directory cleanup tasks that were unable to remove non-empty directories containing our index.html files. - Add config import to packaging.py - Add custom clean function to remove saltenv directory - Use coreutils.rm_rf for safe recursive removal This ensures complete cleanup allows e2e tests to run properly.
1 parent 7148dec commit 3bb0469

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

buildchain/buildchain/packaging.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import doit # type: ignore
3333

3434
from buildchain import builder
35+
from buildchain import config
3536
from buildchain import constants
3637
from buildchain import coreutils
3738
from buildchain import docker_command
@@ -45,7 +46,7 @@
4546

4647

4748
def _list_packages_to_build(
48-
pkg_cats: Mapping[str, Mapping[str, Tuple[targets.Package, ...]]]
49+
pkg_cats: Mapping[str, Mapping[str, Tuple[targets.Package, ...]]],
4950
) -> Dict[str, List[str]]:
5051
return {
5152
version: [pkg.name for pkg in pkg_list]
@@ -149,11 +150,27 @@ def task__package_mkdir_iso_root() -> types.TaskDict:
149150

150151
def task__package_mkdir_redhat_iso_root() -> types.TaskDict:
151152
"""Create the RedHat packages root directory on the ISO."""
152-
return targets.Mkdir(
153+
154+
def clean() -> None:
155+
"""Clean RedHat directory including saltenv directory structure."""
156+
# Remove saltenv directory structure created by repository index files
157+
saltenv_dir = (
158+
constants.REPO_REDHAT_ROOT
159+
/ f"{config.PROJECT_NAME.lower()}-{versions.VERSION}"
160+
)
161+
if saltenv_dir.exists():
162+
coreutils.rm_rf(saltenv_dir)
163+
164+
mkdir_task = targets.Mkdir(
153165
directory=constants.REPO_REDHAT_ROOT,
154166
task_dep=["_package_mkdir_iso_root"],
155167
).task
156168

169+
# Add our custom cleanup function
170+
mkdir_task["clean"] = [clean]
171+
172+
return mkdir_task
173+
157174

158175
def _package_mkdir_redhat_release_iso_root(releasever: str) -> types.TaskDict:
159176
"""
@@ -263,6 +280,7 @@ def task__build_redhat_8_repositories() -> Iterator[types.TaskDict]:
263280
# }}}
264281
# RPM packages and repository {{{
265282

283+
266284
# Packages to build, per repository.
267285
def _rpm_package(name: str, releasever: str, sources: List[Path]) -> targets.RPMPackage:
268286
try:
@@ -362,11 +380,11 @@ def _rpm_package_metalk8s_sosreport(releasever: str) -> targets.RPMPackage:
362380

363381

364382
# Store these versions in a dict to use with doit.tools.config_changed
365-
_TO_DOWNLOAD_RPM_CONFIG: Dict[
366-
str, Dict[str, Optional[str]]
367-
] = _list_packages_to_download(
368-
versions.REDHAT_PACKAGES,
369-
_RPM_TO_BUILD_PKG_NAMES,
383+
_TO_DOWNLOAD_RPM_CONFIG: Dict[str, Dict[str, Optional[str]]] = (
384+
_list_packages_to_download(
385+
versions.REDHAT_PACKAGES,
386+
_RPM_TO_BUILD_PKG_NAMES,
387+
)
370388
)
371389

372390

0 commit comments

Comments
 (0)