Skip to content

Commit 3753163

Browse files
committed
Remove calculate_images_to_build function
1 parent 20ea2ad commit 3753163

File tree

2 files changed

+12
-86
lines changed

2 files changed

+12
-86
lines changed

pipeline.py

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,40 +1518,13 @@ def build_all_images(
15181518
build_image(image, build_configuration)
15191519

15201520

1521-
def calculate_images_to_build(
1522-
images: List[str], include: Optional[List[str]], exclude: Optional[List[str]]
1523-
) -> Set[str]:
1524-
"""
1525-
Calculates which images to build based on the `images`, `include` and `exclude` sets.
1526-
1527-
>>> calculate_images_to_build(["a", "b"], ["a"], ["b"])
1528-
... ["a"]
1529-
"""
1530-
1531-
if not include and not exclude:
1532-
return set(images)
1533-
include = set(include or [])
1534-
exclude = set(exclude or [])
1535-
images = set(images or [])
1536-
1537-
for image in include.union(exclude):
1538-
if image not in images:
1539-
raise ValueError("Image definition {} not found".format(image))
1540-
1541-
images_to_build = include.intersection(images)
1542-
if exclude:
1543-
images_to_build = images.difference(exclude)
1544-
return images_to_build
1545-
1546-
15471521
def main():
15481522
_setup_tracing()
15491523
_setup_tracing()
15501524

15511525
parser = argparse.ArgumentParser()
1552-
parser.add_argument("--include", action="append", help="list of images to include")
1553-
parser.add_argument("--exclude", action="append", help="list of images to exclude")
1554-
parser.add_argument("--builder", default="docker", type=str, help="docker or podman")
1526+
parser.add_argument("--include", action="append", required=True)
1527+
parser.add_argument("--builder", default="docker", type=str)
15551528
parser.add_argument("--list-images", action="store_true")
15561529
parser.add_argument("--parallel", action="store_true", default=False)
15571530
parser.add_argument("--debug", action="store_true", default=False)
@@ -1588,12 +1561,17 @@ def main():
15881561
if not args.sign:
15891562
logger.warning("--sign flag not provided, images won't be signed")
15901563

1591-
images_to_build = calculate_images_to_build(
1592-
list(get_builder_function_for_image_name().keys()), args.include, args.exclude
1593-
)
1564+
if args.include is None:
1565+
print("No images to build, --include is required.")
1566+
sys.exit(1)
1567+
1568+
image_to_build = args.include
1569+
if args.include not in get_builder_function_for_image_name():
1570+
print("Image {} not found".format(args.include))
1571+
sys.exit(1)
15941572

15951573
build_all_images(
1596-
images_to_build,
1574+
image_to_build,
15971575
args.builder,
15981576
debug=args.debug,
15991577
parallel=args.parallel,

pipeline_test.py

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import pytest
77

88
from pipeline import (
9-
calculate_images_to_build,
9+
get_included_images,
1010
gather_all_supported_agent_versions,
1111
gather_latest_agent_versions,
1212
get_versions_to_rebuild,
@@ -64,58 +64,6 @@ def test_operator_build_configuration_defaults():
6464
assert config.namespace == "default"
6565

6666

67-
@pytest.mark.parametrize(
68-
"test_case",
69-
[
70-
(["a", "b", "c"], ["a"], ["b"], {"a", "c"}),
71-
(["a", "b", "c"], ["a", "b"], None, {"a", "b"}),
72-
(["a", "b", "c"], None, ["a"], {"b", "c"}),
73-
(["a", "b", "c"], [], [], {"a", "b", "c"}),
74-
(["a", "b", "c"], ["d"], None, ValueError),
75-
(["a", "b", "c"], None, ["d"], ValueError),
76-
([], ["a"], ["b"], ValueError),
77-
(["a", "b", "c"], None, None, {"a", "b", "c"}),
78-
# Given an include, it should only return include images
79-
(["cli", "ops-manager", "appdb-daily", "init-appdb"], ["cli"], [], {"cli"}),
80-
# Given no include nor excludes it should return all images
81-
(
82-
["cli", "ops-manager", "appdb-daily", "init-appdb"],
83-
[],
84-
[],
85-
{"init-appdb", "appdb-daily", "ops-manager", "cli"},
86-
),
87-
# Given an exclude, it should return all images except the excluded ones
88-
(
89-
["cli", "ops-manager", "appdb-daily", "init-appdb"],
90-
[],
91-
["init-appdb", "appdb-daily"],
92-
{"ops-manager", "cli"},
93-
),
94-
# Given an include and a different exclude, it should return all images except the exclusions
95-
(
96-
["cli", "ops-manager", "appdb-daily", "init-appdb"],
97-
["appdb-daily"],
98-
["init-appdb"],
99-
{"appdb-daily", "cli", "ops-manager"},
100-
),
101-
# Given multiple includes and a different exclude, it should return all images except the exclusions
102-
(
103-
["cli", "ops-manager", "appdb-daily", "init-appdb"],
104-
["cli", "appdb-daily"],
105-
["init-appdb"],
106-
{"appdb-daily", "cli", "ops-manager"},
107-
),
108-
],
109-
)
110-
def test_calculate_images_to_build(test_case):
111-
images, include, exclude, expected = test_case
112-
if expected is ValueError:
113-
with pytest.raises(ValueError):
114-
calculate_images_to_build(images, include, exclude)
115-
else:
116-
assert calculate_images_to_build(images, include, exclude) == expected
117-
118-
11967
@pytest.mark.parametrize(
12068
"version,min_version,max_version,expected",
12169
[

0 commit comments

Comments
 (0)