From 1ac05dc4a69a10ea892e68b73c6df64c493df87b Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Wed, 30 Jun 2021 14:42:09 +0300 Subject: [PATCH 01/41] create driver ci --- .github/workflows/driver_ci.yaml | 184 ++++++++++++++++++++++ scripts/ci/deploy_driver.sh | 30 ++++ scripts/ci/get_operator_github_branch.sh | 32 ++++ scripts/ci/save_driver_pods_logs.sh | 9 ++ scripts/ci/setup_ci_dependencies.sh | 4 + scripts/ci/wait_for_driver_to_be_ready.sh | 24 +++ scripts/ci/wait_for_k8s_ready.sh | 16 ++ 7 files changed, 299 insertions(+) create mode 100644 .github/workflows/driver_ci.yaml create mode 100755 scripts/ci/deploy_driver.sh create mode 100755 scripts/ci/get_operator_github_branch.sh create mode 100755 scripts/ci/save_driver_pods_logs.sh create mode 100755 scripts/ci/setup_ci_dependencies.sh create mode 100755 scripts/ci/wait_for_driver_to_be_ready.sh create mode 100755 scripts/ci/wait_for_k8s_ready.sh diff --git a/.github/workflows/driver_ci.yaml b/.github/workflows/driver_ci.yaml new file mode 100644 index 000000000..2d95bebc9 --- /dev/null +++ b/.github/workflows/driver_ci.yaml @@ -0,0 +1,184 @@ +name: CSI IBM Driver CI +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: Setup dependencies + run: | + scripts/ci/setup_ci_dependencies.sh + - 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: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: CSI-controller- static code analysis + 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 + 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 + # https://github.com/docker/build-push-action/issues/252 + # 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 }}" + + 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: Get the operator github branch + 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 \ No newline at end of file diff --git a/scripts/ci/deploy_driver.sh b/scripts/ci/deploy_driver.sh new file mode 100755 index 000000000..88dc45c74 --- /dev/null +++ b/scripts/ci/deploy_driver.sh @@ -0,0 +1,30 @@ +#!/bin/bash -xel +set +o pipefail + +if [ "$driver_images_tag" == "develop" ]; then + driver_images_tag=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 diff --git a/scripts/ci/get_operator_github_branch.sh b/scripts/ci/get_operator_github_branch.sh new file mode 100755 index 000000000..092c07c7b --- /dev/null +++ b/scripts/ci/get_operator_github_branch.sh @@ -0,0 +1,32 @@ +#!/bin/bash -xe +set +o pipefail + +does_operator_branch_has_image=false +operator_branch=develop + +token=`curl -X POST -H "Content-Type: application/json" -d '{"username": "csiblock1", "password": "'$csiblock_dockerhub_password'"}' https://hub.docker.com/v2/users/login | jq .token` +token=`echo ${token//\"}` +image_tags=`curl -s -H "Authorization: JWT ${token}" https://hub.docker.com/v2/namespaces/csiblock1/repositories/ibm-block-csi-operator/images | jq .results[0] | jq .tags | jq -c '.[]' | jq .tag` +for tag in $image_tags +do + tag=`echo ${tag//\"}` + if [ "$tag" == `echo $CI_ACTION_REF_NAME | sed 's|/|.|g'` ]; 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 + 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}" diff --git a/scripts/ci/save_driver_pods_logs.sh b/scripts/ci/save_driver_pods_logs.sh new file mode 100755 index 000000000..8c7e31db2 --- /dev/null +++ b/scripts/ci/save_driver_pods_logs.sh @@ -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 diff --git a/scripts/ci/setup_ci_dependencies.sh b/scripts/ci/setup_ci_dependencies.sh new file mode 100755 index 000000000..26e156072 --- /dev/null +++ b/scripts/ci/setup_ci_dependencies.sh @@ -0,0 +1,4 @@ +#!/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 diff --git a/scripts/ci/wait_for_driver_to_be_ready.sh b/scripts/ci/wait_for_driver_to_be_ready.sh new file mode 100755 index 000000000..e0c502912 --- /dev/null +++ b/scripts/ci/wait_for_driver_to_be_ready.sh @@ -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 + fi + kubectl get pod -A -l csi | grep -iv running | grep -iv name + sleep 1 +done +echo Driver is running +kubectl get pod -A -l csi diff --git a/scripts/ci/wait_for_k8s_ready.sh b/scripts/ci/wait_for_k8s_ready.sh new file mode 100755 index 000000000..52287e007 --- /dev/null +++ b/scripts/ci/wait_for_k8s_ready.sh @@ -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 From 6aff2f7c9c3a67c238b883453802b3f3a8952b75 Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Thu, 1 Jul 2021 09:59:49 +0300 Subject: [PATCH 02/41] move env vars place --- .github/workflows/driver_ci.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/driver_ci.yaml b/.github/workflows/driver_ci.yaml index 2d95bebc9..c8f6ba78d 100644 --- a/.github/workflows/driver_ci.yaml +++ b/.github/workflows/driver_ci.yaml @@ -125,9 +125,6 @@ jobs: 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 @@ -167,6 +164,9 @@ jobs: 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" + 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 - name: Wait for csi ibm block driver to be ready run: | driver/scripts/ci/wait_for_driver_to_be_ready.sh From 1fe56d83645277296338a5b82eb1a805080e166c Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Thu, 1 Jul 2021 11:00:23 +0300 Subject: [PATCH 03/41] add environment variables to yq command --- .github/workflows/driver_ci.yaml | 6 +++--- scripts/ci/setup_ci_dependencies.sh | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/driver_ci.yaml b/.github/workflows/driver_ci.yaml index c8f6ba78d..2d95bebc9 100644 --- a/.github/workflows/driver_ci.yaml +++ b/.github/workflows/driver_ci.yaml @@ -125,6 +125,9 @@ jobs: 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 @@ -164,9 +167,6 @@ jobs: 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" - 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 - name: Wait for csi ibm block driver to be ready run: | driver/scripts/ci/wait_for_driver_to_be_ready.sh diff --git a/scripts/ci/setup_ci_dependencies.sh b/scripts/ci/setup_ci_dependencies.sh index 26e156072..fa4dabf9d 100755 --- a/scripts/ci/setup_ci_dependencies.sh +++ b/scripts/ci/setup_ci_dependencies.sh @@ -1,4 +1,4 @@ #!/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 +echo $'yq() {\n 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:4 "$@"\n}' >> /home/runner/.bash_profile From 572dddc202e1b30801e4a305f30768661c64c28c Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Thu, 1 Jul 2021 11:35:31 +0300 Subject: [PATCH 04/41] show all pods while wating --- scripts/ci/wait_for_driver_to_be_ready.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ci/wait_for_driver_to_be_ready.sh b/scripts/ci/wait_for_driver_to_be_ready.sh index e0c502912..7f9dbe434 100755 --- a/scripts/ci/wait_for_driver_to_be_ready.sh +++ b/scripts/ci/wait_for_driver_to_be_ready.sh @@ -17,7 +17,7 @@ while [ $driver_is_ready == "false" ]; do else amount_of_seconds_that_driver_pods_are_running=0 fi - kubectl get pod -A -l csi | grep -iv running | grep -iv name + kubectl get pod -A -l csi sleep 1 done echo Driver is running From 88672c30e48adc00115d63003c7090d3a5c045c4 Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Thu, 1 Jul 2021 16:51:05 +0300 Subject: [PATCH 05/41] change the images check --- scripts/ci/deploy_driver.sh | 4 ++-- scripts/ci/get_operator_github_branch.sh | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/ci/deploy_driver.sh b/scripts/ci/deploy_driver.sh index 88dc45c74..8e42ccca4 100755 --- a/scripts/ci/deploy_driver.sh +++ b/scripts/ci/deploy_driver.sh @@ -1,8 +1,8 @@ #!/bin/bash -xel set +o pipefail -if [ "$driver_images_tag" == "develop" ]; then - driver_images_tag=latest +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 diff --git a/scripts/ci/get_operator_github_branch.sh b/scripts/ci/get_operator_github_branch.sh index 092c07c7b..6183d1fae 100755 --- a/scripts/ci/get_operator_github_branch.sh +++ b/scripts/ci/get_operator_github_branch.sh @@ -3,19 +3,19 @@ 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'` -token=`curl -X POST -H "Content-Type: application/json" -d '{"username": "csiblock1", "password": "'$csiblock_dockerhub_password'"}' https://hub.docker.com/v2/users/login | jq .token` -token=`echo ${token//\"}` -image_tags=`curl -s -H "Authorization: JWT ${token}" https://hub.docker.com/v2/namespaces/csiblock1/repositories/ibm-block-csi-operator/images | jq .results[0] | jq .tags | jq -c '.[]' | jq .tag` +does_docker_image_has_tag=false +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 - tag=`echo ${tag//\"}` - if [ "$tag" == `echo $CI_ACTION_REF_NAME | sed 's|/|.|g'` ]; then - does_operator_branch_has_image=true + if [[ "$tag" == "$wanted_image_tag" ]]; then + does_docker_image_has_tag=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 From 0eb3674f4ca5eeb283744073ead1779bacccce09 Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Thu, 1 Jul 2021 16:58:26 +0300 Subject: [PATCH 06/41] add docker-hub command --- .github/workflows/driver_ci.yaml | 16 ++++++++++++++++ scripts/ci/setup_ci_dependencies.sh | 3 +++ 2 files changed, 19 insertions(+) diff --git a/.github/workflows/driver_ci.yaml b/.github/workflows/driver_ci.yaml index 2d95bebc9..9e1e96f4d 100644 --- a/.github/workflows/driver_ci.yaml +++ b/.github/workflows/driver_ci.yaml @@ -15,9 +15,17 @@ jobs: 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: @@ -140,6 +148,14 @@ jobs: 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 id: operator_github_branch run: | diff --git a/scripts/ci/setup_ci_dependencies.sh b/scripts/ci/setup_ci_dependencies.sh index fa4dabf9d..2a62b0323 100755 --- a/scripts/ci/setup_ci_dependencies.sh +++ b/scripts/ci/setup_ci_dependencies.sh @@ -1,4 +1,7 @@ #!/bin/bash -xe set +o pipefail +python -m pip install --upgrade pip docker-hub==2.2.0 +echo yq > dev-requirements.txt + echo $'yq() {\n 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:4 "$@"\n}' >> /home/runner/.bash_profile From 1e6d6be3db5c3a164eb7f79d10f060a53e6597a5 Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Thu, 1 Jul 2021 17:41:28 +0300 Subject: [PATCH 07/41] not fail on getting the image tags --- scripts/ci/get_operator_github_branch.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/ci/get_operator_github_branch.sh b/scripts/ci/get_operator_github_branch.sh index 6183d1fae..a91013408 100755 --- a/scripts/ci/get_operator_github_branch.sh +++ b/scripts/ci/get_operator_github_branch.sh @@ -6,13 +6,12 @@ operator_branch=develop DOCKER_HUB_USERNAME=csiblock1 DOCKER_HUB_PASSWORD=$csiblock_dockerhub_password wanted_image_tag=`echo $CI_ACTION_REF_NAME | sed 's|/|.|g'` +export image_tags=`docker-hub tags --orgname csiblock1 --reponame ibm-block-csi-operator --all-pages | grep $wanted_image_tag | awk '{print$2}'` -does_docker_image_has_tag=false -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_docker_image_has_tag=true + does_operator_branch_has_image=true fi done From 34f9715387f418846f49ba9952af35f9b19e8ec7 Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Mon, 5 Jul 2021 11:49:31 +0300 Subject: [PATCH 08/41] made yq butifule --- scripts/ci/setup_ci_dependencies.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/ci/setup_ci_dependencies.sh b/scripts/ci/setup_ci_dependencies.sh index 2a62b0323..ef63f7b43 100755 --- a/scripts/ci/setup_ci_dependencies.sh +++ b/scripts/ci/setup_ci_dependencies.sh @@ -2,6 +2,14 @@ set +o pipefail python -m pip install --upgrade pip docker-hub==2.2.0 -echo yq > dev-requirements.txt +echo docker-hub > dev-requirements.txt -echo $'yq() {\n 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:4 "$@"\n}' >> /home/runner/.bash_profile +cat >>/tmp/myconfig.conf <<'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 From 057884fbf55b2a8f982aef28740c142243b24b1f Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Mon, 5 Jul 2021 13:25:17 +0300 Subject: [PATCH 09/41] change the .bash_profile path --- scripts/ci/setup_ci_dependencies.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ci/setup_ci_dependencies.sh b/scripts/ci/setup_ci_dependencies.sh index ef63f7b43..7ff0bd002 100755 --- a/scripts/ci/setup_ci_dependencies.sh +++ b/scripts/ci/setup_ci_dependencies.sh @@ -4,7 +4,7 @@ set +o pipefail python -m pip install --upgrade pip docker-hub==2.2.0 echo docker-hub > dev-requirements.txt -cat >>/tmp/myconfig.conf <<'EOL' +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\ From 683a5a2da78de868553ba6a400aec8d8b78e8c5a Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Wed, 7 Jul 2021 14:36:16 +0300 Subject: [PATCH 10/41] add CSI-3164 --- .github/workflows/driver_ci.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/driver_ci.yaml b/.github/workflows/driver_ci.yaml index 9e1e96f4d..7b7b6b1c7 100644 --- a/.github/workflows/driver_ci.yaml +++ b/.github/workflows/driver_ci.yaml @@ -119,6 +119,7 @@ jobs: 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 # https://github.com/moby/buildkit/issues/1896 - name: Move cache From 90add39efdef423bdc7f4a6cc887395ad3579971 Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Thu, 8 Jul 2021 09:14:50 +0300 Subject: [PATCH 11/41] add permissions to edit cr files --- scripts/ci/deploy_driver.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/ci/deploy_driver.sh b/scripts/ci/deploy_driver.sh index 8e42ccca4..c0021994b 100755 --- a/scripts/ci/deploy_driver.sh +++ b/scripts/ci/deploy_driver.sh @@ -11,10 +11,10 @@ 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 +sudo yq eval ".spec.controller.repository |= env(controller_repository_for_test)" $(basename $cr_file) -i +sudo yq eval ".spec.controller.tag |= env(driver_images_tag)" $(basename $cr_file) -i +sudo yq eval ".spec.node.repository |= env(node_repository_for_test)" $(basename $cr_file) -i +sudo yq eval ".spec.node.tag |= env(driver_images_tag)" $(basename $cr_file) -i cd - cd $(dirname $operator_file) From 364b42bf5f7215c0e1bc9700ead61d9917c44351 Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Thu, 8 Jul 2021 10:05:41 +0300 Subject: [PATCH 12/41] allow editing cr file --- scripts/ci/deploy_driver.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/ci/deploy_driver.sh b/scripts/ci/deploy_driver.sh index c0021994b..99419c8ac 100755 --- a/scripts/ci/deploy_driver.sh +++ b/scripts/ci/deploy_driver.sh @@ -11,10 +11,11 @@ docker exec -i $kind_node_name apt-get update docker exec -i $kind_node_name apt -y install open-iscsi cd $(dirname $cr_file) -sudo yq eval ".spec.controller.repository |= env(controller_repository_for_test)" $(basename $cr_file) -i -sudo yq eval ".spec.controller.tag |= env(driver_images_tag)" $(basename $cr_file) -i -sudo yq eval ".spec.node.repository |= env(node_repository_for_test)" $(basename $cr_file) -i -sudo yq eval ".spec.node.tag |= env(driver_images_tag)" $(basename $cr_file) -i +chmod 777 $(basename $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) From 782645fb69ed3062bf85c0c6634bb0211bded31b Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Mon, 12 Jul 2021 12:16:02 +0300 Subject: [PATCH 13/41] answer some code review comments --- scripts/ci/deploy_driver.sh | 2 +- scripts/ci/wait_for_driver_to_be_ready.sh | 2 +- scripts/ci/wait_for_k8s_ready.sh | 29 +++++++++++++---------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/scripts/ci/deploy_driver.sh b/scripts/ci/deploy_driver.sh index 99419c8ac..403d1002c 100755 --- a/scripts/ci/deploy_driver.sh +++ b/scripts/ci/deploy_driver.sh @@ -11,7 +11,7 @@ docker exec -i $kind_node_name apt-get update docker exec -i $kind_node_name apt -y install open-iscsi cd $(dirname $cr_file) -chmod 777 $(basename $cr_file) +chmod 547 $(basename $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 diff --git a/scripts/ci/wait_for_driver_to_be_ready.sh b/scripts/ci/wait_for_driver_to_be_ready.sh index 7f9dbe434..3c1c70421 100755 --- a/scripts/ci/wait_for_driver_to_be_ready.sh +++ b/scripts/ci/wait_for_driver_to_be_ready.sh @@ -10,7 +10,7 @@ while [ "$(kubectl get pod -A -l csi | grep controller | wc -l)" -eq 0 ]; do 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)) + ((amount_of_seconds_that_driver_pods_are_running++)) 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 diff --git a/scripts/ci/wait_for_k8s_ready.sh b/scripts/ci/wait_for_k8s_ready.sh index 52287e007..9293345b0 100755 --- a/scripts/ci/wait_for_k8s_ready.sh +++ b/scripts/ci/wait_for_k8s_ready.sh @@ -1,16 +1,21 @@ #!/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 +is_kubernetes_cluster_ready (){ + pods=`kubectl get pods -A | awk '{print$3}' | grep -iv ready` + all_the_containers_are_runninig=true + for pod in $pods; do + running_containers=`echo $pod | awk -F / '{print$1}'` + wanted_containers=`echo $pod | awk -F / '{print$2}'` + if [ $running_containers != $wanted_containers ]; then + all_the_containers_are_runninig=false + break + fi + done + echo $all_the_containers_are_runninig +} + +while [[ `is_kubernetes_cluster_ready` == "false" ]]; do + kubectl get pods -A done -echo Cluster is ready -kubectl get pod -A + From e6a4b96cb3b2893a92c9e3ac96f13abf20b2c02e Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Mon, 12 Jul 2021 13:32:02 +0300 Subject: [PATCH 14/41] change the image tag --- .github/workflows/driver_ci.yaml | 19 +++++++++++++------ scripts/ci/get_operator_github_branch.sh | 11 ++++++----- scripts/ci/save_driver_pods_logs.sh | 22 ++++++++++++++++------ scripts/ci/setup_ci_dependencies.sh | 5 +++++ scripts/ci/wait_for_driver_to_be_ready.sh | 10 +++++----- 5 files changed, 45 insertions(+), 22 deletions(-) diff --git a/.github/workflows/driver_ci.yaml b/.github/workflows/driver_ci.yaml index 7b7b6b1c7..e8c022c05 100644 --- a/.github/workflows/driver_ci.yaml +++ b/.github/workflows/driver_ci.yaml @@ -1,4 +1,4 @@ -name: CSI IBM Driver CI +name: Driver Build on: push: branches: @@ -9,7 +9,7 @@ on: - develop - master jobs: - prepare_env: + Prepare_env: name: "prepare env" runs-on: ubuntu-latest steps: @@ -20,6 +20,7 @@ jobs: with: python-version: '3.x' - name: Setup dependencies + id: setup_dependencies run: | scripts/ci/setup_ci_dependencies.sh - uses: actions/cache@v2 @@ -34,6 +35,9 @@ jobs: /home/runner/.bash_profile retention-days: 1 - uses: FranzDiebold/github-env-vars-action@v2 + outputs: + image_version: "${{ steps.setup_dependencies.outputs.image_version }}" + CSI-controller-static_code_analysis: runs-on: ubuntu-latest steps: @@ -42,6 +46,7 @@ jobs: - name: CSI-controller- static code analysis run: | ./scripts/run_static_code_analysis.sh + Unit_testing_coverage: runs-on: ubuntu-latest name: "Unit testing + coverage ${{ matrix.csiblock-component }}" @@ -70,12 +75,14 @@ jobs: - 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 + - Prepare_env strategy: matrix: image_type: ['node', 'controller'] @@ -112,7 +119,7 @@ jobs: 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 }}:${{ needs.Prepare_env.outputs.image_version }}_b${{ github.run_number }}_${{ steps.tested_github_branch.outputs.docker_image_branch_tag }} 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 }} @@ -127,9 +134,9 @@ jobs: [[ -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 }}" + driver_images_tag: "${{ needs.Prepare_env.outputs.image_version }}_b${{ github.run_number }}_${{ steps.tested_github_branch.outputs.docker_image_branch_tag }}" - create-cluster: + Create-cluster: runs-on: ubuntu-latest needs: CSI-Build-and-push-images env: @@ -198,4 +205,4 @@ jobs: name: Driver logs path: | /tmp/driver_*.txt - retention-days: 7 \ No newline at end of file + retention-days: 7 diff --git a/scripts/ci/get_operator_github_branch.sh b/scripts/ci/get_operator_github_branch.sh index a91013408..c8e5fc5ee 100755 --- a/scripts/ci/get_operator_github_branch.sh +++ b/scripts/ci/get_operator_github_branch.sh @@ -5,12 +5,13 @@ 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'` -export image_tags=`docker-hub tags --orgname csiblock1 --reponame ibm-block-csi-operator --all-pages | grep $wanted_image_tag | awk '{print$2}'` +triggering_branch=$CI_ACTION_REF_NAME +target_image_tag=`echo $triggering_branch | sed 's|/|.|g'` +export image_tags=`docker-hub tags --orgname csiblock1 --reponame ibm-block-csi-operator --all-pages | grep $target_image_tag | awk '{print$2}'` for tag in $image_tags do - if [[ "$tag" == "$wanted_image_tag" ]]; then + if [[ "$tag" == "$target_image_tag" ]]; then does_operator_branch_has_image=true fi done @@ -19,8 +20,8 @@ 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 + if [ "$branch_name" == "$triggering_branch" ]; then + operator_branch=$triggering_branch fi done diff --git a/scripts/ci/save_driver_pods_logs.sh b/scripts/ci/save_driver_pods_logs.sh index 8c7e31db2..39c982c14 100755 --- a/scripts/ci/save_driver_pods_logs.sh +++ b/scripts/ci/save_driver_pods_logs.sh @@ -1,9 +1,19 @@ #!/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 +get_pod_logs_or_events (){ + pod_name=$1 + information_type=$2 + kubectl $information_type $(kubectl get pod -l csi | grep $pod_name | awk '{print$1}') -c ibm-block-csi-$pod_name > /tmp/driver_$(kubectl get pod -l csi | grep $pod_name | awk '{print$1}')_$information_type.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 +declare -a pod_types=( + "node" + "controller" + "operator" +) + +for pod_type in "${pod_types[@]}" +do + get_pod_logs_or_events $pod_type logs + get_pod_logs_or_events $pod_type describe +done diff --git a/scripts/ci/setup_ci_dependencies.sh b/scripts/ci/setup_ci_dependencies.sh index 7ff0bd002..cdfe78151 100755 --- a/scripts/ci/setup_ci_dependencies.sh +++ b/scripts/ci/setup_ci_dependencies.sh @@ -13,3 +13,8 @@ yq() { -i -v "${PWD}":/workdir mikefarah/yq "$@" } EOL + +source /home/runner/.bash_profile +cd common +image_version=`yq eval .identity.version config.yaml` +echo "::set-output name=image_version::${image_version}" \ No newline at end of file diff --git a/scripts/ci/wait_for_driver_to_be_ready.sh b/scripts/ci/wait_for_driver_to_be_ready.sh index 3c1c70421..fb9e6d580 100755 --- a/scripts/ci/wait_for_driver_to_be_ready.sh +++ b/scripts/ci/wait_for_driver_to_be_ready.sh @@ -2,20 +2,20 @@ 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 +actual_driver_running_time_in_seconds=0 +minimum_driver_running_time_in_seconds=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++)) - if [ $amount_of_seconds_that_driver_pods_are_running -eq $amount_of_seconds_that_driver_pods_should_be_running ]; then + ((actual_driver_running_time_in_seconds++)) + if [ $actual_driver_running_time_in_seconds -eq $minimum_driver_running_time_in_seconds ]; then driver_is_ready=true fi else - amount_of_seconds_that_driver_pods_are_running=0 + actual_driver_running_time_in_seconds=0 fi kubectl get pod -A -l csi sleep 1 From 1ea7d404ef2b5972ebfcfb25ff6fd8cd2eb0ca62 Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Mon, 12 Jul 2021 14:50:02 +0300 Subject: [PATCH 15/41] change saving driver logs script --- scripts/ci/save_driver_pods_logs.sh | 12 +++++++----- scripts/ci/setup_ci_dependencies.sh | 2 +- scripts/ci/wait_for_driver_to_be_ready.sh | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/scripts/ci/save_driver_pods_logs.sh b/scripts/ci/save_driver_pods_logs.sh index 39c982c14..79a249107 100755 --- a/scripts/ci/save_driver_pods_logs.sh +++ b/scripts/ci/save_driver_pods_logs.sh @@ -1,9 +1,11 @@ #!/bin/bash -x -get_pod_logs_or_events (){ +run_action_on_pod (){ pod_name=$1 - information_type=$2 - kubectl $information_type $(kubectl get pod -l csi | grep $pod_name | awk '{print$1}') -c ibm-block-csi-$pod_name > /tmp/driver_$(kubectl get pod -l csi | grep $pod_name | awk '{print$1}')_$information_type.txt + action=$2 + extra_args=$3 + get_all_pods_by_type="kubectl get pod -l csi | grep $pod_name | awk '{print$1}'" + kubectl $action $($get_all_pods_by_type) $extra_args -c ibm-block-csi-$pod_name > /tmp/driver_$($get_all_pods_by_type)_$action.txt } declare -a pod_types=( @@ -14,6 +16,6 @@ declare -a pod_types=( for pod_type in "${pod_types[@]}" do - get_pod_logs_or_events $pod_type logs - get_pod_logs_or_events $pod_type describe + get_pod_logs_or_events $pod_type logs "-c ibm-block-csi-$pod_name" + get_pod_logs_or_events $pod_type describe "" done diff --git a/scripts/ci/setup_ci_dependencies.sh b/scripts/ci/setup_ci_dependencies.sh index cdfe78151..d21eff42c 100755 --- a/scripts/ci/setup_ci_dependencies.sh +++ b/scripts/ci/setup_ci_dependencies.sh @@ -17,4 +17,4 @@ EOL source /home/runner/.bash_profile cd common image_version=`yq eval .identity.version config.yaml` -echo "::set-output name=image_version::${image_version}" \ No newline at end of file +echo "::set-output name=image_version::${image_version}" diff --git a/scripts/ci/wait_for_driver_to_be_ready.sh b/scripts/ci/wait_for_driver_to_be_ready.sh index fb9e6d580..144444ed3 100755 --- a/scripts/ci/wait_for_driver_to_be_ready.sh +++ b/scripts/ci/wait_for_driver_to_be_ready.sh @@ -10,7 +10,7 @@ while [ "$(kubectl get pod -A -l csi | grep controller | wc -l)" -eq 0 ]; do 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 - ((actual_driver_running_time_in_seconds++)) + ((++actual_driver_running_time_in_seconds)) if [ $actual_driver_running_time_in_seconds -eq $minimum_driver_running_time_in_seconds ]; then driver_is_ready=true fi From 605d01638246d34f01ec0b8444a9e0b000474573 Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Mon, 12 Jul 2021 15:48:09 +0300 Subject: [PATCH 16/41] use run_action_on_pod function --- scripts/ci/save_driver_pods_logs.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/ci/save_driver_pods_logs.sh b/scripts/ci/save_driver_pods_logs.sh index 79a249107..1cb557aa3 100755 --- a/scripts/ci/save_driver_pods_logs.sh +++ b/scripts/ci/save_driver_pods_logs.sh @@ -16,6 +16,6 @@ declare -a pod_types=( for pod_type in "${pod_types[@]}" do - get_pod_logs_or_events $pod_type logs "-c ibm-block-csi-$pod_name" - get_pod_logs_or_events $pod_type describe "" + run_action_on_pod $pod_type logs "-c ibm-block-csi-$pod_name" + run_action_on_pod $pod_type describe "" done From ed661c54bd6016e50389faef3c7d5aa859ad3c85 Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Mon, 12 Jul 2021 17:22:46 +0300 Subject: [PATCH 17/41] fix save logs --- scripts/ci/save_driver_pods_logs.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts/ci/save_driver_pods_logs.sh b/scripts/ci/save_driver_pods_logs.sh index 1cb557aa3..f56d1d822 100755 --- a/scripts/ci/save_driver_pods_logs.sh +++ b/scripts/ci/save_driver_pods_logs.sh @@ -1,11 +1,16 @@ #!/bin/bash -x +get_all_pods_by_type (){ + pod_name=$1 + kubectl get pod -l csi | grep $pod_name | awk '{print$1}' +} + run_action_on_pod (){ pod_name=$1 action=$2 extra_args=$3 - get_all_pods_by_type="kubectl get pod -l csi | grep $pod_name | awk '{print$1}'" - kubectl $action $($get_all_pods_by_type) $extra_args -c ibm-block-csi-$pod_name > /tmp/driver_$($get_all_pods_by_type)_$action.txt + kubectl $action $(get_all_pods_by_type $pod_name) $extra_args > "/tmp/driver_$(get_all_pods_by_type $pod_name)_${action}.txt" + } declare -a pod_types=( @@ -17,5 +22,5 @@ declare -a pod_types=( for pod_type in "${pod_types[@]}" do run_action_on_pod $pod_type logs "-c ibm-block-csi-$pod_name" - run_action_on_pod $pod_type describe "" + run_action_on_pod $pod_type "describe pod" "" done From 12050f86a577c266b104e48e4b9d9d657add1530 Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Mon, 12 Jul 2021 18:24:06 +0300 Subject: [PATCH 18/41] cahnge the edit of the cr file --- scripts/ci/deploy_driver.sh | 14 ++++++++++---- scripts/ci/save_driver_pods_logs.sh | 2 +- scripts/ci/setup_ci_dependencies.sh | 4 +--- scripts/ci/wait_for_k8s_ready.sh | 6 +++--- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/scripts/ci/deploy_driver.sh b/scripts/ci/deploy_driver.sh index 403d1002c..7c02f4149 100755 --- a/scripts/ci/deploy_driver.sh +++ b/scripts/ci/deploy_driver.sh @@ -12,10 +12,16 @@ docker exec -i $kind_node_name apt -y install open-iscsi cd $(dirname $cr_file) chmod 547 $(basename $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 +declare -A cr_image_fields=( + [".spec.controller.repository"]="$controller_repository_for_test" + [".spec.controller.tag"]="$driver_images_tag" + ["node_repository_for_test"]="$node_repository_for_test" + [".spec.node.tag"]="$driver_images_tag" +) +for image_field in ${!cr_image_fields[@]}; do + cr_image_value=${cr_image_fields[${image_field}]} + yq eval "${image_field} |= env(test)" $(basename $cr_file) -i +done cd - cd $(dirname $operator_file) diff --git a/scripts/ci/save_driver_pods_logs.sh b/scripts/ci/save_driver_pods_logs.sh index f56d1d822..1019734df 100755 --- a/scripts/ci/save_driver_pods_logs.sh +++ b/scripts/ci/save_driver_pods_logs.sh @@ -21,6 +21,6 @@ declare -a pod_types=( for pod_type in "${pod_types[@]}" do - run_action_on_pod $pod_type logs "-c ibm-block-csi-$pod_name" + run_action_on_pod $pod_type logs "-c ibm-block-csi-$pod_type" run_action_on_pod $pod_type "describe pod" "" done diff --git a/scripts/ci/setup_ci_dependencies.sh b/scripts/ci/setup_ci_dependencies.sh index d21eff42c..776f87ba8 100755 --- a/scripts/ci/setup_ci_dependencies.sh +++ b/scripts/ci/setup_ci_dependencies.sh @@ -7,9 +7,7 @@ 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\ + -e cr_image_value=$cr_image_value\ -i -v "${PWD}":/workdir mikefarah/yq "$@" } EOL diff --git a/scripts/ci/wait_for_k8s_ready.sh b/scripts/ci/wait_for_k8s_ready.sh index 9293345b0..a6b8fc760 100755 --- a/scripts/ci/wait_for_k8s_ready.sh +++ b/scripts/ci/wait_for_k8s_ready.sh @@ -5,9 +5,9 @@ is_kubernetes_cluster_ready (){ pods=`kubectl get pods -A | awk '{print$3}' | grep -iv ready` all_the_containers_are_runninig=true for pod in $pods; do - running_containers=`echo $pod | awk -F / '{print$1}'` - wanted_containers=`echo $pod | awk -F / '{print$2}'` - if [ $running_containers != $wanted_containers ]; then + running_containers_count=`echo $pod | awk -F / '{print$1}'` + total_containers_count=`echo $pod | awk -F / '{print$2}'` + if [ $running_containers_count != $total_containers_count ]; then all_the_containers_are_runninig=false break fi From c2fba0beeac4f17d5d72d6298cfb8da4511b158b Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Mon, 12 Jul 2021 19:05:07 +0300 Subject: [PATCH 19/41] fix some problems --- scripts/ci/deploy_driver.sh | 2 +- scripts/ci/save_driver_pods_logs.sh | 8 ++++---- scripts/ci/wait_for_k8s_ready.sh | 22 ++++++++++++++++------ 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/scripts/ci/deploy_driver.sh b/scripts/ci/deploy_driver.sh index 7c02f4149..80ff28fff 100755 --- a/scripts/ci/deploy_driver.sh +++ b/scripts/ci/deploy_driver.sh @@ -20,7 +20,7 @@ declare -A cr_image_fields=( ) for image_field in ${!cr_image_fields[@]}; do cr_image_value=${cr_image_fields[${image_field}]} - yq eval "${image_field} |= env(test)" $(basename $cr_file) -i + yq eval "${image_field} |= env(cr_image_value)" $(basename $cr_file) -i done cd - diff --git a/scripts/ci/save_driver_pods_logs.sh b/scripts/ci/save_driver_pods_logs.sh index 1019734df..c565882b3 100755 --- a/scripts/ci/save_driver_pods_logs.sh +++ b/scripts/ci/save_driver_pods_logs.sh @@ -1,15 +1,15 @@ #!/bin/bash -x get_all_pods_by_type (){ - pod_name=$1 - kubectl get pod -l csi | grep $pod_name | awk '{print$1}' + pod_type=$1 + kubectl get pod -l csi | grep $pod_type | awk '{print$1}' } run_action_on_pod (){ - pod_name=$1 + pod_type=$1 action=$2 extra_args=$3 - kubectl $action $(get_all_pods_by_type $pod_name) $extra_args > "/tmp/driver_$(get_all_pods_by_type $pod_name)_${action}.txt" + kubectl $action $(get_all_pods_by_type $pod_type) $extra_args > "/tmp/driver_$(get_all_pods_by_type $pod_type)_${action}.txt" } diff --git a/scripts/ci/wait_for_k8s_ready.sh b/scripts/ci/wait_for_k8s_ready.sh index a6b8fc760..00a981812 100755 --- a/scripts/ci/wait_for_k8s_ready.sh +++ b/scripts/ci/wait_for_k8s_ready.sh @@ -1,21 +1,31 @@ #!/bin/bash -xe set +o pipefail -is_kubernetes_cluster_ready (){ - pods=`kubectl get pods -A | awk '{print$3}' | grep -iv ready` - all_the_containers_are_runninig=true +is_pod_ready (){ + pods=$1 + are_all_pods_ready=false for pod in $pods; do running_containers_count=`echo $pod | awk -F / '{print$1}'` total_containers_count=`echo $pod | awk -F / '{print$2}'` if [ $running_containers_count != $total_containers_count ]; then - all_the_containers_are_runninig=false + are_all_pods_ready=true break fi done - echo $all_the_containers_are_runninig +} + +is_kubernetes_cluster_ready (){ + pods=`kubectl get pods -A | awk '{print$3}' | grep -iv ready` + all_containers_are_running=false + are_all_pods_ready=false + are_all_pods_ready=$(is_pod_ready $pods) + if [[ "$are_all_pods_ready" == "false" ]]: then + all_containers_are_running=true + fi + + echo $all_containers_are_running } while [[ `is_kubernetes_cluster_ready` == "false" ]]; do kubectl get pods -A done - From d640b794327c0c6619f34adfd1d5d3fc5a239a3b Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Mon, 12 Jul 2021 19:19:21 +0300 Subject: [PATCH 20/41] create github_actions firectory --- .github/workflows/driver_ci.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/driver_ci.yaml b/.github/workflows/driver_ci.yaml index e8c022c05..14f65cf0e 100644 --- a/.github/workflows/driver_ci.yaml +++ b/.github/workflows/driver_ci.yaml @@ -22,7 +22,7 @@ jobs: - name: Setup dependencies id: setup_dependencies run: | - scripts/ci/setup_ci_dependencies.sh + scripts/ci/github_actions/driver/setup_ci_dependencies.sh - uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} @@ -167,7 +167,7 @@ jobs: - name: Get the operator github branch id: operator_github_branch run: | - driver/scripts/ci/get_operator_github_branch.sh + driver/scripts/ci/github_actions/driver/get_operator_github_branch.sh env: github_token: ${{ secrets.CSIBLOCK_GITHUB_TOKEN }} - name: Create k8s Kind Cluster @@ -176,7 +176,7 @@ jobs: version: v0.11.1 - name: Wait for k8s cluster to be ready run: | - driver/scripts/ci/wait_for_k8s_ready.sh + driver/scripts/ci/github_actions/driver/wait_for_k8s_ready.sh - name: Checkout uses: actions/checkout@v2 with: @@ -185,7 +185,7 @@ jobs: path: operator - name: Deploy ibm block csi driver run: | - driver/scripts/ci/deploy_driver.sh + driver/scripts/ci/github_actions/driver/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 }}" @@ -193,11 +193,11 @@ jobs: 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 + driver/scripts/ci/github_actions/driver/wait_for_driver_to_be_ready.sh - name: Save driver pods logs if: always() run: | - driver/scripts/ci/save_driver_pods_logs.sh + driver/scripts/ci/github_actions/driver/save_driver_pods_logs.sh - name: Upload driver pods logs if: always() uses: actions/upload-artifact@v2 From 31438ff7e82baf46fc09928cd30d6d4e95706285 Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Mon, 12 Jul 2021 19:19:40 +0300 Subject: [PATCH 21/41] create github_actions firectory --- scripts/ci/{ => github_actions/driver}/deploy_driver.sh | 0 .../ci/{ => github_actions/driver}/get_operator_github_branch.sh | 0 scripts/ci/{ => github_actions/driver}/save_driver_pods_logs.sh | 0 scripts/ci/{ => github_actions/driver}/setup_ci_dependencies.sh | 0 .../ci/{ => github_actions/driver}/wait_for_driver_to_be_ready.sh | 0 scripts/ci/{ => github_actions/driver}/wait_for_k8s_ready.sh | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename scripts/ci/{ => github_actions/driver}/deploy_driver.sh (100%) rename scripts/ci/{ => github_actions/driver}/get_operator_github_branch.sh (100%) rename scripts/ci/{ => github_actions/driver}/save_driver_pods_logs.sh (100%) rename scripts/ci/{ => github_actions/driver}/setup_ci_dependencies.sh (100%) rename scripts/ci/{ => github_actions/driver}/wait_for_driver_to_be_ready.sh (100%) rename scripts/ci/{ => github_actions/driver}/wait_for_k8s_ready.sh (100%) diff --git a/scripts/ci/deploy_driver.sh b/scripts/ci/github_actions/driver/deploy_driver.sh similarity index 100% rename from scripts/ci/deploy_driver.sh rename to scripts/ci/github_actions/driver/deploy_driver.sh diff --git a/scripts/ci/get_operator_github_branch.sh b/scripts/ci/github_actions/driver/get_operator_github_branch.sh similarity index 100% rename from scripts/ci/get_operator_github_branch.sh rename to scripts/ci/github_actions/driver/get_operator_github_branch.sh diff --git a/scripts/ci/save_driver_pods_logs.sh b/scripts/ci/github_actions/driver/save_driver_pods_logs.sh similarity index 100% rename from scripts/ci/save_driver_pods_logs.sh rename to scripts/ci/github_actions/driver/save_driver_pods_logs.sh diff --git a/scripts/ci/setup_ci_dependencies.sh b/scripts/ci/github_actions/driver/setup_ci_dependencies.sh similarity index 100% rename from scripts/ci/setup_ci_dependencies.sh rename to scripts/ci/github_actions/driver/setup_ci_dependencies.sh diff --git a/scripts/ci/wait_for_driver_to_be_ready.sh b/scripts/ci/github_actions/driver/wait_for_driver_to_be_ready.sh similarity index 100% rename from scripts/ci/wait_for_driver_to_be_ready.sh rename to scripts/ci/github_actions/driver/wait_for_driver_to_be_ready.sh diff --git a/scripts/ci/wait_for_k8s_ready.sh b/scripts/ci/github_actions/driver/wait_for_k8s_ready.sh similarity index 100% rename from scripts/ci/wait_for_k8s_ready.sh rename to scripts/ci/github_actions/driver/wait_for_k8s_ready.sh From 6d906c0425992b19d4b22e9046a85db1d8868e45 Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Tue, 13 Jul 2021 09:08:27 +0300 Subject: [PATCH 22/41] fix syntax errors in wait for k8s cluster --- scripts/ci/github_actions/driver/wait_for_k8s_ready.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ci/github_actions/driver/wait_for_k8s_ready.sh b/scripts/ci/github_actions/driver/wait_for_k8s_ready.sh index 00a981812..2a1c5ed4a 100755 --- a/scripts/ci/github_actions/driver/wait_for_k8s_ready.sh +++ b/scripts/ci/github_actions/driver/wait_for_k8s_ready.sh @@ -19,7 +19,7 @@ is_kubernetes_cluster_ready (){ all_containers_are_running=false are_all_pods_ready=false are_all_pods_ready=$(is_pod_ready $pods) - if [[ "$are_all_pods_ready" == "false" ]]: then + if [ $are_all_pods_ready == "false" ]; then all_containers_are_running=true fi From 31d711bc0066f8a90482024c94f8ec53aa3a186d Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Tue, 13 Jul 2021 10:43:59 +0300 Subject: [PATCH 23/41] fix is_pod_ready function --- scripts/ci/github_actions/driver/wait_for_k8s_ready.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/ci/github_actions/driver/wait_for_k8s_ready.sh b/scripts/ci/github_actions/driver/wait_for_k8s_ready.sh index 2a1c5ed4a..6c5ab42aa 100755 --- a/scripts/ci/github_actions/driver/wait_for_k8s_ready.sh +++ b/scripts/ci/github_actions/driver/wait_for_k8s_ready.sh @@ -2,7 +2,7 @@ set +o pipefail is_pod_ready (){ - pods=$1 + pods=$@ are_all_pods_ready=false for pod in $pods; do running_containers_count=`echo $pod | awk -F / '{print$1}'` @@ -12,6 +12,7 @@ is_pod_ready (){ break fi done + echo $are_all_pods_ready } is_kubernetes_cluster_ready (){ From 0827d76d4a112fdde05d1e4593f3a557bbea8012 Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Wed, 14 Jul 2021 09:34:27 +0300 Subject: [PATCH 24/41] fix some syntax errors in deploy driver --- scripts/ci/github_actions/driver/deploy_driver.sh | 2 +- scripts/ci/github_actions/driver/wait_for_k8s_ready.sh | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/scripts/ci/github_actions/driver/deploy_driver.sh b/scripts/ci/github_actions/driver/deploy_driver.sh index 80ff28fff..8e35db7cb 100755 --- a/scripts/ci/github_actions/driver/deploy_driver.sh +++ b/scripts/ci/github_actions/driver/deploy_driver.sh @@ -15,7 +15,7 @@ chmod 547 $(basename $cr_file) declare -A cr_image_fields=( [".spec.controller.repository"]="$controller_repository_for_test" [".spec.controller.tag"]="$driver_images_tag" - ["node_repository_for_test"]="$node_repository_for_test" + [".node_repository_for_test"]="$node_repository_for_test" [".spec.node.tag"]="$driver_images_tag" ) for image_field in ${!cr_image_fields[@]}; do diff --git a/scripts/ci/github_actions/driver/wait_for_k8s_ready.sh b/scripts/ci/github_actions/driver/wait_for_k8s_ready.sh index 6c5ab42aa..5b918ab80 100755 --- a/scripts/ci/github_actions/driver/wait_for_k8s_ready.sh +++ b/scripts/ci/github_actions/driver/wait_for_k8s_ready.sh @@ -1,7 +1,7 @@ #!/bin/bash -xe set +o pipefail -is_pod_ready (){ +is_pods_ready (){ pods=$@ are_all_pods_ready=false for pod in $pods; do @@ -18,8 +18,7 @@ is_pod_ready (){ is_kubernetes_cluster_ready (){ pods=`kubectl get pods -A | awk '{print$3}' | grep -iv ready` all_containers_are_running=false - are_all_pods_ready=false - are_all_pods_ready=$(is_pod_ready $pods) + are_all_pods_ready=$(is_pods_ready $pods) if [ $are_all_pods_ready == "false" ]; then all_containers_are_running=true fi From 2ba9b3a454da6f8f6ca65ba8b56d5d33e36e1bc6 Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Wed, 14 Jul 2021 13:24:24 +0300 Subject: [PATCH 25/41] change the node ripository yaml path --- .../ci/github_actions/driver/deploy_driver.sh | 30 +++++++++++-------- .../driver/get_operator_github_branch.sh | 6 ++-- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/scripts/ci/github_actions/driver/deploy_driver.sh b/scripts/ci/github_actions/driver/deploy_driver.sh index 8e35db7cb..062a159d1 100755 --- a/scripts/ci/github_actions/driver/deploy_driver.sh +++ b/scripts/ci/github_actions/driver/deploy_driver.sh @@ -10,19 +10,23 @@ 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) -chmod 547 $(basename $cr_file) -declare -A cr_image_fields=( - [".spec.controller.repository"]="$controller_repository_for_test" - [".spec.controller.tag"]="$driver_images_tag" - [".node_repository_for_test"]="$node_repository_for_test" - [".spec.node.tag"]="$driver_images_tag" -) -for image_field in ${!cr_image_fields[@]}; do - cr_image_value=${cr_image_fields[${image_field}]} - yq eval "${image_field} |= env(cr_image_value)" $(basename $cr_file) -i -done -cd - +edit_cr_images (){ + cd $(dirname $cr_file) + chmod 547 $(basename $cr_file) + declare -A cr_image_fields=( + [".spec.controller.repository"]="$controller_repository_for_test" + [".spec.controller.tag"]="$driver_images_tag" + [".spec.node.repository"]="$node_repository_for_test" + [".spec.node.tag"]="$driver_images_tag" + ) + for image_field in ${!cr_image_fields[@]}; do + cr_image_value=${cr_image_fields[${image_field}]} + yq eval "${image_field} |= env(cr_image_value)" $(basename $cr_file) -i + done + cd - +} + +edit_cr_images cd $(dirname $operator_file) operator_image_in_branch=`yq eval '(.spec.template.spec.containers[0].image | select(. == "*ibmcom*"))' $(basename $operator_file)` diff --git a/scripts/ci/github_actions/driver/get_operator_github_branch.sh b/scripts/ci/github_actions/driver/get_operator_github_branch.sh index c8e5fc5ee..444443ca3 100755 --- a/scripts/ci/github_actions/driver/get_operator_github_branch.sh +++ b/scripts/ci/github_actions/driver/get_operator_github_branch.sh @@ -1,7 +1,7 @@ #!/bin/bash -xe set +o pipefail -does_operator_branch_has_image=false +is_operator_branch_image_exists=false operator_branch=develop DOCKER_HUB_USERNAME=csiblock1 DOCKER_HUB_PASSWORD=$csiblock_dockerhub_password @@ -12,11 +12,11 @@ export image_tags=`docker-hub tags --orgname csiblock1 --reponame ibm-block-csi- for tag in $image_tags do if [[ "$tag" == "$target_image_tag" ]]; then - does_operator_branch_has_image=true + is_operator_branch_image_exists=true fi done -if [ $does_operator_branch_has_image == "true" ]; then +if [ $is_operator_branch_image_exists == "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 From 36d7a6eb919ae4650a3ec5c8eafe02075f378a5f Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Wed, 21 Jul 2021 17:22:56 +0300 Subject: [PATCH 26/41] remove cluster setup from driver repository --- .github/workflows/driver_ci.yaml | 90 ++----------------- scripts/ci/build_push_images.sh | 4 +- scripts/ci/get_image_tag_from_branch.sh | 8 ++ .../ci/github_actions/driver/deploy_driver.sh | 41 --------- .../driver/get_operator_github_branch.sh | 32 ------- .../driver/save_driver_pods_logs.sh | 26 ------ .../driver/setup_ci_dependencies.sh | 7 +- .../driver/wait_for_driver_to_be_ready.sh | 24 ----- .../driver/wait_for_k8s_ready.sh | 31 ------- 9 files changed, 24 insertions(+), 239 deletions(-) create mode 100755 scripts/ci/get_image_tag_from_branch.sh delete mode 100755 scripts/ci/github_actions/driver/deploy_driver.sh delete mode 100755 scripts/ci/github_actions/driver/get_operator_github_branch.sh delete mode 100755 scripts/ci/github_actions/driver/save_driver_pods_logs.sh delete mode 100755 scripts/ci/github_actions/driver/wait_for_driver_to_be_ready.sh delete mode 100755 scripts/ci/github_actions/driver/wait_for_k8s_ready.sh diff --git a/.github/workflows/driver_ci.yaml b/.github/workflows/driver_ci.yaml index 14f65cf0e..cd5535f87 100644 --- a/.github/workflows/driver_ci.yaml +++ b/.github/workflows/driver_ci.yaml @@ -19,6 +19,7 @@ jobs: uses: actions/setup-python@v2 with: python-version: '3.x' + - uses: FranzDiebold/github-env-vars-action@v2 - name: Setup dependencies id: setup_dependencies run: | @@ -34,12 +35,13 @@ jobs: path: | /home/runner/.bash_profile retention-days: 1 - - uses: FranzDiebold/github-env-vars-action@v2 outputs: - image_version: "${{ steps.setup_dependencies.outputs.image_version }}" + docker_image_branch_tag: "${{ steps.setup_dependencies.outputs.docker_image_branch_tag }}" + driver_images_tag: "${{ steps.setup_dependencies.outputs.driver_images_tag }}" CSI-controller-static_code_analysis: runs-on: ubuntu-latest + name: "CSI controller static code analysis" steps: - name: Checkout uses: actions/checkout@v2 @@ -69,6 +71,7 @@ jobs: CSI-deployment-k8s_yamls_validation: runs-on: ubuntu-latest + name: "CSI deployment k8s yamls validation" steps: - name: Checkout uses: actions/checkout@v2 @@ -78,6 +81,7 @@ jobs: CSI-Build-and-push-images: runs-on: ubuntu-latest + name: "CSI Build and push images" needs: - CSI-controller-static_code_analysis - Unit_testing_coverage @@ -107,11 +111,6 @@ jobs: 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: @@ -119,8 +118,8 @@ jobs: platforms: linux/amd64,linux/ppc64le,linux/s390x push: true tags: | - csiblock1/ibm-block-csi-${{ matrix.image_type }}:${{ needs.Prepare_env.outputs.image_version }}_b${{ github.run_number }}_${{ steps.tested_github_branch.outputs.docker_image_branch_tag }} - csiblock1/ibm-block-csi-${{ matrix.image_type }}:${{ steps.tested_github_branch.outputs.docker_image_branch_tag }} + csiblock1/ibm-block-csi-${{ matrix.image_type }}:${{ needs.Prepare_env.outputs.driver_images_tag }} + csiblock1/ibm-block-csi-${{ matrix.image_type }}:${{ needs.Prepare_env.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 }} @@ -133,76 +132,3 @@ jobs: 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: "${{ needs.Prepare_env.outputs.image_version }}_b${{ github.run_number }}_${{ steps.tested_github_branch.outputs.docker_image_branch_tag }}" - - 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 - id: operator_github_branch - run: | - driver/scripts/ci/github_actions/driver/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/github_actions/driver/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/github_actions/driver/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/github_actions/driver/wait_for_driver_to_be_ready.sh - - name: Save driver pods logs - if: always() - run: | - driver/scripts/ci/github_actions/driver/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 diff --git a/scripts/ci/build_push_images.sh b/scripts/ci/build_push_images.sh index 9b1f251d5..978590397 100755 --- a/scripts/ci/build_push_images.sh +++ b/scripts/ci/build_push_images.sh @@ -7,8 +7,8 @@ for envi in $MANDATORY_ENVS; do done # Prepare specific tag for the image -branch=`echo $GIT_BRANCH| sed 's|/|.|g'` #not sure if docker accept / in the version -specific_tag="${IMAGE_VERSION}_b${BUILD_NUMBER}_${branch}" +specific_tag=`scripts/ci/get_image_tag_from_branch.sh ${IMAGE_VERSION} ${BUILD_NUMBER} ${GIT_BRANCH}` +specific_tag=`echo $specific_tag | awk '{print$1}'` # Set latest tag only if its from develop branch or master and prepare tags [ "$GIT_BRANCH" = "develop" -o "$GIT_BRANCH" = "origin/develop" -o "$GIT_BRANCH" = "master" ] && tag_latest="true" || tag_latest="false" diff --git a/scripts/ci/get_image_tag_from_branch.sh b/scripts/ci/get_image_tag_from_branch.sh new file mode 100755 index 000000000..475dfd619 --- /dev/null +++ b/scripts/ci/get_image_tag_from_branch.sh @@ -0,0 +1,8 @@ +#!/bin/bash -xe +IMAGE_VERSION=$1 +BUILD_NUMBER=$2 +GIT_BRANCH=$3 +branch=`echo $GIT_BRANCH| sed 's|/|.|g'` #not sure if docker accept / in the version +specific_tag="${IMAGE_VERSION}_b${BUILD_NUMBER}_${branch}" +echo $specific_tag +echo $branch diff --git a/scripts/ci/github_actions/driver/deploy_driver.sh b/scripts/ci/github_actions/driver/deploy_driver.sh deleted file mode 100755 index 062a159d1..000000000 --- a/scripts/ci/github_actions/driver/deploy_driver.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/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 - -edit_cr_images (){ - cd $(dirname $cr_file) - chmod 547 $(basename $cr_file) - declare -A cr_image_fields=( - [".spec.controller.repository"]="$controller_repository_for_test" - [".spec.controller.tag"]="$driver_images_tag" - [".spec.node.repository"]="$node_repository_for_test" - [".spec.node.tag"]="$driver_images_tag" - ) - for image_field in ${!cr_image_fields[@]}; do - cr_image_value=${cr_image_fields[${image_field}]} - yq eval "${image_field} |= env(cr_image_value)" $(basename $cr_file) -i - done - cd - -} - -edit_cr_images - -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 diff --git a/scripts/ci/github_actions/driver/get_operator_github_branch.sh b/scripts/ci/github_actions/driver/get_operator_github_branch.sh deleted file mode 100755 index 444443ca3..000000000 --- a/scripts/ci/github_actions/driver/get_operator_github_branch.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash -xe -set +o pipefail - -is_operator_branch_image_exists=false -operator_branch=develop -DOCKER_HUB_USERNAME=csiblock1 -DOCKER_HUB_PASSWORD=$csiblock_dockerhub_password -triggering_branch=$CI_ACTION_REF_NAME -target_image_tag=`echo $triggering_branch | sed 's|/|.|g'` -export image_tags=`docker-hub tags --orgname csiblock1 --reponame ibm-block-csi-operator --all-pages | grep $target_image_tag | awk '{print$2}'` - -for tag in $image_tags -do - if [[ "$tag" == "$target_image_tag" ]]; then - is_operator_branch_image_exists=true - fi -done - -if [ $is_operator_branch_image_exists == "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" == "$triggering_branch" ]; then - operator_branch=$triggering_branch - 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}" diff --git a/scripts/ci/github_actions/driver/save_driver_pods_logs.sh b/scripts/ci/github_actions/driver/save_driver_pods_logs.sh deleted file mode 100755 index c565882b3..000000000 --- a/scripts/ci/github_actions/driver/save_driver_pods_logs.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash -x - -get_all_pods_by_type (){ - pod_type=$1 - kubectl get pod -l csi | grep $pod_type | awk '{print$1}' -} - -run_action_on_pod (){ - pod_type=$1 - action=$2 - extra_args=$3 - kubectl $action $(get_all_pods_by_type $pod_type) $extra_args > "/tmp/driver_$(get_all_pods_by_type $pod_type)_${action}.txt" - -} - -declare -a pod_types=( - "node" - "controller" - "operator" -) - -for pod_type in "${pod_types[@]}" -do - run_action_on_pod $pod_type logs "-c ibm-block-csi-$pod_type" - run_action_on_pod $pod_type "describe pod" "" -done diff --git a/scripts/ci/github_actions/driver/setup_ci_dependencies.sh b/scripts/ci/github_actions/driver/setup_ci_dependencies.sh index 776f87ba8..805afd81b 100755 --- a/scripts/ci/github_actions/driver/setup_ci_dependencies.sh +++ b/scripts/ci/github_actions/driver/setup_ci_dependencies.sh @@ -15,4 +15,9 @@ EOL source /home/runner/.bash_profile cd common image_version=`yq eval .identity.version config.yaml` -echo "::set-output name=image_version::${image_version}" + +driver_images_tag=`scripts/ci/get_image_tag_from_branch.sh ${image_version} ${build_number} ${CI_ACTION_REF_NAME}` +driver_images_tag=`echo $driver_images_tag | awk '{print$1}'` +docker_image_branch_tag=`echo $driver_images_tag | awk '{print$2}'` +echo "::set-output name=docker_image_branch_tag::${docker_image_branch_tag}" +echo "::set-output name=driver_images_tag::${driver_images_tag}" diff --git a/scripts/ci/github_actions/driver/wait_for_driver_to_be_ready.sh b/scripts/ci/github_actions/driver/wait_for_driver_to_be_ready.sh deleted file mode 100755 index 144444ed3..000000000 --- a/scripts/ci/github_actions/driver/wait_for_driver_to_be_ready.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash -xe -set +o pipefail - -driver_is_ready=false -actual_driver_running_time_in_seconds=0 -minimum_driver_running_time_in_seconds=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 - ((++actual_driver_running_time_in_seconds)) - if [ $actual_driver_running_time_in_seconds -eq $minimum_driver_running_time_in_seconds ]; then - driver_is_ready=true - fi - else - actual_driver_running_time_in_seconds=0 - fi - kubectl get pod -A -l csi - sleep 1 -done -echo Driver is running -kubectl get pod -A -l csi diff --git a/scripts/ci/github_actions/driver/wait_for_k8s_ready.sh b/scripts/ci/github_actions/driver/wait_for_k8s_ready.sh deleted file mode 100755 index 5b918ab80..000000000 --- a/scripts/ci/github_actions/driver/wait_for_k8s_ready.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash -xe -set +o pipefail - -is_pods_ready (){ - pods=$@ - are_all_pods_ready=false - for pod in $pods; do - running_containers_count=`echo $pod | awk -F / '{print$1}'` - total_containers_count=`echo $pod | awk -F / '{print$2}'` - if [ $running_containers_count != $total_containers_count ]; then - are_all_pods_ready=true - break - fi - done - echo $are_all_pods_ready -} - -is_kubernetes_cluster_ready (){ - pods=`kubectl get pods -A | awk '{print$3}' | grep -iv ready` - all_containers_are_running=false - are_all_pods_ready=$(is_pods_ready $pods) - if [ $are_all_pods_ready == "false" ]; then - all_containers_are_running=true - fi - - echo $all_containers_are_running -} - -while [[ `is_kubernetes_cluster_ready` == "false" ]]; do - kubectl get pods -A -done From e3aa5d6613fa9587fed17c1b335ab61f7218973a Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Wed, 21 Jul 2021 17:28:29 +0300 Subject: [PATCH 27/41] fix get_image_tag_from_branch script path --- scripts/ci/github_actions/driver/setup_ci_dependencies.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/ci/github_actions/driver/setup_ci_dependencies.sh b/scripts/ci/github_actions/driver/setup_ci_dependencies.sh index 805afd81b..7fa40c862 100755 --- a/scripts/ci/github_actions/driver/setup_ci_dependencies.sh +++ b/scripts/ci/github_actions/driver/setup_ci_dependencies.sh @@ -15,6 +15,7 @@ EOL source /home/runner/.bash_profile cd common image_version=`yq eval .identity.version config.yaml` +cd - driver_images_tag=`scripts/ci/get_image_tag_from_branch.sh ${image_version} ${build_number} ${CI_ACTION_REF_NAME}` driver_images_tag=`echo $driver_images_tag | awk '{print$1}'` From f854cb0674de8722dbcd37590a3f64d96b294ba6 Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Wed, 21 Jul 2021 17:32:11 +0300 Subject: [PATCH 28/41] add build_number env variable --- .github/workflows/driver_ci.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/driver_ci.yaml b/.github/workflows/driver_ci.yaml index cd5535f87..a88bfc6b7 100644 --- a/.github/workflows/driver_ci.yaml +++ b/.github/workflows/driver_ci.yaml @@ -24,6 +24,8 @@ jobs: id: setup_dependencies run: | scripts/ci/github_actions/driver/setup_ci_dependencies.sh + env: + build_number: "${{ github.run_number }}" - uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} From b4300eed2269d8b51f815bd8e85f0fbbd69734ff Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Wed, 21 Jul 2021 17:42:33 +0300 Subject: [PATCH 29/41] fix setup ci dependencies --- scripts/ci/github_actions/driver/setup_ci_dependencies.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ci/github_actions/driver/setup_ci_dependencies.sh b/scripts/ci/github_actions/driver/setup_ci_dependencies.sh index 7fa40c862..9753cde19 100755 --- a/scripts/ci/github_actions/driver/setup_ci_dependencies.sh +++ b/scripts/ci/github_actions/driver/setup_ci_dependencies.sh @@ -18,7 +18,7 @@ image_version=`yq eval .identity.version config.yaml` cd - driver_images_tag=`scripts/ci/get_image_tag_from_branch.sh ${image_version} ${build_number} ${CI_ACTION_REF_NAME}` -driver_images_tag=`echo $driver_images_tag | awk '{print$1}'` docker_image_branch_tag=`echo $driver_images_tag | awk '{print$2}'` +driver_images_tag=`echo $driver_images_tag | awk '{print$1}'` echo "::set-output name=docker_image_branch_tag::${docker_image_branch_tag}" echo "::set-output name=driver_images_tag::${driver_images_tag}" From 7e6c3947197125ced28694cc40b96e72d39f8140 Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Mon, 26 Jul 2021 11:43:15 +0300 Subject: [PATCH 30/41] change get_image_tags_from_branch script name --- scripts/ci/build_push_images.sh | 4 ++-- scripts/ci/get_image_tag_from_branch.sh | 8 -------- scripts/ci/get_image_tags_from_branch.sh | 8 ++++++++ scripts/ci/github_actions/driver/setup_ci_dependencies.sh | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) delete mode 100755 scripts/ci/get_image_tag_from_branch.sh create mode 100755 scripts/ci/get_image_tags_from_branch.sh diff --git a/scripts/ci/build_push_images.sh b/scripts/ci/build_push_images.sh index 978590397..d00b51d3d 100755 --- a/scripts/ci/build_push_images.sh +++ b/scripts/ci/build_push_images.sh @@ -7,8 +7,8 @@ for envi in $MANDATORY_ENVS; do done # Prepare specific tag for the image -specific_tag=`scripts/ci/get_image_tag_from_branch.sh ${IMAGE_VERSION} ${BUILD_NUMBER} ${GIT_BRANCH}` -specific_tag=`echo $specific_tag | awk '{print$1}'` +tags=`scripts/ci/get_image_tags_from_branch.sh ${IMAGE_VERSION} ${BUILD_NUMBER} ${GIT_BRANCH}` +specific_tag=`echo $tags | awk '{print$1}'` # Set latest tag only if its from develop branch or master and prepare tags [ "$GIT_BRANCH" = "develop" -o "$GIT_BRANCH" = "origin/develop" -o "$GIT_BRANCH" = "master" ] && tag_latest="true" || tag_latest="false" diff --git a/scripts/ci/get_image_tag_from_branch.sh b/scripts/ci/get_image_tag_from_branch.sh deleted file mode 100755 index 475dfd619..000000000 --- a/scripts/ci/get_image_tag_from_branch.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -xe -IMAGE_VERSION=$1 -BUILD_NUMBER=$2 -GIT_BRANCH=$3 -branch=`echo $GIT_BRANCH| sed 's|/|.|g'` #not sure if docker accept / in the version -specific_tag="${IMAGE_VERSION}_b${BUILD_NUMBER}_${branch}" -echo $specific_tag -echo $branch diff --git a/scripts/ci/get_image_tags_from_branch.sh b/scripts/ci/get_image_tags_from_branch.sh new file mode 100755 index 000000000..0e6a587e9 --- /dev/null +++ b/scripts/ci/get_image_tags_from_branch.sh @@ -0,0 +1,8 @@ +#!/bin/bash -xe +IMAGE_VERSION=$1 +BUILD_NUMBER=$2 +GIT_BRANCH=$3 +branch_tag=`echo $GIT_BRANCH| sed 's|/|.|g'` #not sure if docker accept / in the version +specific_tag="${IMAGE_VERSION}_b${BUILD_NUMBER}_${branch_tag}" +echo $specific_tag +echo $branch_tag diff --git a/scripts/ci/github_actions/driver/setup_ci_dependencies.sh b/scripts/ci/github_actions/driver/setup_ci_dependencies.sh index 9753cde19..48c62f46c 100755 --- a/scripts/ci/github_actions/driver/setup_ci_dependencies.sh +++ b/scripts/ci/github_actions/driver/setup_ci_dependencies.sh @@ -17,7 +17,7 @@ cd common image_version=`yq eval .identity.version config.yaml` cd - -driver_images_tag=`scripts/ci/get_image_tag_from_branch.sh ${image_version} ${build_number} ${CI_ACTION_REF_NAME}` +driver_images_tag=`scripts/ci/get_image_tags_from_branch.sh ${image_version} ${build_number} ${CI_ACTION_REF_NAME}` docker_image_branch_tag=`echo $driver_images_tag | awk '{print$2}'` driver_images_tag=`echo $driver_images_tag | awk '{print$1}'` echo "::set-output name=docker_image_branch_tag::${docker_image_branch_tag}" From 684aeccede606c4484230159862d246892e6081e Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Tue, 27 Jul 2021 10:47:59 +0300 Subject: [PATCH 31/41] add commit sha to docker image --- .github/workflows/driver_ci.yaml | 5 ++-- scripts/ci/get_image_tags_from_branch.sh | 3 ++- .../driver/setup_ci_dependencies.sh | 27 +++++++++---------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/.github/workflows/driver_ci.yaml b/.github/workflows/driver_ci.yaml index a88bfc6b7..fc7b570d9 100644 --- a/.github/workflows/driver_ci.yaml +++ b/.github/workflows/driver_ci.yaml @@ -39,7 +39,7 @@ jobs: retention-days: 1 outputs: docker_image_branch_tag: "${{ steps.setup_dependencies.outputs.docker_image_branch_tag }}" - driver_images_tag: "${{ steps.setup_dependencies.outputs.driver_images_tag }}" + driver_images_specific_tag: "${{ steps.setup_dependencies.outputs.driver_images_specific_tag }}" CSI-controller-static_code_analysis: runs-on: ubuntu-latest @@ -120,9 +120,8 @@ jobs: platforms: linux/amd64,linux/ppc64le,linux/s390x push: true tags: | - csiblock1/ibm-block-csi-${{ matrix.image_type }}:${{ needs.Prepare_env.outputs.driver_images_tag }} + csiblock1/ibm-block-csi-${{ matrix.image_type }}:${{ needs.Prepare_env.outputs.driver_images_specific_tag }} csiblock1/ibm-block-csi-${{ matrix.image_type }}:${{ needs.Prepare_env.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 }} diff --git a/scripts/ci/get_image_tags_from_branch.sh b/scripts/ci/get_image_tags_from_branch.sh index 0e6a587e9..1d5df8f71 100755 --- a/scripts/ci/get_image_tags_from_branch.sh +++ b/scripts/ci/get_image_tags_from_branch.sh @@ -2,7 +2,8 @@ IMAGE_VERSION=$1 BUILD_NUMBER=$2 GIT_BRANCH=$3 +commit_sha=$4 branch_tag=`echo $GIT_BRANCH| sed 's|/|.|g'` #not sure if docker accept / in the version -specific_tag="${IMAGE_VERSION}_b${BUILD_NUMBER}_${branch_tag}" +specific_tag="${IMAGE_VERSION}_b${BUILD_NUMBER}_${commit_sha}${branch_tag}" echo $specific_tag echo $branch_tag diff --git a/scripts/ci/github_actions/driver/setup_ci_dependencies.sh b/scripts/ci/github_actions/driver/setup_ci_dependencies.sh index 48c62f46c..f24cbb689 100755 --- a/scripts/ci/github_actions/driver/setup_ci_dependencies.sh +++ b/scripts/ci/github_actions/driver/setup_ci_dependencies.sh @@ -1,24 +1,23 @@ #!/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 cr_image_value=$cr_image_value\ - -i -v "${PWD}":/workdir mikefarah/yq "$@" -} -EOL +python -m pip install --upgrade pip +echo docker-hub==2.2.0 > dev-requirements.txt +pip install -r dev-requirements.txt source /home/runner/.bash_profile cd common image_version=`yq eval .identity.version config.yaml` cd - -driver_images_tag=`scripts/ci/get_image_tags_from_branch.sh ${image_version} ${build_number} ${CI_ACTION_REF_NAME}` -docker_image_branch_tag=`echo $driver_images_tag | awk '{print$2}'` -driver_images_tag=`echo $driver_images_tag | awk '{print$1}'` +GITHUB_SHA=${GITHUB_SHA:0:7}_ +driver_image_tags=`scripts/ci/get_image_tags_from_branch.sh ${image_version} ${build_number} ${CI_ACTION_REF_NAME} ${GITHUB_SHA}` +docker_image_branch_tag=`echo $driver_image_tags | awk '{print$2}'` +driver_images_specific_tag=`echo $driver_image_tags | awk '{print$1}'` + +if [ "$docker_image_branch_tag" == "develop" ]; then + docker_image_branch_tag=latest +fi + echo "::set-output name=docker_image_branch_tag::${docker_image_branch_tag}" -echo "::set-output name=driver_images_tag::${driver_images_tag}" +echo "::set-output name=driver_images_specific_tag::${driver_images_specific_tag}" From 1c9a227fb0c26106d96307a982563943d8c8d446 Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Tue, 27 Jul 2021 11:37:10 +0300 Subject: [PATCH 32/41] change the order in the get branch script --- scripts/ci/build_push_images.sh | 2 +- scripts/ci/get_image_tags_from_branch.sh | 6 +++--- scripts/ci/github_actions/driver/setup_ci_dependencies.sh | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/ci/build_push_images.sh b/scripts/ci/build_push_images.sh index d00b51d3d..3b0851867 100755 --- a/scripts/ci/build_push_images.sh +++ b/scripts/ci/build_push_images.sh @@ -7,7 +7,7 @@ for envi in $MANDATORY_ENVS; do done # Prepare specific tag for the image -tags=`scripts/ci/get_image_tags_from_branch.sh ${IMAGE_VERSION} ${BUILD_NUMBER} ${GIT_BRANCH}` +tags=`scripts/ci/get_image_tags_from_branch.sh ${GIT_BRANCH} ${IMAGE_VERSION} ${BUILD_NUMBER}` specific_tag=`echo $tags | awk '{print$1}'` # Set latest tag only if its from develop branch or master and prepare tags diff --git a/scripts/ci/get_image_tags_from_branch.sh b/scripts/ci/get_image_tags_from_branch.sh index 1d5df8f71..d361ee969 100755 --- a/scripts/ci/get_image_tags_from_branch.sh +++ b/scripts/ci/get_image_tags_from_branch.sh @@ -1,7 +1,7 @@ #!/bin/bash -xe -IMAGE_VERSION=$1 -BUILD_NUMBER=$2 -GIT_BRANCH=$3 +GIT_BRANCH=$1 +IMAGE_VERSION=$2 +BUILD_NUMBER=$3 commit_sha=$4 branch_tag=`echo $GIT_BRANCH| sed 's|/|.|g'` #not sure if docker accept / in the version specific_tag="${IMAGE_VERSION}_b${BUILD_NUMBER}_${commit_sha}${branch_tag}" diff --git a/scripts/ci/github_actions/driver/setup_ci_dependencies.sh b/scripts/ci/github_actions/driver/setup_ci_dependencies.sh index f24cbb689..ed2f10cce 100755 --- a/scripts/ci/github_actions/driver/setup_ci_dependencies.sh +++ b/scripts/ci/github_actions/driver/setup_ci_dependencies.sh @@ -11,7 +11,7 @@ image_version=`yq eval .identity.version config.yaml` cd - GITHUB_SHA=${GITHUB_SHA:0:7}_ -driver_image_tags=`scripts/ci/get_image_tags_from_branch.sh ${image_version} ${build_number} ${CI_ACTION_REF_NAME} ${GITHUB_SHA}` +driver_image_tags=`scripts/ci/get_image_tags_from_branch.sh ${CI_ACTION_REF_NAME} ${image_version} ${build_number} ${GITHUB_SHA}` docker_image_branch_tag=`echo $driver_image_tags | awk '{print$2}'` driver_images_specific_tag=`echo $driver_image_tags | awk '{print$1}'` From 0477825f2488fa0d22fe7cd2576b59a0cd47af86 Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Tue, 3 Aug 2021 11:57:08 +0300 Subject: [PATCH 33/41] change stages names --- .github/workflows/driver_ci.yaml | 10 ++++---- .../driver/setup_ci_dependencies.sh | 25 +++++++++++++------ scripts/ci/jenkins_pipeline_csi | 2 +- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/.github/workflows/driver_ci.yaml b/.github/workflows/driver_ci.yaml index fc7b570d9..4c79f9806 100644 --- a/.github/workflows/driver_ci.yaml +++ b/.github/workflows/driver_ci.yaml @@ -41,7 +41,7 @@ jobs: docker_image_branch_tag: "${{ steps.setup_dependencies.outputs.docker_image_branch_tag }}" driver_images_specific_tag: "${{ steps.setup_dependencies.outputs.driver_images_specific_tag }}" - CSI-controller-static_code_analysis: + CSI_controller_static_code_analysis: runs-on: ubuntu-latest name: "CSI controller static code analysis" steps: @@ -71,7 +71,7 @@ jobs: env: command_to_run: ${{ matrix.command-to-run }} - CSI-deployment-k8s_yamls_validation: + k8s_yamls_validation: runs-on: ubuntu-latest name: "CSI deployment k8s yamls validation" steps: @@ -81,13 +81,13 @@ jobs: run: | ./scripts/run_yamlcheck.sh - CSI-Build-and-push-images: + CSI_Build_and_push_images: runs-on: ubuntu-latest name: "CSI Build and push images" needs: - - CSI-controller-static_code_analysis + - CSI_controller_static_code_analysis - Unit_testing_coverage - - CSI-deployment-k8s_yamls_validation + - k8s_yamls_validation - Prepare_env strategy: matrix: diff --git a/scripts/ci/github_actions/driver/setup_ci_dependencies.sh b/scripts/ci/github_actions/driver/setup_ci_dependencies.sh index ed2f10cce..318587a8a 100755 --- a/scripts/ci/github_actions/driver/setup_ci_dependencies.sh +++ b/scripts/ci/github_actions/driver/setup_ci_dependencies.sh @@ -1,15 +1,26 @@ #!/bin/bash -xe set +o pipefail -python -m pip install --upgrade pip -echo docker-hub==2.2.0 > dev-requirements.txt -pip install -r dev-requirements.txt +install_ci_dependencies (){ + python -m pip install --upgrade pip + echo docker-hub==2.2.0 > dev-requirements.txt + pip install -r dev-requirements.txt +} -source /home/runner/.bash_profile -cd common -image_version=`yq eval .identity.version config.yaml` -cd - +get_driver_version (){ + source /home/runner/.bash_profile + cd common + image_version=`yq eval .identity.version config.yaml` + cd - +} +install_ci_dependencies +cat >>/home/runner/.bash_profile <<'EOL' +yq() { + docker run --rm -i -v "${PWD}":/workdir mikefarah/yq "$@" +} +EOL +get_driver_version GITHUB_SHA=${GITHUB_SHA:0:7}_ driver_image_tags=`scripts/ci/get_image_tags_from_branch.sh ${CI_ACTION_REF_NAME} ${image_version} ${build_number} ${GITHUB_SHA}` docker_image_branch_tag=`echo $driver_image_tags | awk '{print$2}'` diff --git a/scripts/ci/jenkins_pipeline_csi b/scripts/ci/jenkins_pipeline_csi index 6689dbfc5..aaa41bd6a 100644 --- a/scripts/ci/jenkins_pipeline_csi +++ b/scripts/ci/jenkins_pipeline_csi @@ -26,7 +26,7 @@ pipeline { sh 'make test-xunit-in-container' } } - stage ('CSI-deployment: k8s yamls validation') { + stage ('k8s yamls validation') { steps { sh './scripts/run_yamlcheck.sh' } From 3496a4aab2517a4cad963d4b2651d7c34570c513 Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Wed, 4 Aug 2021 09:49:39 +0300 Subject: [PATCH 34/41] change commit sha parameter --- scripts/ci/get_image_tags_from_branch.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/ci/get_image_tags_from_branch.sh b/scripts/ci/get_image_tags_from_branch.sh index d361ee969..7eb8a4d6d 100755 --- a/scripts/ci/get_image_tags_from_branch.sh +++ b/scripts/ci/get_image_tags_from_branch.sh @@ -2,8 +2,8 @@ GIT_BRANCH=$1 IMAGE_VERSION=$2 BUILD_NUMBER=$3 -commit_sha=$4 +COMMIT_HASH=$4 branch_tag=`echo $GIT_BRANCH| sed 's|/|.|g'` #not sure if docker accept / in the version -specific_tag="${IMAGE_VERSION}_b${BUILD_NUMBER}_${commit_sha}${branch_tag}" +specific_tag="${IMAGE_VERSION}_b${BUILD_NUMBER}_${COMMIT_HASH}${branch_tag}" echo $specific_tag echo $branch_tag From 90f3e064b1d29895005eafb8164d5e884e6fe493 Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Wed, 18 Aug 2021 09:41:13 +0300 Subject: [PATCH 35/41] add csiblock1 secret --- .github/workflows/driver_ci.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/driver_ci.yaml b/.github/workflows/driver_ci.yaml index 4c79f9806..645bdb3c3 100644 --- a/.github/workflows/driver_ci.yaml +++ b/.github/workflows/driver_ci.yaml @@ -104,7 +104,7 @@ jobs: - name: Login to DockerHub uses: docker/login-action@v1 with: - username: 'csiblock1' + username: '${{ secrets.CSIBLOCK_DOCKERHUB_USERNAME }}' password: '${{ secrets.CSIBLOCK_DOCKERHUB_PASSWORD }}' - name: Cache Docker layers uses: actions/cache@v2 @@ -120,8 +120,8 @@ jobs: platforms: linux/amd64,linux/ppc64le,linux/s390x push: true tags: | - csiblock1/ibm-block-csi-${{ matrix.image_type }}:${{ needs.Prepare_env.outputs.driver_images_specific_tag }} - csiblock1/ibm-block-csi-${{ matrix.image_type }}:${{ needs.Prepare_env.outputs.docker_image_branch_tag }} + ${{ secrets.CSIBLOCK_DOCKERHUB_USERNAME }}/ibm-block-csi-${{ matrix.image_type }}:${{ needs.Prepare_env.outputs.driver_images_specific_tag }} + ${{ secrets.CSIBLOCK_DOCKERHUB_USERNAME }}/ibm-block-csi-${{ matrix.image_type }}:${{ needs.Prepare_env.outputs.docker_image_branch_tag }} 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 }} From 8ff6f1cae6fc2c326bc1b3d7af10b5a1b82d6fa1 Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Sun, 3 Oct 2021 14:58:38 +0300 Subject: [PATCH 36/41] fix setup_ci_dependencies script comments Signed-off-by: matancarmeli7 --- .../driver/setup_ci_dependencies.sh | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/scripts/ci/github_actions/driver/setup_ci_dependencies.sh b/scripts/ci/github_actions/driver/setup_ci_dependencies.sh index 318587a8a..8439276b6 100755 --- a/scripts/ci/github_actions/driver/setup_ci_dependencies.sh +++ b/scripts/ci/github_actions/driver/setup_ci_dependencies.sh @@ -5,24 +5,22 @@ install_ci_dependencies (){ python -m pip install --upgrade pip echo docker-hub==2.2.0 > dev-requirements.txt pip install -r dev-requirements.txt +cat >>/home/runner/.bash_profile <<'EOL' +yq() { + docker run --rm -i -v "${PWD}":/workdir mikefarah/yq "$@" +} +EOL } get_driver_version (){ source /home/runner/.bash_profile - cd common - image_version=`yq eval .identity.version config.yaml` - cd - + yq eval .identity.version common/config.yaml } install_ci_dependencies -cat >>/home/runner/.bash_profile <<'EOL' -yq() { - docker run --rm -i -v "${PWD}":/workdir mikefarah/yq "$@" -} -EOL -get_driver_version +driver_version=$(get_driver_version) GITHUB_SHA=${GITHUB_SHA:0:7}_ -driver_image_tags=`scripts/ci/get_image_tags_from_branch.sh ${CI_ACTION_REF_NAME} ${image_version} ${build_number} ${GITHUB_SHA}` +driver_image_tags=`scripts/ci/get_image_tags_from_branch.sh ${CI_ACTION_REF_NAME} ${driver_version} ${build_number} ${GITHUB_SHA}` docker_image_branch_tag=`echo $driver_image_tags | awk '{print$2}'` driver_images_specific_tag=`echo $driver_image_tags | awk '{print$1}'` From 3b3c0b9a16f14e4d49be9aa59bd56c9beb8f4881 Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Mon, 4 Oct 2021 09:47:47 +0300 Subject: [PATCH 37/41] add setup_yq.sh file Signed-off-by: matancarmeli7 --- .github/workflows/driver_ci.yaml | 4 ++-- .../ci/github_actions/driver/setup_ci_dependencies.sh | 10 +++------- scripts/ci/github_actions/setup_yq.sh | 8 ++++++++ 3 files changed, 13 insertions(+), 9 deletions(-) create mode 100755 scripts/ci/github_actions/setup_yq.sh diff --git a/.github/workflows/driver_ci.yaml b/.github/workflows/driver_ci.yaml index 645bdb3c3..08790317b 100644 --- a/.github/workflows/driver_ci.yaml +++ b/.github/workflows/driver_ci.yaml @@ -10,7 +10,7 @@ on: - master jobs: Prepare_env: - name: "prepare env" + name: "Prepare env" runs-on: ubuntu-latest steps: - name: Checkout code @@ -18,7 +18,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: '3.x' + python-version: '3.9.7' - uses: FranzDiebold/github-env-vars-action@v2 - name: Setup dependencies id: setup_dependencies diff --git a/scripts/ci/github_actions/driver/setup_ci_dependencies.sh b/scripts/ci/github_actions/driver/setup_ci_dependencies.sh index 8439276b6..092515af6 100755 --- a/scripts/ci/github_actions/driver/setup_ci_dependencies.sh +++ b/scripts/ci/github_actions/driver/setup_ci_dependencies.sh @@ -2,18 +2,14 @@ set +o pipefail install_ci_dependencies (){ - python -m pip install --upgrade pip + scripts/ci/github_actions/setup_yq.sh + python -m pip install --upgrade pip==21.2.4 echo docker-hub==2.2.0 > dev-requirements.txt pip install -r dev-requirements.txt -cat >>/home/runner/.bash_profile <<'EOL' -yq() { - docker run --rm -i -v "${PWD}":/workdir mikefarah/yq "$@" -} -EOL + source /home/runner/.bash_profile } get_driver_version (){ - source /home/runner/.bash_profile yq eval .identity.version common/config.yaml } diff --git a/scripts/ci/github_actions/setup_yq.sh b/scripts/ci/github_actions/setup_yq.sh new file mode 100755 index 000000000..71966a5c2 --- /dev/null +++ b/scripts/ci/github_actions/setup_yq.sh @@ -0,0 +1,8 @@ +#!/bin/bash -xe +set +o pipefail + +cat >>/home/runner/.bash_profile <<'EOL' +yq() { + docker run --rm -i -v "${PWD}":/workdir mikefarah/yq "$@" +} +EOL From cda5430d55a24618c61bc6df7645244e80ec2e5b Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Sun, 31 Oct 2021 16:56:44 +0200 Subject: [PATCH 38/41] PR Signed-off-by: matancarmeli7 --- .github/workflows/driver_ci.yaml | 10 +++++----- scripts/ci/build_push_images.sh | 2 +- scripts/ci/get_image_tags_from_branch.sh | 6 +++--- .../ci/github_actions/driver/setup_ci_dependencies.sh | 11 +++++------ 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/.github/workflows/driver_ci.yaml b/.github/workflows/driver_ci.yaml index 08790317b..3a41b72cd 100644 --- a/.github/workflows/driver_ci.yaml +++ b/.github/workflows/driver_ci.yaml @@ -9,7 +9,7 @@ on: - develop - master jobs: - Prepare_env: + prepare_env: name: "Prepare env" runs-on: ubuntu-latest steps: @@ -41,7 +41,7 @@ jobs: docker_image_branch_tag: "${{ steps.setup_dependencies.outputs.docker_image_branch_tag }}" driver_images_specific_tag: "${{ steps.setup_dependencies.outputs.driver_images_specific_tag }}" - CSI_controller_static_code_analysis: + csi_controller_static_code_analysis: runs-on: ubuntu-latest name: "CSI controller static code analysis" steps: @@ -51,7 +51,7 @@ jobs: run: | ./scripts/run_static_code_analysis.sh - Unit_testing_coverage: + unit_testing_coverage: runs-on: ubuntu-latest name: "Unit testing + coverage ${{ matrix.csiblock-component }}" strategy: @@ -81,9 +81,9 @@ jobs: run: | ./scripts/run_yamlcheck.sh - CSI_Build_and_push_images: + csi_build_and_push_images: runs-on: ubuntu-latest - name: "CSI Build and push images" + name: "Build and push images" needs: - CSI_controller_static_code_analysis - Unit_testing_coverage diff --git a/scripts/ci/build_push_images.sh b/scripts/ci/build_push_images.sh index 3b0851867..f34cdd9bd 100755 --- a/scripts/ci/build_push_images.sh +++ b/scripts/ci/build_push_images.sh @@ -7,7 +7,7 @@ for envi in $MANDATORY_ENVS; do done # Prepare specific tag for the image -tags=`scripts/ci/get_image_tags_from_branch.sh ${GIT_BRANCH} ${IMAGE_VERSION} ${BUILD_NUMBER}` +tags=`scripts/ci/get_image_tags_from_branch.sh ${GIT_BRANCH} ${IMAGE_VERSION} ${BUILD_NUMBER} ${GIT_COMMIT}` specific_tag=`echo $tags | awk '{print$1}'` # Set latest tag only if its from develop branch or master and prepare tags diff --git a/scripts/ci/get_image_tags_from_branch.sh b/scripts/ci/get_image_tags_from_branch.sh index 7eb8a4d6d..5839bb23c 100755 --- a/scripts/ci/get_image_tags_from_branch.sh +++ b/scripts/ci/get_image_tags_from_branch.sh @@ -2,8 +2,8 @@ GIT_BRANCH=$1 IMAGE_VERSION=$2 BUILD_NUMBER=$3 -COMMIT_HASH=$4 -branch_tag=`echo $GIT_BRANCH| sed 's|/|.|g'` #not sure if docker accept / in the version -specific_tag="${IMAGE_VERSION}_b${BUILD_NUMBER}_${COMMIT_HASH}${branch_tag}" +COMMIT_HASH=${4:0:7} +branch_tag=$(echo $GIT_BRANCH| sed 's|/|.|g') #not sure if docker accept / in the version +specific_tag="${IMAGE_VERSION}_b${BUILD_NUMBER}_${COMMIT_HASH}_${branch_tag}" echo $specific_tag echo $branch_tag diff --git a/scripts/ci/github_actions/driver/setup_ci_dependencies.sh b/scripts/ci/github_actions/driver/setup_ci_dependencies.sh index 092515af6..df6aaf05e 100755 --- a/scripts/ci/github_actions/driver/setup_ci_dependencies.sh +++ b/scripts/ci/github_actions/driver/setup_ci_dependencies.sh @@ -3,10 +3,10 @@ set +o pipefail install_ci_dependencies (){ scripts/ci/github_actions/setup_yq.sh + source /home/runner/.bash_profile python -m pip install --upgrade pip==21.2.4 echo docker-hub==2.2.0 > dev-requirements.txt pip install -r dev-requirements.txt - source /home/runner/.bash_profile } get_driver_version (){ @@ -15,14 +15,13 @@ get_driver_version (){ install_ci_dependencies driver_version=$(get_driver_version) -GITHUB_SHA=${GITHUB_SHA:0:7}_ -driver_image_tags=`scripts/ci/get_image_tags_from_branch.sh ${CI_ACTION_REF_NAME} ${driver_version} ${build_number} ${GITHUB_SHA}` -docker_image_branch_tag=`echo $driver_image_tags | awk '{print$2}'` -driver_images_specific_tag=`echo $driver_image_tags | awk '{print$1}'` +driver_image_tags=$(scripts/ci/get_image_tags_from_branch.sh ${CI_ACTION_REF_NAME} ${driver_version} ${build_number} ${GITHUB_SHA}) +driver_images_specific_tag=$(echo $driver_image_tags | awk '{print$1}') +docker_image_branch_tag=$(echo $driver_image_tags | awk '{print$2}') if [ "$docker_image_branch_tag" == "develop" ]; then docker_image_branch_tag=latest fi -echo "::set-output name=docker_image_branch_tag::${docker_image_branch_tag}" echo "::set-output name=driver_images_specific_tag::${driver_images_specific_tag}" +echo "::set-output name=docker_image_branch_tag::${docker_image_branch_tag}" From 43aabe16356f2524262946cbe08519de7eca69f5 Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Mon, 1 Nov 2021 11:57:06 +0200 Subject: [PATCH 39/41] avoid double assignment Signed-off-by: matancarmeli7 --- scripts/ci/github_actions/driver/setup_ci_dependencies.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/ci/github_actions/driver/setup_ci_dependencies.sh b/scripts/ci/github_actions/driver/setup_ci_dependencies.sh index df6aaf05e..ee3f422e5 100755 --- a/scripts/ci/github_actions/driver/setup_ci_dependencies.sh +++ b/scripts/ci/github_actions/driver/setup_ci_dependencies.sh @@ -17,10 +17,11 @@ install_ci_dependencies driver_version=$(get_driver_version) driver_image_tags=$(scripts/ci/get_image_tags_from_branch.sh ${CI_ACTION_REF_NAME} ${driver_version} ${build_number} ${GITHUB_SHA}) driver_images_specific_tag=$(echo $driver_image_tags | awk '{print$1}') -docker_image_branch_tag=$(echo $driver_image_tags | awk '{print$2}') -if [ "$docker_image_branch_tag" == "develop" ]; then +if [ "$CI_ACTION_REF_NAME" == "develop" ]; then docker_image_branch_tag=latest +else + docker_image_branch_tag=$(echo $driver_image_tags | awk '{print$2}') fi echo "::set-output name=driver_images_specific_tag::${driver_images_specific_tag}" From 9bc70b5ade8f8325de26de0504e6a998edd986d5 Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Tue, 2 Nov 2021 09:39:24 +0200 Subject: [PATCH 40/41] align setup_ci with operator Signed-off-by: matancarmeli7 --- .github/workflows/driver_ci.yaml | 2 +- scripts/ci/get_image_tags_from_branch.sh | 6 +++--- scripts/ci/github_actions/driver/setup_ci_dependencies.sh | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/driver_ci.yaml b/.github/workflows/driver_ci.yaml index 3a41b72cd..7478b8228 100644 --- a/.github/workflows/driver_ci.yaml +++ b/.github/workflows/driver_ci.yaml @@ -73,7 +73,7 @@ jobs: k8s_yamls_validation: runs-on: ubuntu-latest - name: "CSI deployment k8s yamls validation" + name: "Deployment k8s yamls validation" steps: - name: Checkout uses: actions/checkout@v2 diff --git a/scripts/ci/get_image_tags_from_branch.sh b/scripts/ci/get_image_tags_from_branch.sh index 5839bb23c..4e4f13c80 100755 --- a/scripts/ci/get_image_tags_from_branch.sh +++ b/scripts/ci/get_image_tags_from_branch.sh @@ -3,7 +3,7 @@ GIT_BRANCH=$1 IMAGE_VERSION=$2 BUILD_NUMBER=$3 COMMIT_HASH=${4:0:7} -branch_tag=$(echo $GIT_BRANCH| sed 's|/|.|g') #not sure if docker accept / in the version -specific_tag="${IMAGE_VERSION}_b${BUILD_NUMBER}_${COMMIT_HASH}_${branch_tag}" +branch_image_tag=$(echo $GIT_BRANCH| sed 's|/|.|g') #not sure if docker accept / in the version +specific_tag="${IMAGE_VERSION}_b${BUILD_NUMBER}_${COMMIT_HASH}_${branch_image_tag}" echo $specific_tag -echo $branch_tag +echo $branch_image_tag diff --git a/scripts/ci/github_actions/driver/setup_ci_dependencies.sh b/scripts/ci/github_actions/driver/setup_ci_dependencies.sh index ee3f422e5..404080afd 100755 --- a/scripts/ci/github_actions/driver/setup_ci_dependencies.sh +++ b/scripts/ci/github_actions/driver/setup_ci_dependencies.sh @@ -15,10 +15,11 @@ get_driver_version (){ install_ci_dependencies driver_version=$(get_driver_version) -driver_image_tags=$(scripts/ci/get_image_tags_from_branch.sh ${CI_ACTION_REF_NAME} ${driver_version} ${build_number} ${GITHUB_SHA}) +triggering_branch = ${CI_ACTION_REF_NAME} +driver_image_tags=$(scripts/ci/get_image_tags_from_branch.sh ${triggering_branch} ${driver_version} ${build_number} ${GITHUB_SHA}) driver_images_specific_tag=$(echo $driver_image_tags | awk '{print$1}') -if [ "$CI_ACTION_REF_NAME" == "develop" ]; then +if [ "$triggering_branch" == "develop" ]; then docker_image_branch_tag=latest else docker_image_branch_tag=$(echo $driver_image_tags | awk '{print$2}') From a05503f9c8f49363ea1e32c16f870f055c2bc857 Mon Sep 17 00:00:00 2001 From: matancarmeli7 Date: Tue, 2 Nov 2021 10:11:09 +0200 Subject: [PATCH 41/41] fix spacing problem Signed-off-by: matancarmeli7 --- scripts/ci/github_actions/driver/setup_ci_dependencies.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ci/github_actions/driver/setup_ci_dependencies.sh b/scripts/ci/github_actions/driver/setup_ci_dependencies.sh index 404080afd..399c694d6 100755 --- a/scripts/ci/github_actions/driver/setup_ci_dependencies.sh +++ b/scripts/ci/github_actions/driver/setup_ci_dependencies.sh @@ -15,7 +15,7 @@ get_driver_version (){ install_ci_dependencies driver_version=$(get_driver_version) -triggering_branch = ${CI_ACTION_REF_NAME} +triggering_branch=${CI_ACTION_REF_NAME} driver_image_tags=$(scripts/ci/get_image_tags_from_branch.sh ${triggering_branch} ${driver_version} ${build_number} ${GITHUB_SHA}) driver_images_specific_tag=$(echo $driver_image_tags | awk '{print$1}')