Skip to content

Commit 5a86b10

Browse files
MaciejKarasfealebenpae
authored andcommitted
CLOUDP-297952 - automatically determine minimum operator version for agent matrix builds (#4107)
# Summary This PR automates calculating the last 3 supported operator versions that are used for agent matrix builds. Previously this had to be updated manually during every release. Additionally fixed possible issue with python `sorted` method. It does not sort properly version strings as it is using lexicographical order i.e. version `1.300.0` would be lower than `1.31.0`. ## Proof of Work Added new test file that is passing [scripts/evergreen/release/agent_matrix_test.py](https://github.com/10gen/ops-manager-kubernetes/blob/58f8f08ad26e55561b0af37c372bedd208962518/scripts/evergreen/release/agent_matrix_test.py) ## Tasks after merge - [ ] Update release guide and remove manual step for bumping supported agent version in code ## Checklist - [x] Have you linked a jira ticket and/or is the ticket in the title? - [x] Have you checked whether your jira ticket required DOCSP changes? - [x] Have you checked for release_note changes? ## Reminder (Please remove this when merging) - Please try to Approve or Reject Changes the PR, keep PRs in review as short as possible - Our Short Guide for PRs: [Link](REDACTED) - Remember the following Communication Standards - use comment prefixes for clarity: * **blocking**: Must be addressed before approval. * **follow-up**: Can be addressed in a later PR or ticket. * **q**: Clarifying question. * **nit**: Non-blocking suggestions. * **note**: Side-note, non-actionable. Example: Praise * --> no prefix is considered a question
1 parent 1e40fec commit 5a86b10

File tree

5 files changed

+78
-15
lines changed

5 files changed

+78
-15
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ sbom-tests:
259259
python-tests:
260260
@ scripts/evergreen/run_python.sh -m pytest pipeline_test.py
261261
@ scripts/evergreen/run_python.sh -m pytest lib/sonar
262+
@ scripts/evergreen/run_python.sh -m pytest scripts/evergreen/release/agent_matrix_test.py
262263
@ scripts/evergreen/run_python.sh -m pytest docker/mongodb-enterprise-tests/kubeobject
263264

264265
generate-ssdlc-report:

generate_ssdlc_report.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
from lib.base_logger import logger
2929
from scripts.evergreen.release.agent_matrix import (
30+
LATEST_OPERATOR_VERSION,
3031
get_supported_version_for_image_matrix_handling,
3132
)
3233

@@ -92,7 +93,7 @@ def get_supported_images(release: Dict) -> dict[str, SupportedImage]:
9293
supported_images = filter_out_unsupported_images(supported_images)
9394
supported_images = convert_to_image_names(supported_images)
9495
supported_images["mongodb-agent-ubi"] = SupportedImage(
95-
get_supported_version_for_image_matrix_handling("mongodb-agent", latest_operator_only=True),
96+
get_supported_version_for_image_matrix_handling("mongodb-agent", LATEST_OPERATOR_VERSION),
9697
"mongodb-agent-ubi",
9798
"quay.io/mongodb/mongodb-agent-ubi",
9899
release["supportedImages"]["mongodb-agent"]["ssdlc_name"],

scripts/evergreen/release/agent_matrix.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import json
22
from typing import Dict, List
33

4+
DEFAULT_SUPPORTED_OPERATOR_VERSIONS = 3
5+
LATEST_OPERATOR_VERSION = 1
6+
47

58
def get_release() -> Dict[str, str]:
69
return json.load(open("release.json"))
@@ -17,14 +20,15 @@ def build_agent_gather_versions(release: Dict[str, str]):
1720
return agent_versions_to_be_build
1821

1922

20-
def get_supported_version_for_image_matrix_handling(image: str, latest_operator_only: bool = False) -> List[str]:
23+
def get_supported_version_for_image_matrix_handling(
24+
image: str, supported_versions: int = DEFAULT_SUPPORTED_OPERATOR_VERSIONS
25+
) -> List[str]:
2126
# if we are a certifying mongodb-agent, we will need to also certify the
2227
# static container images which are a matrix of <agent_version>_<operator_version>
2328
if image == "mongodb-agent":
2429
# officially, we start the support with 1.25.0, but we only support the last three versions
25-
last_supported_operator_versions = get_supported_operator_versions()
26-
if latest_operator_only:
27-
last_supported_operator_versions = [last_supported_operator_versions[-1]]
30+
last_supported_operator_versions = get_supported_operator_versions(supported_versions)
31+
2832
agent_version_with_static_support_without_operator_suffix = build_agent_gather_versions(get_release())
2933
agent_version_with_static_support_with_operator_suffix = list()
3034
for agent in agent_version_with_static_support_without_operator_suffix:
@@ -45,12 +49,11 @@ def get_supported_version_for_image_matrix_handling(image: str, latest_operator_
4549
return sorted(get_release()["supportedImages"][image]["versions"])
4650

4751

48-
def get_supported_operator_versions():
49-
min_supported_version_operator_for_static = "1.29.0"
50-
last_supported_operator_versions = [
51-
v
52-
for v in get_release()["supportedImages"]["operator"]["versions"]
53-
if v >= min_supported_version_operator_for_static
54-
]
52+
def get_supported_operator_versions(supported_versions: int = DEFAULT_SUPPORTED_OPERATOR_VERSIONS):
53+
operator_versions = list(get_release()["supportedImages"]["operator"]["versions"])
54+
operator_versions.sort(key=lambda s: list(map(int, s.split("."))))
55+
56+
if len(operator_versions) <= supported_versions:
57+
return operator_versions
5558

56-
return sorted(last_supported_operator_versions)
59+
return operator_versions[-supported_versions:]
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from unittest import mock
2+
3+
from scripts.evergreen.release.agent_matrix import get_supported_operator_versions
4+
5+
empty_release = {"supportedImages": {"operator": {"versions": []}}}
6+
7+
8+
@mock.patch("scripts.evergreen.release.agent_matrix.get_release", return_value=empty_release)
9+
def test_get_supported_operator_versions_empty(_):
10+
supported_versions = get_supported_operator_versions()
11+
assert len(supported_versions) == 0
12+
13+
14+
single_release = {"supportedImages": {"operator": {"versions": ["1.30.0"]}}}
15+
16+
17+
@mock.patch("scripts.evergreen.release.agent_matrix.get_release", return_value=single_release)
18+
def test_get_supported_operator_versions_single_release(_):
19+
supported_versions = get_supported_operator_versions()
20+
assert len(supported_versions) == 1
21+
assert supported_versions[0] == "1.30.0"
22+
23+
24+
three_releases_not_ordered = {"supportedImages": {"operator": {"versions": ["1.30.0", "1.28.0", "2.0.2"]}}}
25+
26+
27+
@mock.patch("scripts.evergreen.release.agent_matrix.get_release", return_value=three_releases_not_ordered)
28+
def test_get_supported_operator_versions_three_releases_not_ordered(_):
29+
supported_versions = get_supported_operator_versions()
30+
assert len(supported_versions) == 3
31+
assert supported_versions == ["1.28.0", "1.30.0", "2.0.2"]
32+
33+
34+
many_releases_not_ordered = {
35+
"supportedImages": {
36+
"operator": {
37+
"versions": [
38+
"1.32.0",
39+
"1.25.0",
40+
"1.26.0",
41+
"1.27.1",
42+
"1.27.0",
43+
"1.30.0",
44+
"1.300.0",
45+
"1.28.123",
46+
"0.0.1",
47+
"2.0.2",
48+
]
49+
}
50+
}
51+
}
52+
53+
54+
@mock.patch("scripts.evergreen.release.agent_matrix.get_release", return_value=many_releases_not_ordered)
55+
def test_get_supported_operator_versions_many_releases_not_ordered(_):
56+
supported_versions = get_supported_operator_versions()
57+
assert len(supported_versions) == 3
58+
assert supported_versions == ["1.32.0", "1.300.0", "2.0.2"]

scripts/update_supported_dockerfiles.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ def get_release() -> Dict[str, str]:
4141
return json.load(open("release.json"))
4242

4343

44-
def get_supported_variants_for_image(image: str) -> List[Dict[str, str]]:
44+
def get_supported_variants_for_image(image: str) -> List[str]:
4545
splitted_image_name = image.split("mongodb-enterprise-", 1)
4646
if len(splitted_image_name) == 2:
4747
image = splitted_image_name[1]
4848

4949
return get_release()["supportedImages"][image]["variants"]
5050

5151

52-
def get_supported_version_for_image(image: str) -> List[Dict[str, str]]:
52+
def get_supported_version_for_image(image: str) -> List[str]:
5353
splitted_image_name = image.split("mongodb-enterprise-", 1)
5454
if len(splitted_image_name) == 2:
5555
image = splitted_image_name[1]

0 commit comments

Comments
 (0)