Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

task CSI-2892/add community checks to operator #157

Draft
wants to merge 55 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
f2952d0
add community checks to operator
matancarmeli7 May 13, 2021
9650ea5
add code review answers
matancarmeli7 May 16, 2021
58a46c1
complete the CI
matancarmeli7 May 18, 2021
135b96f
remove triger on push
matancarmeli7 May 18, 2021
352247c
use the fork way
matancarmeli7 Jun 9, 2021
3ca3975
answer codereview comments
matancarmeli7 Jun 10, 2021
b267d6d
remove sed from create_demo_pr.sh
matancarmeli7 Jun 10, 2021
f9fdda3
move back the sed command to create_pr
matancarmeli7 Jun 10, 2021
218a95a
pass operator_image_in_branch variable
matancarmeli7 Jun 10, 2021
975fc66
passed operator_image_for_test to CI-csi-demo-pr
matancarmeli7 Jun 10, 2021
362c38f
move csv_file variable to CI-csi-demo-pr
matancarmeli7 Jun 10, 2021
3bb0c93
add check and clean stages
matancarmeli7 Jun 10, 2021
89e065e
changed files name
matancarmeli7 Jun 10, 2021
f3959c6
add debug in the ci
matancarmeli7 Jun 10, 2021
c57a0a6
remove debug
matancarmeli7 Jun 10, 2021
4181fe0
add summary check
matancarmeli7 Jun 13, 2021
466059a
add install_ci_dependencies.sh file
matancarmeli7 Jun 13, 2021
aefc113
change fail check
matancarmeli7 Jun 13, 2021
68c5583
remove underscore
matancarmeli7 Jun 13, 2021
5fd4b11
add new line in install_ci_dependencies.sh
matancarmeli7 Jun 13, 2021
f58e6f4
create are_all_tests_were_passed function
matancarmeli7 Jun 14, 2021
ca18f57
add some cache handle
matancarmeli7 Jun 14, 2021
bf9eac4
fix image field in yq
matancarmeli7 Jun 14, 2021
afdc338
move variable to stage env
matancarmeli7 Jun 14, 2021
4584130
ignore error on pr checks
matancarmeli7 Jun 14, 2021
0672ae8
remove operator_image_in_branch variable
matancarmeli7 Jun 14, 2021
7e9d305
add github_build_number env parameter
matancarmeli7 Jun 15, 2021
88bd0a3
moved scripts to community dir
matancarmeli7 Jun 16, 2021
9386785
remove wrong `
matancarmeli7 Jun 16, 2021
5eff30a
call gh_pr_checks_command as variable
matancarmeli7 Jun 16, 2021
c0140d0
changed yq stracture
matancarmeli7 Jun 20, 2021
79bf3dc
removed shell from github actions
matancarmeli7 Jun 21, 2021
c30c381
add parameters to wait_fot_checks_to_start
matancarmeli7 Jun 21, 2021
caef19d
Merge branch 'develop' into task/CSI-2892_cert_community_operator_hub
matancarmeli7 Jun 21, 2021
219b1a2
change while check
matancarmeli7 Jun 30, 2021
28777cf
remove exports
matancarmeli7 Jun 30, 2021
e52e5f9
add loop for editing the csv file
matancarmeli7 Jun 30, 2021
8bf24e1
remove exports
matancarmeli7 Jul 1, 2021
2f2a1bd
eval repo_pr
matancarmeli7 Jul 1, 2021
0b6a6b5
change repo_pr
matancarmeli7 Jul 1, 2021
5f3c8dd
Merge branch 'develop' into task/CSI-2892_cert_community_operator_hub
matancarmeli7 Jul 12, 2021
abff90b
add some tickets
matancarmeli7 Jul 12, 2021
1fcdb33
add more permmisions to edit csv_file
matancarmeli7 Jul 12, 2021
e4b57bf
change wait for checks condition
matancarmeli7 Jul 13, 2021
75f4007
add some functions
matancarmeli7 Aug 4, 2021
c0bd35d
Merge branch 'develop' into task/CSI-2892_cert_community_operator_hub
matancarmeli7 Aug 4, 2021
d40871f
support new way of community operators
matancarmeli7 Aug 4, 2021
e9da769
add cd -
matancarmeli7 Aug 4, 2021
3e2f6d2
change master branch to main
matancarmeli7 Aug 4, 2021
c79479c
Merge branch 'develop' into task/CSI-2892_cert_community_operator_hub
matancarmeli7 Oct 3, 2021
d4a0f6b
remove file from function
matancarmeli7 Oct 3, 2021
a13fab7
copy only the latest csv
matancarmeli7 Oct 3, 2021
613014a
fix image_version
matancarmeli7 Oct 3, 2021
e25ec2b
remove test directory
matancarmeli7 Oct 4, 2021
7ff7b63
change comment on redhat
matancarmeli7 Oct 4, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions .github/workflows/csi_operator_ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Community Operators test
on:
push:
branches:
- develop
- master
pull_request:
branches:
- develop
- master
jobs:
operator_image_build:
name: "set env"
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
outputs:
operator_image_for_test: "ibmcom/ibm-block-csi-operator:latest"

prepare_env:
name: "prepare env"
needs: operator_image_build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup dependencies
run: |
build/ci/community/setup_ci_dependencies.sh
- name: Save dependencies files
uses: actions/upload-artifact@v2
with:
name: gitconfig-file
path: |
/home/runner/.gitconfig
/home/runner/.bash_profile
retention-days: 1
- uses: FranzDiebold/github-env-vars-action@v2
- name: Prepare env
id: environment_setup
run: |
build/ci/community/prepare_env.sh
outputs:
community_operators_path: "${{ steps.environment_setup.outputs.community_operators_path }}"
upstream_community_operators_path: "${{ steps.environment_setup.outputs.upstream_community_operators_path }}"
repository_path: "${{ steps.environment_setup.outputs.repository_path }}"
operator_image_for_test: ${{ needs.operator_image_build.outputs.operator_image_for_test }}
csv_file: ${{ steps.environment_setup.outputs.csv_file }}

CI-csi-demo-pr:
name: "community-operators fork checks"
needs: prepare_env
runs-on: ubuntu-latest
timeout-minutes: 30
env:
original_community_operators_repository: "k8s-operatorhub/community-operators"
original_community_operators_repository_prod: "redhat-openshift-ecosystem/community-operators-prod"
forked_community_operators_repository: "csiblock/community-operators"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please change the forked terminology to fork wherever applicable

forked_community_operators_repository_prod: "csiblock/community-operators-prod"
community_operators_kubernetes_branch: "ibm-block-csi-update-kubernetes-${{ github.run_number }}"
community_operators_openshift_branch: "ibm-block-csi-update-openshift-${{ github.run_number }}"
github_token: ${{ secrets.CSIBLOCK_GITHUB_TOKEN }}
repository_path: ${{ needs.prepare_env.outputs.repository_path }}
operator_image_for_test: ${{ needs.prepare_env.outputs.operator_image_for_test }}
csv_file: ${{ needs.prepare_env.outputs.csv_file }}
github_build_number: ${{ github.run_number }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Retrieve gitconfig file
uses: actions/download-artifact@v2
with:
name: gitconfig-file
path: /home/runner
- name: Create demo PR
run: |
build/ci/community/create_demo_pr.sh
- name: Wait for all demo PR checks to finish
run: |
build/ci/community/wait_demo_pr_checks.sh
- name: Assert all demo PR checks passed
run: |
build/ci/community/check_all_checks.sh
- name: Clean demo PR
if: always()
run: |
build/ci/community/clean_demo_pr.sh
24 changes: 24 additions & 0 deletions build/ci/community/check_all_checks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash -xe
set +o pipefail

# CSI-3172 - run rad hat bot checks
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# CSI-3172 - run rad hat bot checks
# CSI-3172 - run Red Hat bot checks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rad hat would have been a much cooler name for them


did_all_checks_pass(){
community_operators_branch=$1
forked_repository=$2
all_checks_passed=false
if [ "$(gh pr checks $community_operators_branch --repo $forked_repository | grep -iv pass | wc -l)" -eq 0 ]
then
all_checks_passed=true
fi
echo "$all_checks_passed"
}

passed_k8s_checks=$(did_all_checks_pass $community_operators_kubernetes_branch $forked_community_operators_repository)
passed_openshift_checks=$(did_all_checks_pass $community_operators_openshift_branch $forked_community_operators_repository_prod)

if [ $passed_k8s_checks == "false" ] || [ $passed_openshift_checks == "false" ]
then
echo "some test failed :("
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not clear which test failed (nor if more than 1 failed)

exit 1
fi
17 changes: 17 additions & 0 deletions build/ci/community/clean_demo_pr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash -xe
set +o pipefail

print_checks_and_delete_pr(){
community_operators_branch=$1
cluster_kind=$2
forked_repository=$3
repo_pr="gh pr list --repo $forked_repository | grep $community_operators_branch"
if [[ "`eval $repo_pr`" == *"$community_operators_branch"* ]]; then
echo "The $cluster_kind checks:"
gh pr checks $community_operators_branch --repo $forked_repository || true
gh pr close $community_operators_branch --delete-branch --repo $forked_repository
fi
}

print_checks_and_delete_pr $community_operators_kubernetes_branch 'kubernetes' $forked_community_operators_repository
print_checks_and_delete_pr $community_operators_openshift_branch 'openshift' $forked_community_operators_repository_prod
57 changes: 57 additions & 0 deletions build/ci/community/create_demo_pr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash -xel
set +o pipefail

edit_operator_image_in_csv_yaml_file (){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO no need for _file, since it's implied by the yaml

cd $(dirname $csv_file)
chmod 547 $(basename $csv_file)
declare -a operator_image_fields=(
".spec.install.spec.deployments[0].spec.template.spec.containers[0].image"
".metadata.annotations.containerImage"
".spec.relatedImages[0].image"
)
for image_field in "${operator_image_fields[@]}"
do
yq eval "$image_field |= env(operator_image_for_test)" $(basename $csv_file) -i
done
cd -
}

create_demo_pr(){
community_operators_branch=$1
dest_path=$2
cluster_kind=$3
forked_repository=$4
cd $forked_repository-fork
repo_pr="gh pr list --repo $forked_repository | grep $community_operators_branch"
if [[ "`eval $repo_pr`" == *"$community_operators_branch"* ]]; then
gh pr close $community_operators_branch --delete-branch --repo $forked_repository
fi
git checkout main
git checkout -b $community_operators_branch
yes | cp -r $repository_path/deploy/olm-catalog/ibm-block-csi-operator-community/ $dest_path
git add .
git commit --signoff -m "build number $github_build_number $cluster_kind"
git push origin $community_operators_branch
gh pr create --title "IBM Block CSI update $cluster_kind" --repo $forked_repository --base main --head $community_operators_branch --body "pr check"
cd -
}

update_community_operators_fork (){
forked_repository=$1
original_repository=$2
echo $github_token > github_token.txt
gh auth login --with-token < github_token.txt
gh repo fork $original_repository --clone $forked_repository-fork
cd $forked_repository-fork
git remote set-url origin https://csiblock:[email protected]/$forked_repository.git
git fetch upstream
git rebase upstream/main
git push origin main --force
cd -
}

edit_operator_image_in_csv_yaml_file
update_community_operators_fork $forked_community_operators_repository $original_community_operators_repository
update_community_operators_fork $forked_community_operators_repository_prod $original_community_operators_repository_prod
create_demo_pr $community_operators_kubernetes_branch "operators/" "kubernetes" $forked_community_operators_repository
create_demo_pr $community_operators_openshift_branch "operators/" "openshift" $forked_community_operators_repository_prod
15 changes: 15 additions & 0 deletions build/ci/community/prepare_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash -xel
set +o pipefail
operator_package_file_path=deploy/olm-catalog/ibm-block-csi-operator/ibm-block-csi-operator.package.yaml
csv_version=`yq eval .channels[0].currentCSV $operator_package_file_path`
# CSI-3171 - handle non GA versions
csv_version=`echo ${csv_version//ibm-block-csi-operator.v}`
repository_path=~/work/$CI_REPOSITORY_NAME/$CI_REPOSITORY_NAME
csv_file=$repository_path/deploy/olm-catalog/ibm-block-csi-operator-community/$csv_version/manifests/ibm-block-csi-operator.v$csv_version.clusterserviceversion.yaml
upstream_community_operators_path=upstream-community-operators/ibm-block-csi-operator-community/$csv_version
community_operators_path=community-operators/ibm-block-csi-operator-community/$csv_version

echo "::set-output name=upstream_community_operators_path::${upstream_community_operators_path}"
echo "::set-output name=community_operators_path::${community_operators_path}"
echo "::set-output name=repository_path::${repository_path}"
echo "::set-output name=csv_file::${csv_file}"
12 changes: 12 additions & 0 deletions build/ci/community/setup_ci_dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash -xe
set +o pipefail

echo $'yq() {\n docker run --rm -e operator_image_for_test=$operator_image_for_test -i -v "${PWD}":/workdir mikefarah/yq:4 "$@"\n}' >> /home/runner/.bash_profile
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please apply conversations from other PRs where applicable


curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo gpg --dearmor -o /usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt-get update
sudo apt-get install gh

git config --global user.email [email protected]
git config --global user.name csiblock
32 changes: 32 additions & 0 deletions build/ci/community/wait_demo_pr_checks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash -xe
set +o pipefail

gh_pr_checks_command (){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we run the command, I suggest naming the function accordingly:

Suggested change
gh_pr_checks_command (){
run_gh_pr_checks_command (){

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't gh_pr_checks enough?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From this article:

In general, use nouns for classes, verbs for functions, and names that show purpose for variables, attributes and arguments. Avoid (Systems) Hungarian notation in dynamically typed languages since data types can change. Use lower Camel Case for variables and methods. Use Pascal Case for classes and their constructors. Use Screaming Case for constants.

Thus, I suggest using a verb.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the article, though I think in this case, the function is being used more like a command alias than a function.
I think this distinction is important, otherwise we might wrap all the commands we use with a long, low-level-detail named functions of the form run_X_command.
if you still disagree, at least consider the shorter get_pr_checks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_pr_checks sounds great.
If you want to continue with the discussion about naming, I suggest having a session with Arbel.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matancarmeli7 let's use get_pr_checks here

community_operators_branch=$1
forked_repository=$2
gh pr checks $community_operators_branch --repo $forked_repository
}

wait_for_checks_to_start(){
community_operators_branch=$1
forked_repository=$2
while [ `gh_pr_checks_command $community_operators_branch $forked_repository | wc -l` -eq 0 ]; do
sleep 1
done
}
wait_for_checks_to_complete(){
Comment on lines +16 to +17
Copy link
Contributor

@oriyarde oriyarde Aug 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to have a single line break between functions? what is the convention here?
please try to use an IDE that helps with such conventions

community_operators_branch=$1
forked_repository=$2
all_tests_passed=false
repo_pr=`gh pr list --repo $forked_repository | grep $community_operators_branch`
if [[ "$repo_pr" == *"$community_operators_branch"* ]]; then
Comment on lines +21 to +22
Copy link
Contributor

@oriyarde oriyarde Aug 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you give an example for an output of the gh pr list command that would result in the if condition being false?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and what does it mean if there is no pr with the required branch? shouldn't it fail?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in addition, I see this code in at least 3 different places in this PR.
please move it to a common location

wait_for_checks_to_start $community_operators_branch $forked_repository
test_summary="gh_pr_checks_command $community_operators_branch $forked_repository | grep -i summary"
while [[ ! "`eval $test_summary`" =~ "pass" ]] && [[ ! "`eval $test_summary`" =~ "fail" ]]; do
sleep 1
done
fi
}

wait_for_checks_to_complete $community_operators_kubernetes_branch $forked_community_operators_repository
wait_for_checks_to_complete $community_operators_openshift_branch $forked_community_operators_repository_prod