feat: parallelize bundle/image processing in prepare-restricted-environment.sh#3137
Conversation
…nvironment.sh Parallelize all network-bound operations in the script for an estimated ~8x speedup in disconnected environment workflows: - Add MAX_PARALLEL variable (default 10) with --max-parallel CLI flag - Add reusable throttle_parallel() and wait_for_pids() helper functions - Parallelize process_bundles() with per-worker sed files for race-free render.yaml updates and inner parallel image mirroring - Parallelize process_bundles_from_dir() with same pattern, converting find|while-read to mapfile-based iteration for PID tracking - Parallelize mirror_extra_images() and mirror_extra_images_from_dir() with pre-created namespaces to avoid TOCTOU races - Parallelize ocp_prepare_internal_registry() namespace/policy/secret setup - Add top-level fork-join so extra image mirroring runs concurrently with bundle processing - Update traps to clean up background jobs on exit/signal Setting MAX_PARALLEL=1 restores fully sequential behavior for debugging. Ref: RHDHBUGS-3432 Signed-off-by: Fortune-Ndlovu <fndlovu@redhat.com>
Remove unused CATALOG_PULL_SECRET variable (SC2034) and replace useless echo wrapping oc command output in buildRegistryUrl (SC2005). Ref: RHDHBUGS-3432 Signed-off-by: Fortune-Ndlovu <fndlovu@redhat.com>
|
/agentic_review |
Code Review by Qodo
Context used✅ Compliance rules (platform):
18 rules 1.
|
…in prepare-restricted-environment.sh - Introduced semaphore functions (sem_init, sem_acquire, sem_release) to manage parallel execution. - Removed the throttle_parallel function and its usages, enhancing clarity and control over concurrent processes. - Updated traps to ensure proper cleanup of background jobs and temporary directories. - Adjusted image mirroring and processing functions to utilize the new semaphore mechanism for improved synchronization. Ref: RHDHBUGS-3432 Signed-off-by: Fortune-Ndlovu <fndlovu@redhat.com>
|
/agentic_review |
…ng in prepare-restricted-environment.sh - Introduced caching for registry URLs to optimize repeated calls. - Replaced direct calls to buildRegistryUrl with cached values in image processing functions. - Added a new helper function _last_two to simplify extraction of last two path elements. - Updated various functions to utilize the new caching mechanism, improving performance and readability. Ref: RHDHBUGS-3432 Signed-off-by: Fortune-Ndlovu <fndlovu@redhat.com>
|
/agentic_review |
…environment.sh - Enhanced the documentation for the --max-parallel option to clarify its impact on disk usage and recommend lowering the value when disk space is limited. Ref: RHDHBUGS-3432 Signed-off-by: Fortune-Ndlovu <fndlovu@redhat.com>
|
/agentic_review |
…environment.sh - Added a retry mechanism for the push_image_from_archive function to handle transient failures during image pushing. - Introduced a locking mechanism to prevent duplicate pushes for the same destination image. - Enhanced error handling with exponential backoff for retries. Ref: RHDHBUGS-3432 Signed-off-by: Fortune-Ndlovu <fndlovu@redhat.com>
|
|
/agentic_review |




This PR significantly improves the execution speed of
prepare-restricted-environment.shby parallelizing bundle and image processing operations that were previously sequential. The core changes introduce a FIFO-based global semaphore (sem_init/sem_acquire/sem_release) that enforcesMAX_PARALLELas a true global cap across all concurrent image operations, replacing the previous per-level PID-counting approach that could allow up toMAX_PARALLEL²simultaneous operations.Bundle processing (
process_single_bundle,process_single_bundle_from_dir) and image mirroring now run concurrently with proper backpressure, while registry URL lookups (buildRegistryUrl) are cached at startup to eliminate hundreds of redundant subshell forks and potentialocAPI calls in hot loops.Additional performance wins come from inlining
replaceInternalRegIfNeededandextract_last_two_elementsin hot paths via a fork-free nameref helper (_last_two), removing ~400+ unnecessaryfork()/exec()cycles per run.The PR also fixes several correctness issues: quoting
$TMPDIRin EXIT traps to handle paths with spaces, guarding trap cleanup commands with|| trueto prevent failures under set -euo pipefail, and correcting a tag-loss bug inmirror_extra_images_from_dirwhere${extraImg%:*}was stripping the tag from targetImg instead of preserving it.Which issue(s) does this PR fix or relate to
Resolves: https://redhat.atlassian.net/browse/RHDHBUGS-3432
PR acceptance criteria
How to test changes / Special notes to the reviewer
Signed-off-by: Fortune-Ndlovu fndlovu@redhat.com
Assisted-by: Claude (claude-opus-4-6)