From af35b908292bd8f6d1ec18bd979f9eaa73dda269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lipovsk=C3=BD?= Date: Wed, 31 Jul 2024 15:31:59 +0200 Subject: [PATCH] Remove fbc opted in operators. FBC opted in operator caused opm to fail when removing it because operator was not present in database. If this occurs we try to remove operators once again but we enable permissive mode which silents errors when operator is not present. [CLOUDDST-23683] --- iib/workers/tasks/opm_operations.py | 20 ++++++++++++++++++-- iib/workers/tasks/utils.py | 5 +++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/iib/workers/tasks/opm_operations.py b/iib/workers/tasks/opm_operations.py index 9ea4697a..688e9f88 100644 --- a/iib/workers/tasks/opm_operations.py +++ b/iib/workers/tasks/opm_operations.py @@ -932,13 +932,17 @@ def opm_registry_add_fbc( ) -def _opm_registry_rm(index_db_path: str, operators: List[str], base_dir: str) -> None: +def _opm_registry_rm( + index_db_path: str, operators: List[str], base_dir: str, permissive: bool = False +) -> None: """ Generate and run the opm command to remove operator package from index db provided. :param str index_db_path: path where the input index image is temporarily copied :param list operators: list of operator packages to be removed :param base_dir: the base directory to generate the database and index.Dockerfile in. + :param permissive: enables permissive mode for opm registry rm + WARNING: Do not enable permissive mode outside create-emtpy-index API. """ from iib.workers.tasks.utils import run_cmd @@ -951,6 +955,9 @@ def _opm_registry_rm(index_db_path: str, operators: List[str], base_dir: str) -> '--packages', ','.join(operators), ] + if permissive: + cmd.append('--permissive') + run_cmd(cmd, {'cwd': base_dir}, exc_msg='Failed to remove operators from the index image') @@ -1034,7 +1041,16 @@ def opm_create_empty_fbc( # Remove all the operators from the index set_request_state(request_id, 'in_progress', 'Removing operators from index image') - _opm_registry_rm(index_db_path=index_db_path, operators=operators, base_dir=temp_dir) + try: + _opm_registry_rm(index_db_path=index_db_path, operators=operators, base_dir=temp_dir) + except IIBError as e: + if 'Error deleting packages from database' in str(e): + log.info('Enable permissive mode for opm registry rm', from_index) + _opm_registry_rm( + index_db_path=index_db_path, operators=operators, base_dir=temp_dir, permissive=True + ) + else: + raise e # Migrate the index to FBC fbc_dir, _ = opm_migrate(index_db=index_db_path, base_dir=temp_dir) diff --git a/iib/workers/tasks/utils.py b/iib/workers/tasks/utils.py index 35a10791..121fd36f 100644 --- a/iib/workers/tasks/utils.py +++ b/iib/workers/tasks/utils.py @@ -764,6 +764,11 @@ def run_cmd( match = _regex_reverse_search(regex, response) if match: raise IIBError(f'{exc_msg.rstrip(".")}: {match.groups()[0]}') + elif ( + '"permissive mode disabled" error="error deleting packages from' + ' database: error removing operator package' in response.stderr + ): + raise IIBError("Error deleting packages from database") elif cmd[0] == 'buildah': # Check for HTTP 50X errors on buildah network_regexes = [