Skip to content

Commit de17b0a

Browse files
committed
improve pairing mechanism
1 parent d19c202 commit de17b0a

6 files changed

Lines changed: 41 additions & 161 deletions

File tree

make/ksctl.mk

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,8 @@ endif
1717
get-ksctl-and-install:
1818
ifeq ($(strip $(KSCTL_REPO_PATH)),)
1919
ifneq ($(CI_DISABLE_PAIRING),true)
20-
ifeq ($(shell jq -r '.refs[0].org' <<< $${CLONEREFS_OPTIONS} 2>/dev/null || true | tr -d '[:space:]'),codeready-toolchain)
21-
$(eval AUTHOR_LINK = $(shell jq -r '.refs[0].pulls[0].author_link' <<< $${CLONEREFS_OPTIONS} | tr -d '[:space:]'))
22-
$(eval BRANCH_NAME := $(shell jq -r '.refs[0].pulls[0].head_ref' <<< $${CLONEREFS_OPTIONS} | tr -d '[:space:]'))
23-
@echo "using author link ${AUTHOR_LINK}"
24-
@echo "detected branch ${BRANCH_NAME}"
25-
# check if a branch with the same ref exists in the user's fork of ksctl repo
26-
@echo "branches of ${AUTHOR_LINK}/ksctl - checking if there is a branch ${BRANCH_NAME} we could pair with."
27-
curl ${AUTHOR_LINK}/ksctl.git/info/refs?service=git-upload-pack --output -
28-
$(eval REMOTE_KSCTL_BRANCH := $(shell curl ${AUTHOR_LINK}/ksctl.git/info/refs?service=git-upload-pack --output - 2>/dev/null | grep -a "refs/heads/${BRANCH_NAME}$$" | awk '{print $$2}'))
29-
# check if the branch with the same name exists, if so then merge it with master and use the merge branch, if not then use master
30-
@$(MAKE) clone-ksctl-and-pair REMOTE_KSCTL_BRANCH=${REMOTE_KSCTL_BRANCH} AUTHOR_LINK=${AUTHOR_LINK}
31-
else
32-
@echo "Either not running in openshift-ci or not in the codeready-toolchain org - no pairing"
33-
endif
20+
${PAIRING_EXEC} pair --clone-dir /tmp/ksctl --organization kubesaw --repository ksctl
21+
$(eval KSCTL_REPO_PATH := /tmp/ksctl)
3422
else
3523
@echo "Pairing explicitly disabled"
3624
endif
@@ -39,28 +27,6 @@ else
3927
endif
4028
@$(MAKE) install-ksctl KSCTL_REPO_PATH=${KSCTL_REPO_PATH} REMOTE_KSCTL_BRANCH=${REMOTE_KSCTL_BRANCH}
4129

42-
clone-ksctl-and-pair:
43-
ifneq ($(strip $(REMOTE_KSCTL_BRANCH)),)
44-
@echo "Branch ref of the user's fork to be used for pairing: \"${REMOTE_KSCTL_BRANCH}\""
45-
# define temp dir
46-
$(eval KSCTL_REPO_PATH := /tmp/ksctl)
47-
# delete to have clear environment
48-
rm -rf ${KSCTL_REPO_PATH}
49-
50-
git config --global user.email "devsandbox@redhat.com"
51-
git config --global user.name "KubeSaw"
52-
# clone
53-
git clone --depth=1 https://github.com/kubesaw/ksctl.git ${KSCTL_REPO_PATH}
54-
# add the user's fork as remote repo
55-
git --git-dir=${KSCTL_REPO_PATH}/.git --work-tree=${KSCTL_REPO_PATH} remote add external ${AUTHOR_LINK}/ksctl.git
56-
# fetch the branch
57-
git --git-dir=${KSCTL_REPO_PATH}/.git --work-tree=${KSCTL_REPO_PATH} fetch external ${REMOTE_KSCTL_BRANCH}
58-
# merge the branch with master
59-
git --git-dir=${KSCTL_REPO_PATH}/.git --work-tree=${KSCTL_REPO_PATH} merge --allow-unrelated-histories --no-commit FETCH_HEAD
60-
else
61-
@echo "No branch for pairing found"
62-
endif
63-
6430
install-ksctl:
6531
ifneq ($(strip $(KSCTL_REPO_PATH)$(REMOTE_KSCTL_BRANCH)),)
6632
@echo "Installing ksctl from directory $(or ${KSCTL_REPO_PATH}, /tmp/ksctl)"

make/test.mk

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,24 @@ endif
3939

4040
TESTS_RUN_FILTER_REGEXP ?= ""
4141

42+
PAIRING_DIR := "/tmp/pairing"
43+
PAIRING_EXEC := "/tmp/pairing/pairing"
44+
TOOLCHAIN_CICD := "/tmp/toolchain-cicd"
45+
46+
.PHONY: build-pairing
47+
build-pairing:
48+
# Clean the directory if it exists
49+
if [ -d "${TOOLCHAIN_CICD}" ]; then rm -rf ${TOOLCHAIN_CICD}; fi
50+
# Clone
51+
git clone --branch add_pairing_go_script https://github.com/rsoaresd/toolchain-cicd.git ${TOOLCHAIN_CICD}
52+
# Build the Go binary into the specified directory
53+
make -C ${TOOLCHAIN_CICD}/pairing build-pairing PAIRING_DIR=${PAIRING_DIR}
54+
55+
4256
.PHONY: test-e2e
4357
## Run the e2e tests
4458
test-e2e: INSTALL_OPERATOR=true
45-
test-e2e: prepare-e2e verify-migration-and-deploy-e2e e2e-run-parallel e2e-run e2e-run-metrics
59+
test-e2e: build-pairing prepare-e2e verify-migration-and-deploy-e2e e2e-run-parallel e2e-run e2e-run-metrics
4660
@echo "The tests successfully finished"
4761
@echo "To clean the cluster run 'make clean-e2e-resources'"
4862

@@ -57,7 +71,7 @@ test-e2e-sequential-only: prepare-e2e deploy-e2e e2e-run e2e-run-metrics
5771
@echo "To clean the cluster run 'make clean-e2e-resources'"
5872

5973
.PHONY: prepare-and-deploy-e2e
60-
## Prepare and Deploy e2e environment. Usefull to reset without having to run a test
74+
## Prepare and Deploy e2e environment. Useful to reset without having to run a test
6175
prepare-and-deploy-e2e: prepare-e2e deploy-e2e
6276
@echo "To clean the cluster run 'make clean-e2e-resources'"
6377

@@ -91,7 +105,7 @@ deploy-published-operators-e2e: clean-e2e-files deploy-e2e
91105
.PHONY: deploy-e2e
92106
deploy-e2e: INSTALL_OPERATOR=true
93107
deploy-e2e: prepare-projects get-publish-install-and-register-operators
94-
@echo "Operators are successfuly deployed using the ${ENVIRONMENT} environment."
108+
@echo "Operators are successfully deployed using the ${ENVIRONMENT} environment."
95109
@echo ""
96110

97111
label-olm-ns:
@@ -281,7 +295,8 @@ deploy-single-member-e2e-latest:
281295

282296
.PHONY: publish-current-bundles-for-e2e
283297
## Target that is supposed to be called from CI - it builds & publishes the current operator bundles
284-
publish-current-bundles-for-e2e: get-and-publish-operators
298+
publish-current-bundles-for-e2e:
299+
$(MAKE) build-pairing get-and-publish-operators
285300

286301
.PHONY: get-and-publish-operators
287302
get-and-publish-operators: PUBLISH_OPERATOR=true
@@ -328,7 +343,7 @@ ifeq ($(DEPLOY_LATEST),true)
328343
endif
329344
else
330345
@echo "Installing specific version of the member-operator"
331-
scripts/ci/manage-member-operator.sh -po ${PUBLISH_OPERATOR} -io ${INSTALL_OPERATOR} -mn ${MEMBER_NS} ${MEMBER_REPO_PATH_PARAM} -qn ${QUAY_NAMESPACE} -ds ${DATE_SUFFIX} ${MEMBER_NS_2_PARAM} ${FORCED_TAG_PARAM}
346+
scripts/ci/manage-member-operator.sh -po ${PUBLISH_OPERATOR} -io ${INSTALL_OPERATOR} -mn ${MEMBER_NS} ${MEMBER_REPO_PATH_PARAM} -qn ${QUAY_NAMESPACE} -ds ${DATE_SUFFIX} ${MEMBER_NS_2_PARAM} ${FORCED_TAG_PARAM} -pe ${PAIRING_EXEC}
332347
endif
333348

334349
.PHONY: get-and-publish-host-operator
@@ -353,7 +368,7 @@ ifeq ($(DEPLOY_LATEST),true)
353368
${KSCTL_BIN_DIR}ksctl adm install-operator host --kubeconfig "$(or ${KUBECONFIG}, ${HOME}/.kube/config)" --namespace ${HOST_NS} ${KSCTL_INSTALL_TIMEOUT_PARAM} -y
354369
else
355370
@echo "Installing specific version of the host-operator"
356-
scripts/ci/manage-host-operator.sh -po ${PUBLISH_OPERATOR} -io ${INSTALL_OPERATOR} -hn ${HOST_NS} ${HOST_REPO_PATH_PARAM} -ds ${DATE_SUFFIX} -qn ${QUAY_NAMESPACE} ${REG_REPO_PATH_PARAM} ${FORCED_TAG_PARAM}
371+
scripts/ci/manage-host-operator.sh -po ${PUBLISH_OPERATOR} -io ${INSTALL_OPERATOR} -hn ${HOST_NS} ${HOST_REPO_PATH_PARAM} -ds ${DATE_SUFFIX} -qn ${QUAY_NAMESPACE} ${REG_REPO_PATH_PARAM} ${FORCED_TAG_PARAM} -pe ${PAIRING_EXEC}
357372
endif
358373

359374
###########################################################

scripts/ci/manage-host-operator.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ user_help () {
88
echo "-io, --install-operator Installs the operator to an OpenShift cluster"
99
echo "-hn, --host-namespace Namespace the operator should be installed to"
1010
echo "-hr, --host-repo-path Path to the host operator repo"
11-
echo "-rr, --reg-repo-path Path to the registation service repo"
11+
echo "-rr, --reg-repo-path Path to the registration service repo"
1212
echo "-ds, --date-suffix Date suffix to be added to some resources that are created"
1313
echo "-ft, --forced-tag Forces a tag to be set to all built images. In the case deployment the tag is used for index image in the created CatalogSource"
14+
echo "-pe, --pairing-exec Binary path to execute the pairing"
1415
echo "-h, --help To show this help text"
1516
echo ""
1617
exit 0
@@ -68,6 +69,11 @@ read_arguments() {
6869
FORCED_TAG=$1
6970
shift
7071
;;
72+
-pe|--pairing-exec)
73+
shift
74+
PAIRING_EXEC=$1
75+
shift
76+
;;
7177
*)
7278
echo "$1 is not a recognized flag!" >> /dev/stderr
7379
user_help

scripts/ci/manage-member-operator.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ user_help () {
1111
echo "-mr, --member-repo-path Path to the member operator repo"
1212
echo "-ds, --date-suffix Date suffix to be added to some resources that are created"
1313
echo "-ft, --forced-tag Forces a tag to be set to all built images. In the case deployment the tag is used for index image in the created CatalogSource"
14+
echo "-pe, --pairing-exec Binary path to execute the pairing"
1415
echo "-h, --help To show this help text"
1516
echo ""
1617
exit 0
@@ -67,6 +68,11 @@ read_arguments() {
6768
FORCED_TAG=$1
6869
shift
6970
;;
71+
-pe|--pairing-exec)
72+
shift
73+
PAIRING_EXEC=$1
74+
shift
75+
;;
7076
*)
7177
echo "$1 is not a recognized flag!" >> /dev/stderr
7278
user_help

scripts/ci/manage-operator.sh

Lines changed: 5 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,13 @@ fi
99
WAS_ALREADY_PAIRED_FILE=/tmp/toolchain_e2e_already_paired
1010

1111
get_repo() {
12-
PAIRED=false
1312
if [[ -z ${PROVIDED_REPOSITORY_PATH} ]]; then
1413
REPOSITORY_PATH="/tmp/codeready-toolchain/${REPOSITORY_NAME}"
15-
rm -rf ${REPOSITORY_PATH}
16-
# clone
17-
git clone https://github.com/codeready-toolchain/${REPOSITORY_NAME}.git ${REPOSITORY_PATH}
18-
19-
pair_repo_if_needed
14+
15+
${PAIRING_EXEC} pair --clone-dir ${REPOSITORY_PATH} --organization codeready-toolchain --repository ${REPOSITORY_NAME}
2016
else
2117
REPOSITORY_PATH=${PROVIDED_REPOSITORY_PATH}
2218
fi
23-
2419
}
2520

2621
set_tags() {
@@ -47,117 +42,11 @@ set_tags() {
4742
push_image() {
4843
GIT_COMMIT_ID=$(git --git-dir=${REPOSITORY_PATH}/.git --work-tree=${REPOSITORY_PATH} rev-parse --short HEAD)
4944
IMAGE_LOC=quay.io/codeready-toolchain/${REPOSITORY_NAME}:${GIT_COMMIT_ID}
50-
if is_provided_or_paired; then
51-
IMAGE_BUILDER=${IMAGE_BUILDER:-"podman"}
52-
make -C ${REPOSITORY_PATH} ${IMAGE_BUILDER}-push QUAY_NAMESPACE=${QUAY_NAMESPACE} IMAGE_TAG=${TAGS}
53-
IMAGE_LOC=quay.io/${QUAY_NAMESPACE}/${REPOSITORY_NAME}:${TAGS}
54-
fi
45+
IMAGE_BUILDER=${IMAGE_BUILDER:-"podman"}
46+
make -C ${REPOSITORY_PATH} ${IMAGE_BUILDER}-push QUAY_NAMESPACE=${QUAY_NAMESPACE} IMAGE_TAG=${TAGS}
47+
IMAGE_LOC=quay.io/${QUAY_NAMESPACE}/${REPOSITORY_NAME}:${TAGS}
5548
}
5649

57-
is_provided_or_paired() {
58-
[[ -n ${PROVIDED_REPOSITORY_PATH} ]] || [[ ${PAIRED} == true ]]
59-
}
60-
61-
pair_repo_if_needed() {
62-
if [[ -n ${GITHUB_ACTIONS} ]]; then
63-
PR_REPO_NAME=${GITHUB_REPOSITORY##*/}
64-
else
65-
PR_REPO_NAME=$(echo ${REPO_NAME} | sed 's/"//g')
66-
fi
67-
68-
69-
if [[ -n "${CI}${CLONEREFS_OPTIONS}" ]] && [[ ${PR_REPO_NAME} == "toolchain-e2e" ]]; then
70-
if [[ -n ${CLONEREFS_OPTIONS} ]]; then
71-
# get branch ref of the fork the PR was created from
72-
AUTHOR_LINK=$(jq -r '.refs[0].pulls[0].author_link' <<< ${CLONEREFS_OPTIONS} | tr -d '[:space:]')
73-
PULL_PULL_SHA=${PULL_PULL_SHA:-$(jq -r '.refs[0].pulls[0].sha' <<< ${CLONEREFS_OPTIONS} | tr -d '[:space:]')}
74-
echo "using author link ${AUTHOR_LINK}"
75-
echo "using pull sha ${PULL_PULL_SHA}"
76-
# get branch ref of the fork the PR was created from
77-
REPO_URL=${AUTHOR_LINK}/toolchain-e2e
78-
echo "branches of ${REPO_URL} - trying to detect the branch name we should use for pairing."
79-
curl ${REPO_URL}.git/info/refs?service=git-upload-pack --output -
80-
GET_BRANCH_NAME=$(curl ${REPO_URL}.git/info/refs?service=git-upload-pack --output - 2>/dev/null | grep -a ${PULL_PULL_SHA} || true)
81-
if [[ $(echo ${GET_BRANCH_NAME} | wc -l) > 1 ]]; then \
82-
echo "################################### ERROR DURING THE E2E TEST SETUP ###################################
83-
There were found more branches with the same latest commit '${PULL_PULL_SHA}' in the repo ${REPO_URL} - see:
84-
85-
${GET_BRANCH_NAME}
86-
87-
It's not possible to detect the correct branch this PR is made for.
88-
Please delete the unrelated branch from your fork and rerun the e2e tests.
89-
Note: If you have already deleted the unrelated branch from your fork, it can take a few hours before the
90-
github api is updated so the e2e tests may still fail with the same error until then.
91-
##########################################################################################################"
92-
exit 1
93-
fi
94-
BRANCH_REF=$(echo ${GET_BRANCH_NAME} | awk '{print $2}')
95-
echo "detected branch ref ${BRANCH_REF}"
96-
# retrieve the branch name
97-
BRANCH_NAME=$(echo ${BRANCH_REF} | awk -F'/' '{print $3}')
98-
else
99-
AUTHOR_LINK=https://github.com/${AUTHOR}
100-
BRANCH_REF=refs/heads/${GITHUB_HEAD_REF}
101-
BRANCH_NAME=${GITHUB_HEAD_REF}
102-
REPO_URL=${AUTHOR_LINK}/toolchain-e2e
103-
fi
104-
105-
if [[ -n "${BRANCH_REF}" ]]; then \
106-
# check if a branch with the same ref exists in the user's fork of ${REPOSITORY_NAME} repo
107-
echo "branches of ${AUTHOR_LINK}/${REPOSITORY_NAME} - checking if there is a branch ${BRANCH_REF} we could pair with."
108-
curl ${AUTHOR_LINK}/${REPOSITORY_NAME}.git/info/refs?service=git-upload-pack --output -
109-
REMOTE_E2E_BRANCH=$(curl ${AUTHOR_LINK}/${REPOSITORY_NAME}.git/info/refs?service=git-upload-pack --output - 2>/dev/null | grep -a "${BRANCH_REF}$" | awk '{print $2}')
110-
echo "branch ref of the user's fork: \"${REMOTE_E2E_BRANCH}\" - if empty then not found"
111-
# check if the branch with the same name exists, if so then merge it with master and use the merge branch, if not then use master \
112-
if [[ -n "${REMOTE_E2E_BRANCH}" ]]; then \
113-
if [[ -f ${WAS_ALREADY_PAIRED_FILE} ]]; then \
114-
echo "#################################### ERROR WHILE TRYING TO PAIR PRs ####################################
115-
There was an error while trying to pair this e2e PR with ${AUTHOR_LINK}/${REPOSITORY_NAME}@${BRANCH_REF}
116-
The reason is that there was already detected a branch from another repo this PR could be paired with - see:
117-
118-
$(cat ${WAS_ALREADY_PAIRED_FILE})
119-
120-
It's not possible to pair a PR with multiple branches from other repositories.
121-
Please delete one of the branches from your fork and rerun the e2e tests
122-
Note: If you have already deleted one of the branches from your fork, it can take a few hours before the
123-
github api is updated so the e2e tests may still fail with the same error until then.
124-
##########################################################################################################"
125-
exit 1
126-
fi
127-
128-
git config --global user.email "devsandbox@redhat.com"
129-
git config --global user.name "KubeSaw"
130-
131-
echo -e "repository: ${AUTHOR_LINK}/${REPOSITORY_NAME} \nbranch: ${BRANCH_NAME}" > ${WAS_ALREADY_PAIRED_FILE}
132-
# add the user's fork as remote repo
133-
git --git-dir=${REPOSITORY_PATH}/.git --work-tree=${REPOSITORY_PATH} remote add external ${AUTHOR_LINK}/${REPOSITORY_NAME}.git
134-
# fetch the branch
135-
git --git-dir=${REPOSITORY_PATH}/.git --work-tree=${REPOSITORY_PATH} fetch external ${BRANCH_REF}
136-
137-
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
138-
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
139-
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
140-
echo ""
141-
echo "The following command will try to merge the paired PR using fast-forward way."
142-
echo "If the command fails, then it means that the paired PR https://github.com/codeready-toolchain/${REPOSITORY_NAME}/ from branch ${BRANCH_NAME}"
143-
echo "is not up-to-date with master and the fast-forward merge cannot be performed."
144-
echo "If this happens, then rebase the PR with the latest changes from master and rerun this GH Actions build (or comment /retest in this PR)."
145-
echo " https://github.com/codeready-toolchain/${REPOSITORY_NAME}/pulls?q=head%3A${BRANCH_NAME}"
146-
echo ""
147-
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
148-
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
149-
# merge the branch with master using fast-forward
150-
git --git-dir=${REPOSITORY_PATH}/.git --work-tree=${REPOSITORY_PATH} merge --ff-only FETCH_HEAD
151-
# print information about the last three commits, so we know what was merged plus some additional context/history
152-
git --git-dir=${REPOSITORY_PATH}/.git --work-tree=${REPOSITORY_PATH} log --ancestry-path HEAD~3..HEAD
153-
154-
PAIRED=true
155-
fi
156-
fi
157-
fi
158-
}
159-
160-
16150
install_operator() {
16251
DISPLAYNAME=$(echo ${OPERATOR_NAME} | tr '-' ' ' | awk '{for (i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) substr($i,2)} 1')
16352

test/e2e/parallel/nstemplatetier_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,6 @@ func TestTierTemplateRevision(t *testing.T) {
479479
Value: "100",
480480
})
481481
})
482-
483482
})
484483

485484
t.Run("when updating one tiertemplate the revisions field should be cleaned up from old entries", func(t *testing.T) {
@@ -517,7 +516,6 @@ func TestTierTemplateRevision(t *testing.T) {
517516
// revisions values should be different compared to the previous ones
518517
assert.NotEqual(t, revisionsBeforeUpdate, updatedTier.Status.Revisions)
519518
})
520-
521519
}
522520

523521
func getTestCRQ(podsCount string) unstructured.Unstructured {

0 commit comments

Comments
 (0)