Skip to content

Commit 83c2189

Browse files
committed
[operator_build] Update the go.mod replace to use local repos
When building from a PR that has multiple dependencies in the same repo, the incorrect versions are built. This happens because the build tasks extract a sha from an operators list that is built from zuul.items, which contains a list of the dependencies on a PR (from Depends-On). This list can contain multiple PRs from the same repo, however, the operator list only takes the first item for each repo. The information is used to update the openstack-operator go.mod file with a "replaces" directive that tell it where to find the operators to deploy. The line being added was referencing a particular commit on the PR source branch previously. This is incorrect when using zuul, as zuul uses speculative merging and prepares a version of the repositories that have all the dependencies merged together. The "replaces" is updated to reference the local version of the operator i.e. the one prepared by zuul.
1 parent 07f6a4f commit 83c2189

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

roles/operator_build/tasks/build.yml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@
3838
ansible.builtin.set_fact:
3939
operator_api_path: "github.com/{{ cifmw_operator_build_org }}/{{ operator.name }}/{{ operator_base_module_name }}"
4040

41+
# This is telling the openstack operator to look for dependency on a particular branch on github.
42+
# This should be the zuul src path.
4143
- name: "{{ operator.name }} - Update the go.mod file in meta operator for provided PR_SHA" # noqa: name[template]
4244
ansible.builtin.shell: |
43-
go mod edit -replace {{ operator_api_path }}=github.com/{{ operator.pr_owner }}/{{ operator_base_module_name }}@{{ operator.pr_sha }}
45+
go mod edit -replace {{ operator_api_path }}={{ ansible_user_dir }}/{{ operator.src_dir }}/{{ operator_base_module_name }}
4446
go mod tidy
4547
if [ -d ./apis ]; then
4648
pushd ./apis/
47-
go mod edit -replace {{ operator_api_path }}=github.com/{{ operator.pr_owner }}/{{ operator_base_module_name }}@{{ operator.pr_sha }}
49+
go mod edit -replace {{ operator_api_path }}={{ ansible_user_dir }}/{{ operator.src_dir }}/{{ operator_base_module_name }}
4850
go mod tidy
4951
popd
5052
fi
@@ -63,17 +65,24 @@
6365
chdir: "{{ operator.src }}"
6466
register: git_head_out
6567

68+
# The PR sha does not need to be pulled from the zuul.projects, since this __should__ match HEAD
6669
- name: "{{ operator.name }} - Set pr_sha to be used as image tag" # noqa: name[template]
6770
ansible.builtin.set_fact:
68-
pr_sha: "{{ operator.pr_sha | default(git_head_out.stdout | trim) }}"
71+
#pr_sha: "{{ operator.pr_sha | default(git_head_out.stdout | trim) }}"
72+
pr_sha: "{{ git_head_out.stdout | trim }}"
73+
74+
- name: Skip if operator.pr_sha matches HEAD
75+
when: pr_sha != operator.pr_sha | default('')
76+
ansible.builtin.debug:
77+
msg: "Something"
6978

7079
- name: "{{ operator.name }} - Update the go.mod file using latest commit if no PR is provided" # noqa: name[template]
7180
ansible.builtin.shell: |
72-
go mod edit -replace {{ operator_api_path }}={{ operator_api_path }}@{{ pr_sha }}
81+
go mod edit -replace {{ operator_api_path }}={{ ansible_user_dir }}/{{ operator.src_dir }}/{{ operator_base_module_name }}
7382
go mod tidy
7483
if [ -d ./apis ]; then
7584
pushd ./apis/
76-
go mod edit -replace {{ operator_api_path }}={{ operator_api_path }}@{{ pr_sha }}
85+
go mod edit -replace {{ operator_api_path }}={{ ansible_user_dir }}/{{ operator.src_dir }}/{{ operator_base_module_name }}
7786
go mod tidy
7887
popd
7988
fi

roles/operator_build/tasks/main.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@
3232
cifmw_operator_build_output: "{{ cifmw_operator_build_output }}"
3333
cifmw_operator_build_meta_name: "{{ cifmw_operator_build_meta_name }}"
3434

35+
# This builds a list of operators from the zuul.items list.
36+
# zuul.items is a list of all the changes that are included via Depends-On.
37+
# This can have duplicates if you have multiple changes from the same repo.
38+
# e.g. when there's a CI PR trying to test some other unmerged change.
39+
# In the case that there are duplicates, only one version is taken, which is incorrect.
40+
# zuul.projects contains a list of the prepared repos that the job needs (listed in required-projects)
41+
# zuul.projects contains reporitories that have the multiple changes from each repo merged.
42+
# The operator we want to build is from this source.
43+
# The zuul.items list can be used to build a list of operators that need to be build i.e. all the operators that have been changed and are depended on by the PR being tested.
44+
# However, the repository/version to build from should be obtained from zuul.projects[$operator_name], not zuul.items.search($operator_name) | first.
3545
- name: Populate operators list with zuul info
3646
when:
3747
- zuul is defined
@@ -42,6 +52,16 @@
4252
loop_control:
4353
loop_var: zuul_item
4454

55+
# The task above gets a list of the projects that have changed and will need to be rebuilt.
56+
# Since we're not using the github URLs in go.mod replace lines, we don't need to get any of the URLs
57+
# The PR shas are also no longer used, since we set the image sha from the git HEAD.
58+
59+
# Before running this, the zuul_info_operators var needs to be updated with the information from zuul.projects
60+
# The information that it needs from zuul.projects is the commit hash?
61+
# operators_list is used in build.yml, where is it looped through and passed in one-at-a-time as the operator variable
62+
# The values needed are the URL of the source branch of the PR and the commit sha
63+
# The usage of this information has been updated, so that the go.mod redirects point to the local repos and
64+
# the commit sha is looked up in the local repo
4565
- name: Merge lists of operators
4666
ansible.builtin.set_fact:
4767
operators_list: "{{ [cifmw_operator_build_operators, zuul_info_operators | default([])] \

0 commit comments

Comments
 (0)