Skip to content

Commit

Permalink
Merge pull request #52 from emilyzheng/add-deprecations
Browse files Browse the repository at this point in the history
Create add-deprecations entrypoint [CLOUDDST-23912]
  • Loading branch information
emilyzheng authored Aug 30, 2024
2 parents e9f414c + 96efc3f commit 1586706
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 70 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def read_content(filepath):
"console_scripts": [
"pubtools-iib-add-bundles = pubtools.iib.iib_ops:add_bundles_main",
"pubtools-iib-remove-operators = pubtools.iib.iib_ops:remove_operators_main",
"pubtools-iib-add-deprecations = pubtools.iib.iib_ops:add_deprecations_main",
]
},
include_package_data=True,
Expand Down
85 changes: 70 additions & 15 deletions src/pubtools/iib/iib_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,6 @@
"required": False,
"type": str,
},
("--arch",): {
"group": "IIB service",
"help": "architecture to rebuild",
"required": False,
"type": str,
"action": "append",
},
("--overwrite-from-index",): {
"group": "IIB service",
"help": (
Expand Down Expand Up @@ -117,6 +110,13 @@
"required": False,
"type": bool,
}
ADD_CMD_ARGS[("--arch",)] = {
"group": "IIB service",
"help": "architecture to rebuild",
"required": False,
"type": str,
"action": "append",
}

RM_CMD_ARGS = CMD_ARGS.copy()
RM_CMD_ARGS[("--operator",)] = {
Expand All @@ -126,6 +126,27 @@
"type": str,
"action": "append",
}
RM_CMD_ARGS[("--arch",)] = {
"group": "IIB service",
"help": "architecture to rebuild",
"required": False,
"type": str,
"action": "append",
}

ADD_DEPRECATIONS_CMD_ARGS = CMD_ARGS.copy()
ADD_DEPRECATIONS_CMD_ARGS[("--deprecation-schema",)] = {
"group": "IIB service",
"help": "JSON formatted deprecation schema",
"required": True,
"type": str,
}
ADD_DEPRECATIONS_CMD_ARGS[("--operator-package",)] = {
"group": "IIB service",
"help": "operator name",
"required": True,
"type": str,
}


def push_items_from_build(
Expand All @@ -150,7 +171,7 @@ def push_items_from_build(
for operator in build_details.removed_operators:
item = {
"state": state,
"origin": build_details.from_index or "scratch",
"origin": build_details.from_index,
"src": None,
"filename": operator,
"dest": "redhat-operator-index",
Expand All @@ -159,6 +180,18 @@ def push_items_from_build(
"checksums": None,
}
ret.append(item)
elif build_details.request_type == "add-deprecations":
item = {
"state": state,
"origin": build_details.from_index,
"src": None,
"filename": build_details.operator_package,
"dest": "redhat-operator-index",
"build": build_details.index_image,
"signing_key": None,
"checksums": None,
}
ret.append(item)

return ret

Expand All @@ -185,7 +218,7 @@ def _iib_op_main(
operation: str | None = None,
items_final_state: str = "PUSHED",
) -> list[dict[Any, Any]] | Any:
if operation not in ("add_bundles", "remove_operators"):
if operation not in ("add_bundles", "remove_operators", "add_deprecations"):
raise ValueError("Must set iib operation")

pc = pushcollector.Collector.get()
Expand All @@ -201,6 +234,14 @@ def _iib_op_main(
extra_args["deprecation_list"] = args.deprecation_list.split(",")
if args.check_related_images:
extra_args["check_related_images"] = args.check_related_images
extra_args["arches"] = args.arch
extra_args["bundles"] = args.bundle
if operation == "remove_operators":
extra_args["arches"] = args.arch
extra_args["operators"] = args.operator
if operation == "add_deprecations":
extra_args["operator_package"] = args.operator_package
extra_args["deprecation_schema"] = args.deprecation_schema

if args.binary_image:
extra_args["binary_image"] = args.binary_image
Expand All @@ -214,12 +255,7 @@ def _iib_op_main(
if args.build_tag:
extra_args["build_tags"] = args.build_tag

build_details = bundle_op(
args.index_image,
args.bundle if operation == "add_bundles" else args.operator,
args.arch,
**extra_args,
)
build_details = bundle_op(args.index_image, **extra_args)

push_items = push_items_from_build(build_details, "PENDING")
LOG.debug("Updating push items")
Expand Down Expand Up @@ -251,6 +287,10 @@ def make_rm_operators_parser() -> ArgumentParser:
return setup_arg_parser(RM_CMD_ARGS)


def make_add_deprecations_parser() -> ArgumentParser:
return setup_arg_parser(ADD_DEPRECATIONS_CMD_ARGS)


def add_bundles_main(sysargs: list[str] | None = None) -> list[dict[Any, Any]]:
logging.basicConfig(level=logging.INFO)

Expand Down Expand Up @@ -279,6 +319,21 @@ def remove_operators_main(
return _iib_op_main(args, "remove_operators", "DELETED")


def add_deprecations_main(
sysargs: list[str] | None = None,
) -> list[dict[Any, Any]]:
logging.basicConfig(level=logging.INFO)

parser = make_add_deprecations_parser()
if sysargs:
args = parser.parse_args(sysargs[1:])
else:
args = parser.parse_args()
process_parsed_args(args, ADD_DEPRECATIONS_CMD_ARGS)

return _iib_op_main(args, "add_deprecations")


def _make_iib_build_details_url(host: str, task_id: str) -> str:
return "https://%s/api/v1/builds/%s" % (host, task_id)

Expand Down
Loading

0 comments on commit 1586706

Please sign in to comment.