Skip to content

Commit 75d8a88

Browse files
Allow update of multiple operator catalogs
1 parent 49be60d commit 75d8a88

8 files changed

Lines changed: 100 additions & 40 deletions

File tree

ansible/roles/operator-pipeline/templates/openshift/pipelines/operator-ci-pipeline.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ spec:
228228
params:
229229
- name: pipeline_image
230230
value: "$(params.pipeline_image)"
231-
- name: operator_path
232-
value: "$(tasks.bundle-path-validation.results.package_path)"
231+
- name: affected_operators
232+
value: "$(tasks.bundle-path-validation.results.package_name)"
233233
workspaces:
234234
- name: source
235235
workspace: pipeline

ansible/roles/operator-pipeline/templates/openshift/pipelines/operator-hosted-pipeline.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,10 @@ spec:
525525
params:
526526
- name: pipeline_image
527527
value: "$(params.pipeline_image)"
528-
- name: operator_path
529-
value: "$(tasks.detect-changes.results.operator_path)"
528+
- name: affected_operators
529+
value: "$(tasks.detect-changes.results.affected_operators)"
530+
- name: affected_catalog_operators
531+
value: "$(tasks.detect-changes.results.affected_catalog_operators)"
530532
- name: cert_project_required
531533
value: "$(params.cert_project_required)"
532534
workspaces:
@@ -1034,8 +1036,8 @@ spec:
10341036
- input: "$(tasks.certification-project-check.results.certification_project_id)"
10351037
operator: "notin"
10361038
values: [""]
1037-
- input: "$(tasks.detect-changes.results.affected_catalogs)"
1038-
operator: in
1039+
- input: "$(tasks.detect-changes.results.added_or_modified_bundles)"
1040+
operator: "notin"
10391041
values: [""]
10401042
params:
10411043
- name: pipeline_image

ansible/roles/operator-pipeline/templates/openshift/pipelines/operator-release-pipeline.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,10 @@ spec:
276276
params:
277277
- name: pipeline_image
278278
value: "$(params.pipeline_image)"
279-
- name: operator_path
280-
value: "$(tasks.detect-changes.results.operator_path)"
279+
- name: affected_operators
280+
value: "$(tasks.detect-changes.results.affected_operators)"
281+
- name: affected_catalog_operators
282+
value: "$(tasks.detect-changes.results.affected_catalog_operators)"
281283
- name: cert_project_required
282284
value: "$(params.cert_project_required)"
283285
workspaces:

ansible/roles/operator-pipeline/templates/openshift/tasks/cert-project-check.yml

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ metadata:
66
spec:
77
params:
88
- name: pipeline_image
9-
- name: operator_path
10-
description: path indicating the location of the certified operator within the repository
9+
- name: affected_operators
10+
description: Comma separated list of affected operators
11+
default: ""
12+
- name: affected_catalog_operators
13+
description: Comma separated list of affected catalog operators
1114
default: ""
1215
- name: cert_project_required
1316
description: A flag determines whether a cert project ID needs to be present
@@ -32,18 +35,48 @@ spec:
3235
exit 0
3336
fi
3437
35-
if [ -z "$(params.operator_path)" ]; then
36-
echo "Operator path is missing."
38+
if [[ -z "$(params.affected_operators)" && -z "$(params.affected_catalog_operators)" ]]; then
39+
echo "No operator is affected."
3740
exit 1
3841
fi
3942
40-
CI_FILE_PATH="$(params.operator_path)/ci.yaml"
43+
# Create dictionary of all affected operators to serve as a set
44+
declare -A ALL_AFFECTED_OPERATORS
4145
42-
CERT_PROJECT_ID=$(cat $CI_FILE_PATH | yq -r '.cert_project_id | select (.!=null)')
46+
# Add operators from affected_operators
47+
if [ -n "$(params.affected_operators)" ]; then
48+
IFS=',' read -ra affected_ops_array <<< "$(params.affected_operators)"
49+
for op in "${affected_ops_array[@]}"; do
50+
ALL_AFFECTED_OPERATORS["$op"]=1
51+
done
52+
fi
4353
44-
if [ -z $CERT_PROJECT_ID ]; then
45-
echo "Certification project ID is missing in ci.yaml file (cert_project_id)"
46-
exit 1
54+
# Add operators from affected_catalog_operators
55+
if [ -n "$(params.affected_catalog_operators)" ]; then
56+
IFS=',' read -ra affected_catalog_ops_array <<< "$(params.affected_catalog_operators)"
57+
for op in "${affected_catalog_ops_array[@]}"; do
58+
operator_name=$(echo "$op" | cut -d'/' -f2) # Parse operator name from its catalog path
59+
if [ -n "$operator_name" ]; then
60+
ALL_AFFECTED_OPERATORS["$operator_name"]=1
61+
fi
62+
done
4763
fi
4864
49-
echo -n $CERT_PROJECT_ID | tee $(results.certification_project_id.path)
65+
66+
for operator_name in "${!ALL_AFFECTED_OPERATORS[@]}"; do
67+
file_path="operators/$operator_name/ci.yaml"
68+
69+
if [ ! -f "$file_path" ]; then
70+
echo "File '$file_path' not found."
71+
exit 1
72+
fi
73+
74+
CERT_PROJECT_ID=$(cat "$file_path" | yq -r '.cert_project_id | select (.!=null)')
75+
76+
if [ -z "$CERT_PROJECT_ID" ]; then
77+
echo "Certification project ID is missing in '$file_path' file (cert_project_id)"
78+
exit 1
79+
fi
80+
done
81+
82+
echo -n "$CERT_PROJECT_ID" | tee "$(results.certification_project_id.path)"

ansible/roles/operator-pipeline/templates/openshift/tasks/parse-repo-changes.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ spec:
2424
description: Path to the operator containing the new bundle
2525
- name: bundle_path
2626
description: Path to the new bundle
27+
- name: affected_operators
28+
description: Comma separated list of affected operators
29+
- name: added_or_modified_bundles
30+
description: Comma separated list of added or updated bundles
2731
- name: affected_catalogs
2832
description: Comma separated list of updated catalogs
2933
- name: added_or_modified_catalogs
@@ -83,6 +87,12 @@ spec:
8387
affected_catalogs="$(jq -r '.affected_catalogs | join(",")' < changes.json)"
8488
echo -n $affected_catalogs > "$(results.affected_catalogs.path)"
8589
90+
affected_operators="$(jq -r '.affected_operators | join(",")' < changes.json)"
91+
echo -n $affected_operators > "$(results.affected_operators.path)"
92+
93+
added_or_modified_bundles="$(jq -r '.added_or_modified_bundles | join(",")' < changes.json)"
94+
echo -n $added_or_modified_bundles > "$(results.added_or_modified_bundles.path)"
95+
8696
added_or_modified_catalogs="$(jq -r '.added_or_modified_catalogs | join(",")' < changes.json)"
8797
echo -n $added_or_modified_catalogs > "$(results.added_or_modified_catalogs.path)"
8898

docs/users/community-operators-troubleshooting.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Failures at this stage are rare. To diagnose the issue, review the pipeline logs
8282
The pipeline may fail at this stage due to the following reasons:
8383

8484
1. <b>Changing Non-Operator Files:</b> If the PR attempts to modify external files outside of targeted operator, the pipeline will fail.
85-
1. <b>Affecting Multiple Operators:</b> If the PR impacts more than one operator, it will result in a failure.
85+
1. <b>Affecting Multiple Operator Bundles:</b> If the PR impacts more than one operator bundle, it will result in a failure. Update of multiple operators non-bundle files is allowed.
8686
1. <b>Modifying Existing Bundles:</b> Changes to existing bundles in the PR are not allowed at this stage.
8787
1. <b>Deleting Existing Bundles:</b> Deleting bundles is only permissible for FBC-enabled operators.
8888

operator-pipeline-images/operatorcert/parsed_file.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,12 @@ def check_extra_files(self) -> None:
249249

250250
def check_affected_operators(self) -> None:
251251
"""
252-
The PR should affect at most one operator
252+
The PR should affect at most one operator unless only non-bundle files are updated.
253253
"""
254-
if len(self.object.affected_operators.union) > 1:
254+
if (
255+
len(self.object.affected_operators.union) > 1
256+
and len(self.object.affected_bundles.union) != 0
257+
):
255258
self.errors.append(
256259
"The PR affects more than one operator: "
257260
f"{sorted(self.object.affected_operators.union)}"
@@ -349,8 +352,7 @@ def check_added_bundles(self) -> None:
349352

350353
def check_affected_catalog_operators(self) -> None:
351354
"""
352-
Check if the PR affects at most one catalog operator and PR doesn't contains
353-
catalog changes and operator changes
355+
Check if the PR doesn't contains catalog changes and operator changes at the same time.
354356
"""
355357
added_or_modified_bundles = (
356358
self.object.affected_bundles.added | self.object.affected_bundles.modified
@@ -363,18 +365,6 @@ def check_affected_catalog_operators(self) -> None:
363365
f"({sorted(self.object.affected_catalog_operators.union)}) at the same time. "
364366
"Split operator and catalog changes into 2 separate pull requests."
365367
)
366-
catalog_operators = sorted(
367-
list(
368-
{
369-
operator[1]
370-
for operator in self.object.affected_catalog_operators.union
371-
}
372-
)
373-
)
374-
if len(catalog_operators) > 1:
375-
self.errors.append(
376-
f"The PR affects more than one catalog operator: {catalog_operators}"
377-
)
378368

379369
def validate(self) -> None:
380370
"""

operator-pipeline-images/tests/entrypoints/test_detect_changed_operators.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -496,9 +496,19 @@ def test_github_pr_affected_files_invalid_url(
496496
"extra_files": [],
497497
"added_operators": ["operator-e2e", "operator-clone-e2e"],
498498
},
499+
True,
500+
None,
501+
id="Multiple operators - no bundle change",
502+
),
503+
pytest.param(
504+
{
505+
"extra_files": [],
506+
"added_operators": ["operator-e2e", "operator-clone-e2e"],
507+
"added_bundles": [("operator-e2e", "0.0.101")],
508+
},
499509
False,
500510
"The PR affects more than one operator: ['operator-clone-e2e', 'operator-e2e']",
501-
id="Multiple operators",
511+
id="Multiple operators - with bundle change",
502512
),
503513
pytest.param(
504514
{
@@ -526,17 +536,17 @@ def test_github_pr_affected_files_invalid_url(
526536
("v4.15", "operator-2"),
527537
],
528538
},
529-
False,
530-
"The PR affects more than one catalog operator: ['operator-1', 'operator-2']",
539+
True,
540+
None,
531541
id="Multiple catalog operators",
532542
),
533543
pytest.param(
534544
{
535545
"extra_files": ["empty.txt", "operators/empty.txt"],
536-
"added_operators": ["operator-e2e", "operator-clone-e2e"],
546+
"added_bundles": ["operator-e2e", "operator-clone-e2e"],
537547
},
538548
False,
539-
"The PR affects more than one operator: ['operator-clone-e2e', 'operator-e2e']\n"
549+
"The PR affects more than one bundle: ['operator-clone-e2e', 'operator-e2e']\n"
540550
"The PR affects non-operator files: ['empty.txt', 'operators/empty.txt']",
541551
id="Multiple issues",
542552
),
@@ -578,6 +588,19 @@ def test_github_pr_affected_files_invalid_url(
578588
None,
579589
id="Add operator catalog",
580590
),
591+
pytest.param(
592+
{
593+
"added_catalog_operators": [
594+
("v4.15", "operator-e2e"),
595+
("v4.15", "operator-e2e"),
596+
],
597+
"modified_operators": ["operator-e2e", "operator-clone-e2e"],
598+
"modified_bundles": [],
599+
},
600+
True,
601+
None,
602+
id="Modify two operators' non-bundle files and their catalogs.",
603+
),
581604
],
582605
)
583606
def test_ParserRules_validate(

0 commit comments

Comments
 (0)