Skip to content

Commit

Permalink
Remove fbc opted in operators.
Browse files Browse the repository at this point in the history
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]
  • Loading branch information
lipoja committed Aug 15, 2024
1 parent bf6a896 commit af35b90
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
20 changes: 18 additions & 2 deletions iib/workers/tasks/opm_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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')


Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions iib/workers/tasks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down

0 comments on commit af35b90

Please sign in to comment.