Skip to content

Commit e69f976

Browse files
committed
Remove calculate_images_to_build function
1 parent 96ade9a commit e69f976

File tree

2 files changed

+11
-70
lines changed

2 files changed

+11
-70
lines changed

pipeline.py

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,38 +1518,11 @@ 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

15501524
parser = argparse.ArgumentParser()
1551-
parser.add_argument("--include", action="append")
1552-
parser.add_argument("--exclude", action="append")
1525+
parser.add_argument("--include", required=True)
15531526
parser.add_argument("--builder", default="docker", type=str)
15541527
parser.add_argument("--list-images", action="store_true")
15551528
parser.add_argument("--parallel", action="store_true", default=False)
@@ -1587,12 +1560,17 @@ def main():
15871560
if not args.sign:
15881561
logger.warning("--sign flag not provided, images won't be signed")
15891562

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

15941572
build_all_images(
1595-
images_to_build,
1573+
image_to_build,
15961574
args.builder,
15971575
debug=args.debug,
15981576
parallel=args.parallel,

pipeline_test.py

Lines changed: 1 addition & 38 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,43 +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-
79-
# Given an include, it should only return include images
80-
(["cli", "ops-manager", "appdb-daily", "init-appdb"], ["cli"], [], {"cli"}),
81-
82-
# Given no include nor excludes it should return all images
83-
(["cli", "ops-manager", "appdb-daily", "init-appdb"], [], [], {'init-appdb', 'appdb-daily', 'ops-manager', 'cli'}),
84-
85-
# Given an exclude, it should return all images except the excluded ones
86-
(["cli", "ops-manager", "appdb-daily", "init-appdb"], [], ['init-appdb', 'appdb-daily'], {'ops-manager', 'cli'}),
87-
88-
# Given an include and a different exclude, it should return all images except the exclusions
89-
(["cli", "ops-manager", "appdb-daily", "init-appdb"], ['appdb-daily'], ['init-appdb'], {'appdb-daily', 'cli', 'ops-manager'}),
90-
91-
# Given multiple includes and a different exclude, it should return all images except the exclusions
92-
(["cli", "ops-manager", "appdb-daily", "init-appdb"], ['cli', 'appdb-daily'], ['init-appdb'], {'appdb-daily', 'cli', 'ops-manager'}),
93-
],
94-
)
95-
def test_calculate_images_to_build(test_case):
96-
images, include, exclude, expected = test_case
97-
if expected is ValueError:
98-
with pytest.raises(ValueError):
99-
calculate_images_to_build(images, include, exclude)
100-
else:
101-
assert calculate_images_to_build(images, include, exclude) == expected
102-
103-
10467
@pytest.mark.parametrize(
10568
"version,min_version,max_version,expected",
10669
[

0 commit comments

Comments
 (0)