Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create-emty-index - remove FBC opted in operators. #711

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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