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

CSI-2625 create driver ci #344

Draft
wants to merge 45 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
1ac05dc
create driver ci
matancarmeli7 Jun 30, 2021
6aff2f7
move env vars place
matancarmeli7 Jul 1, 2021
1fe56d8
add environment variables to yq command
matancarmeli7 Jul 1, 2021
572dddc
show all pods while wating
matancarmeli7 Jul 1, 2021
88672c3
change the images check
matancarmeli7 Jul 1, 2021
0eb3674
add docker-hub command
matancarmeli7 Jul 1, 2021
1e6d6be
not fail on getting the image tags
matancarmeli7 Jul 1, 2021
34f9715
made yq butifule
matancarmeli7 Jul 5, 2021
057884f
change the .bash_profile path
matancarmeli7 Jul 5, 2021
683a5a2
add CSI-3164
matancarmeli7 Jul 7, 2021
90add39
add permissions to edit cr files
matancarmeli7 Jul 8, 2021
364b42b
allow editing cr file
matancarmeli7 Jul 8, 2021
782645f
answer some code review comments
matancarmeli7 Jul 12, 2021
e6a4b96
change the image tag
matancarmeli7 Jul 12, 2021
1ea7d40
change saving driver logs script
matancarmeli7 Jul 12, 2021
605d016
use run_action_on_pod function
matancarmeli7 Jul 12, 2021
ed661c5
fix save logs
matancarmeli7 Jul 12, 2021
12050f8
cahnge the edit of the cr file
matancarmeli7 Jul 12, 2021
c2fba0b
fix some problems
matancarmeli7 Jul 12, 2021
d640b79
create github_actions firectory
matancarmeli7 Jul 12, 2021
31438ff
create github_actions firectory
matancarmeli7 Jul 12, 2021
6d906c0
fix syntax errors in wait for k8s cluster
matancarmeli7 Jul 13, 2021
31d711b
fix is_pod_ready function
matancarmeli7 Jul 13, 2021
0827d76
fix some syntax errors in deploy driver
matancarmeli7 Jul 14, 2021
2ba9b3a
change the node ripository yaml path
matancarmeli7 Jul 14, 2021
36d7a6e
remove cluster setup from driver repository
matancarmeli7 Jul 21, 2021
e3aa5d6
fix get_image_tag_from_branch script path
matancarmeli7 Jul 21, 2021
f854cb0
add build_number env variable
matancarmeli7 Jul 21, 2021
b4300ee
fix setup ci dependencies
matancarmeli7 Jul 21, 2021
7e6c394
change get_image_tags_from_branch script name
matancarmeli7 Jul 26, 2021
684aecc
add commit sha to docker image
matancarmeli7 Jul 27, 2021
1c9a227
change the order in the get branch script
matancarmeli7 Jul 27, 2021
0477825
change stages names
matancarmeli7 Aug 3, 2021
3496a4a
change commit sha parameter
matancarmeli7 Aug 4, 2021
a04194b
Merge branch 'develop' of https://github.com/IBM/ibm-block-csi-driver…
matancarmeli7 Aug 4, 2021
90f3e06
add csiblock1 secret
matancarmeli7 Aug 18, 2021
fb1f865
Merge branch 'develop' into task/CSI-2625_add_another_stage_before_th…
matancarmeli7 Aug 18, 2021
a4b84c1
Merge branch 'develop' into task/CSI-2625_add_another_stage_before_th…
matancarmeli7 Oct 3, 2021
8ff6f1c
fix setup_ci_dependencies script comments
matancarmeli7 Oct 3, 2021
3b3c0b9
add setup_yq.sh file
matancarmeli7 Oct 4, 2021
fadd666
Merge branch 'develop' into task/CSI-2625_add_another_stage_before_th…
matancarmeli7 Oct 31, 2021
cda5430
PR
matancarmeli7 Oct 31, 2021
43aabe1
avoid double assignment
matancarmeli7 Nov 1, 2021
9bc70b5
align setup_ci with operator
matancarmeli7 Nov 2, 2021
a05503f
fix spacing problem
matancarmeli7 Nov 2, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
201 changes: 201 additions & 0 deletions .github/workflows/driver_ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
name: CSI IBM Driver CI
oriyarde marked this conversation as resolved.
Show resolved Hide resolved
oriyarde marked this conversation as resolved.
Show resolved Hide resolved
on:
push:
branches:
- develop
- master
pull_request:
branches:
- develop
- master
jobs:
prepare_env:
name: "prepare env"
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Setup dependencies
run: |
scripts/ci/setup_ci_dependencies.sh
- uses: actions/cache@v2
with:
path: ${{ env.pythonLocation }}
key: ${{ env.pythonLocation }}-${{ hashFiles('dev-requirements.txt') }}
- name: Save dependencies files
uses: actions/upload-artifact@v2
with:
name: ci-dependencies
path: |
/home/runner/.bash_profile
retention-days: 1
- uses: FranzDiebold/github-env-vars-action@v2
CSI-controller-static_code_analysis:
Copy link
Contributor

Choose a reason for hiding this comment

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

image
please choose casing + punctuation convention and align all accordingly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

Choose a reason for hiding this comment

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

and align all with the stage names accordingly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

@oriyarde oriyarde Jul 14, 2021

Choose a reason for hiding this comment

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

let me clarify - e.g. prepare env and Create-cluster are not in the same convention, because of whitespace vs. -, uppercase vs. lowercase, etc...

I personally prefer whitespace over -, but the main point is for all to be aligned.

btw, I know the example yamls dir is currently under a "deploy" dir, but "k8s yamls validation" is not "CSI deployment", it's more "CSI configuration" (the true deployment dir is on the operator side), but I think "k8s yamls validation" is enough

Copy link
Contributor

Choose a reason for hiding this comment

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

the case of the first letter is still not unified in the job "keys".
also it is not the same as in the other PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I aligned all the keys now

Copy link
Contributor

Choose a reason for hiding this comment

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

I still see this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I got it right now, I think I was confused from all the comments

Copy link
Contributor

Choose a reason for hiding this comment

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

perhaps I wasn't specific enough (though I don't think I should link to every relevant line):
I still see this

runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: CSI-controller- static code analysis
Copy link
Contributor

@oriyarde oriyarde Nov 28, 2021

Choose a reason for hiding this comment

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

Suggested change
- name: CSI-controller- static code analysis
- name: CSI-controller: static code analysis

(same for unit testing, etc...)
could you align the names to the ones in the jenkinsfile, as much as possible?
unless you know of an easy way to maintain them in one place

Copy link
Contributor

Choose a reason for hiding this comment

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

this would also mean:
k8s yamls validation should be:
K8s yamls validation (in both files)

run: |
./scripts/run_static_code_analysis.sh
Unit_testing_coverage:
runs-on: ubuntu-latest
name: "Unit testing + coverage ${{ matrix.csiblock-component }}"
strategy:
matrix:
include:
- csiblock-component: controller
command-to-run: "./scripts/run_unitests.sh"
- csiblock-component: node
command-to-run: "make test-xunit-in-container"
steps:
- name: Checkout
uses: actions/checkout@v2
- name: CSI-${{ matrix.csiblock-component }}- Unit testing + coverage
run: |
mkdir -p build/reports && chmod 777 build/reports
$command_to_run `pwd`/build/reports
env:
command_to_run: ${{ matrix.command-to-run }}

CSI-deployment-k8s_yamls_validation:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: CSI-deployment- k8s yamls validation
run: |
./scripts/run_yamlcheck.sh
CSI-Build-and-push-images:
runs-on: ubuntu-latest
needs:
- CSI-controller-static_code_analysis
- Unit_testing_coverage
- CSI-deployment-k8s_yamls_validation
strategy:
matrix:
image_type: ['node', 'controller']
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
oriyarde marked this conversation as resolved.
Show resolved Hide resolved
id: buildx
uses: docker/setup-buildx-action@v1.3.0
- uses: FranzDiebold/github-env-vars-action@v2
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: 'csiblock1'
password: '${{ secrets.CSIBLOCK_DOCKERHUB_PASSWORD }}'
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-${{ matrix.image_type }}
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Create github branch parameter
id: tested_github_branch
run: |
docker_image_branch_tag=`echo $CI_ACTION_REF_NAME| sed 's|/|.|g'`
echo "::set-output name=docker_image_branch_tag::${docker_image_branch_tag}"
- name: Build and push ${{ matrix.image_type }}
uses: docker/build-push-action@v2
with:
context: .
platforms: linux/amd64,linux/ppc64le,linux/s390x
push: true
tags: |
csiblock1/ibm-block-csi-${{ matrix.image_type }}:${{ steps.tested_github_branch.outputs.docker_image_branch_tag }}_${{ github.run_number }}
csiblock1/ibm-block-csi-${{ matrix.image_type }}:${{ steps.tested_github_branch.outputs.docker_image_branch_tag }}
csiblock1/ibm-block-csi-${{ matrix.image_type }}:latest
file: Dockerfile-csi-${{ matrix.image_type }}
cache-from: type=local,src=/tmp/.buildx-${{ matrix.image_type }}
cache-to: type=local,dest=/tmp/.buildx-new-${{ matrix.image_type }}
# Temp fix
# CSI-3164
# https://github.com/docker/build-push-action/issues/252
Copy link
Contributor

Choose a reason for hiding this comment

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

could you check if this is still needed?

# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
[[ -G /tmp/.buildx-${{ matrix.image_type }} ]] && rm -rf /tmp/.buildx-${{ matrix.image_type }}
mv /tmp/.buildx-new-${{ matrix.image_type }} /tmp/.buildx-${{ matrix.image_type }}
outputs:
driver_images_tag: "${{ steps.tested_github_branch.outputs.docker_image_branch_tag }}_${{ github.run_number }}"
oriyarde marked this conversation as resolved.
Show resolved Hide resolved

create-cluster:
runs-on: ubuntu-latest
needs: CSI-Build-and-push-images
env:
csiblock_dockerhub_password: ${{ secrets.CSIBLOCK_DOCKERHUB_PASSWORD }}
controller_repository_for_test: csiblock1/ibm-block-csi-controller
node_repository_for_test: csiblock1/ibm-block-csi-node
operator_image_repository_for_test: csiblock1/ibm-block-csi-operator
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v2
with:
path: driver
- uses: FranzDiebold/github-env-vars-action@v2
- name: Retrieve ci dependencies
uses: actions/download-artifact@v2
with:
name: ci-dependencies
path: /home/runner
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- uses: actions/cache@v2
with:
path: ${{ env.pythonLocation }}
key: ${{ env.pythonLocation }}-${{ hashFiles('dev-requirements.txt') }}
- name: Get the operator github branch
zingero marked this conversation as resolved.
Show resolved Hide resolved
id: operator_github_branch
run: |
driver/scripts/ci/get_operator_github_branch.sh
env:
github_token: ${{ secrets.CSIBLOCK_GITHUB_TOKEN }}
- name: Create k8s Kind Cluster
uses: helm/kind-action@v1.1.0
with:
version: v0.11.1
- name: Wait for k8s cluster to be ready
run: |
driver/scripts/ci/wait_for_k8s_ready.sh
- name: Checkout
uses: actions/checkout@v2
with:
repository: IBM/ibm-block-csi-operator
ref: "${{ steps.operator_github_branch.outputs.operator_branch }}"
path: operator
- name: Deploy ibm block csi driver
run: |
driver/scripts/ci/deploy_driver.sh
env:
driver_images_tag: "${{ needs.CSI-Build-and-push-images.outputs.driver_images_tag }}"
operator_image_tag_for_test: "${{ steps.operator_github_branch.outputs.docker_image_branch_tag }}"
operator_file: "operator/deploy/installer/generated/ibm-block-csi-operator.yaml"
cr_file: "operator/deploy/crds/csi.ibm.com_v1_ibmblockcsi_cr.yaml"
- name: Wait for csi ibm block driver to be ready
run: |
driver/scripts/ci/wait_for_driver_to_be_ready.sh
- name: Save driver pods logs
if: always()
run: |
driver/scripts/ci/save_driver_pods_logs.sh
- name: Upload driver pods logs
if: always()
uses: actions/upload-artifact@v2
with:
name: Driver logs
path: |
/tmp/driver_*.txt
retention-days: 7
oriyarde marked this conversation as resolved.
Show resolved Hide resolved
30 changes: 30 additions & 0 deletions scripts/ci/deploy_driver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash -xel
set +o pipefail

if [ "$operator_image_tag_for_test" == "develop" ]; then
operator_image_tag_for_test=latest
fi
operator_image_for_test=$operator_image_repository_for_test:$operator_image_tag_for_test

kind_node_name=`docker ps --format "{{.Names}}"`
docker exec -i $kind_node_name apt-get update
docker exec -i $kind_node_name apt -y install open-iscsi

cd $(dirname $cr_file)
yq eval ".spec.controller.repository |= env(controller_repository_for_test)" $(basename $cr_file) -i
yq eval ".spec.controller.tag |= env(driver_images_tag)" $(basename $cr_file) -i
yq eval ".spec.node.repository |= env(node_repository_for_test)" $(basename $cr_file) -i
yq eval ".spec.node.tag |= env(driver_images_tag)" $(basename $cr_file) -i
cd -

cd $(dirname $operator_file)
operator_image_in_branch=`yq eval '(.spec.template.spec.containers[0].image | select(. == "*ibmcom*"))' $(basename $operator_file)`
sed -i "s+$operator_image_in_branch+$operator_image_for_test+g" $(basename $operator_file)
cd -

cat $operator_file | grep image:
cat $cr_file | grep repository:
cat $cr_file | grep tag:

kubectl apply -f $operator_file
kubectl apply -f $cr_file
31 changes: 31 additions & 0 deletions scripts/ci/get_operator_github_branch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash -xe
set +o pipefail

does_operator_branch_has_image=false
operator_branch=develop
DOCKER_HUB_USERNAME=csiblock1
DOCKER_HUB_PASSWORD=$csiblock_dockerhub_password
wanted_image_tag=`echo $CI_ACTION_REF_NAME | sed 's|/|.|g'`
oriyarde marked this conversation as resolved.
Show resolved Hide resolved
oriyarde marked this conversation as resolved.
Show resolved Hide resolved
oriyarde marked this conversation as resolved.
Show resolved Hide resolved
export image_tags=`docker-hub tags --orgname csiblock1 --reponame ibm-block-csi-operator --all-pages | grep $wanted_image_tag | awk '{print$2}'`

for tag in $image_tags
do
if [[ "$tag" == "$wanted_image_tag" ]]; then
does_operator_branch_has_image=true
fi
done

if [ $does_operator_branch_has_image == "true" ]; then
operator_branches=`curl -H "Authorization: token $github_token" https://api.github.com/repos/IBM/ibm-block-csi-operator/branches | jq -c '.[]' | jq -r .name`
for branch_name in $operator_branches
do
if [ "$branch_name" == "$CI_ACTION_REF_NAME" ]; then
operator_branch=$CI_ACTION_REF_NAME
oriyarde marked this conversation as resolved.
Show resolved Hide resolved
fi

done
fi

docker_image_branch_tag=`echo $operator_branch| sed 's|/|.|g'`
echo "::set-output name=docker_image_branch_tag::${docker_image_branch_tag}"
echo "::set-output name=operator_branch::${operator_branch}"
9 changes: 9 additions & 0 deletions scripts/ci/save_driver_pods_logs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash -x

kubectl logs $(kubectl get pod -l csi | grep controller | awk '{print$1}') -c ibm-block-csi-controller > /tmp/driver_$(kubectl get pod -l csi | grep controller | awk '{print$1}')_logs.txt
kubectl logs $(kubectl get pod -l csi | grep node | awk '{print$1}') -c ibm-block-csi-node > /tmp/driver_$(kubectl get pod -l csi | grep node | awk '{print$1}')_logs.txt
kubectl logs $(kubectl get pod -l csi | grep operator | awk '{print$1}') > /tmp/driver_$(kubectl get pod -l csi | grep operator | awk '{print$1}')_logs.txt

kubectl describe pod $(kubectl get pod -l csi | grep controller | awk '{print$1}') > /tmp/driver_$(kubectl get pod -l csi | grep controller | awk '{print$1}')_events.txt
kubectl describe pod $(kubectl get pod -l csi | grep node | awk '{print$1}') > /tmp/driver_$(kubectl get pod -l csi | grep node | awk '{print$1}')_events.txt
kubectl describe pod $(kubectl get pod -l csi | grep operator | awk '{print$1}') > /tmp/driver_$(kubectl get pod -l csi | grep operator | awk '{print$1}')_events.txt
oriyarde marked this conversation as resolved.
Show resolved Hide resolved
15 changes: 15 additions & 0 deletions scripts/ci/setup_ci_dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash -xe
set +o pipefail

python -m pip install --upgrade pip docker-hub==2.2.0
echo docker-hub > dev-requirements.txt

cat >>/home/runner/.bash_profile <<'EOL'
yq() {
docker run --rm -e operator_image_for_test=$operator_image_for_test\
-e controller_repository_for_test=$controller_repository_for_test\
-e node_repository_for_test=$node_repository_for_test\
-e driver_images_tag=$driver_images_tag\
-i -v "${PWD}":/workdir mikefarah/yq "$@"
}
EOL
24 changes: 24 additions & 0 deletions scripts/ci/wait_for_driver_to_be_ready.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash -xe
set +o pipefail

driver_is_ready=false
amount_of_seconds_that_driver_pods_are_running=0
amount_of_seconds_that_driver_pods_should_be_running=10
while [ "$(kubectl get pod -A -l csi | grep controller | wc -l)" -eq 0 ]; do
echo "The controller is not deployed"
sleep 1
done
while [ $driver_is_ready == "false" ]; do
if [ "$(kubectl get pod -A -l csi | grep -iv running | grep -iv name | wc -l)" -eq 0 ]; then
((amount_of_seconds_that_driver_pods_are_running=amount_of_seconds_that_driver_pods_are_running+1))
if [ $amount_of_seconds_that_driver_pods_are_running -eq $amount_of_seconds_that_driver_pods_should_be_running ]; then
driver_is_ready=true
fi
else
amount_of_seconds_that_driver_pods_are_running=0
oriyarde marked this conversation as resolved.
Show resolved Hide resolved
fi
kubectl get pod -A -l csi
sleep 1
done
echo Driver is running
kubectl get pod -A -l csi
16 changes: 16 additions & 0 deletions scripts/ci/wait_for_k8s_ready.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash -xe
set +o pipefail

echo "Wait for all the pods to be in running state"
while [ "$(kubectl get pod -A | grep 0/ | grep -iv name | wc -l)" -gt 0 ]; do
echo Some pods did not start thier containers
kubectl get pod -A | grep 0/ | grep -iv name
sleep 5
done
while [ "$(kubectl get pod -A | grep -iv running | grep -iv name | wc -l)" -gt 0 ]; do
echo Some pods are still not in running state
kubectl get pod -A | grep -iv running | grep -iv name
sleep 5
done
echo Cluster is ready
kubectl get pod -A