Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

CSI-2625 add CSI IBM Driver operator CI #189

Draft
wants to merge 72 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
782cf90
add CSI IBM Driver operator CI
matancarmeli7 Jul 1, 2021
ccd312e
change wait for driver script
matancarmeli7 Jul 1, 2021
3881a4e
change does_the_docker_image_has_tag
matancarmeli7 Jul 1, 2021
11658a1
add docker-hub command
matancarmeli7 Jul 1, 2021
b32d494
not fail on getting the image tags
matancarmeli7 Jul 1, 2021
0cf1015
add break in does_the_docker_image_has_tag
matancarmeli7 Jul 5, 2021
b6dd4ec
add permissions to edit cr files
matancarmeli7 Jul 8, 2021
205dfcc
Merge branch 'develop' into task/CSI-2625_add_another_stage_before_th…
matancarmeli7 Jul 8, 2021
9546870
change olm verification to olm validation
matancarmeli7 Jul 8, 2021
a420bee
remove sudo from changing the cr files
matancarmeli7 Jul 8, 2021
359459b
answer some code review comments
matancarmeli7 Jul 12, 2021
564df3e
change the image tag
matancarmeli7 Jul 12, 2021
8dad6ff
change the directory that it will check the image_version
matancarmeli7 Jul 12, 2021
80b68d9
change the image_version check to certified dir
matancarmeli7 Jul 12, 2021
69cd690
change saving driver logs script
matancarmeli7 Jul 12, 2021
bba693e
use run_action_on_pod function
matancarmeli7 Jul 12, 2021
5ded798
fix save logs
matancarmeli7 Jul 12, 2021
0485341
cahnge the edit of the cr file
matancarmeli7 Jul 12, 2021
d30934d
fix some problems
matancarmeli7 Jul 12, 2021
0f5f33c
create github_actions firectory
matancarmeli7 Jul 12, 2021
4081c49
fix syntax errors in wait for k8s cluster
matancarmeli7 Jul 13, 2021
e6d3c1d
fix is_pod_ready function
matancarmeli7 Jul 13, 2021
5e00875
fix some syntax errors in deploy driver
matancarmeli7 Jul 14, 2021
f7b7c6b
change the node ripository yaml path
matancarmeli7 Jul 14, 2021
ed5a5a4
remove cluster setup from driver repository
matancarmeli7 Jul 21, 2021
4314f6a
add build_number env variable
matancarmeli7 Jul 21, 2021
fd7fa44
fix setup ci dependencies
matancarmeli7 Jul 21, 2021
2306ea5
change are_pods_ready in wait for k8s
matancarmeli7 Jul 26, 2021
0f39210
add edit_operator_yaml_image function
matancarmeli7 Jul 26, 2021
949bdcf
change get_image_tags_from_branch script name
matancarmeli7 Jul 26, 2021
4df43a6
help the deer readers to read wait for driver
matancarmeli7 Jul 27, 2021
9c6da84
add is_wanted_image_in_pod
matancarmeli7 Jul 27, 2021
df5f840
add driver_images_tag env to wait for driver
matancarmeli7 Jul 27, 2021
ccdd46d
fix wait for driver
matancarmeli7 Jul 29, 2021
a0e8eb4
fix function is_expected_image_in_pod
matancarmeli7 Jul 29, 2021
fcffa32
answer some code review comments
matancarmeli7 Aug 3, 2021
3cb03f3
remove variables from yq command
matancarmeli7 Aug 3, 2021
16e7869
change commit sha parameter
matancarmeli7 Aug 4, 2021
5e4ecaa
fix operator image branch for test parameter
matancarmeli7 Aug 4, 2021
a38ca6d
change CSI_Build_and_push_images variable
matancarmeli7 Aug 4, 2021
d6f412f
fix the assert for images function
matancarmeli7 Aug 4, 2021
38f2573
change the image_in_pod command
matancarmeli7 Aug 4, 2021
c97bade
Merge branch 'develop' into task/CSI-2625_add_another_stage_before_th…
matancarmeli7 Aug 4, 2021
d2a3d02
change driver logs artifactes upload
matancarmeli7 Aug 4, 2021
5f36254
Merge branch 'develop' into task/CSI-2625_add_another_stage_before_th…
matancarmeli7 Aug 8, 2021
4963b9b
add get_pod_images_by_type function
matancarmeli7 Aug 10, 2021
0b6be16
code review comments
matancarmeli7 Aug 10, 2021
8bc6d03
fix spelling problem
matancarmeli7 Aug 10, 2021
4d9db61
add parameter to wiat for driver
matancarmeli7 Aug 11, 2021
32eaf69
change get driver branch script name
matancarmeli7 Aug 16, 2021
55f17ea
fix save logs with describe
matancarmeli7 Aug 16, 2021
46ecb71
change github_actions/operator directory to driver
matancarmeli7 Aug 17, 2021
ea0e064
add action_name parameter to run_action_and_save_output
matancarmeli7 Aug 17, 2021
d51d2ac
add csiblock1 secret
matancarmeli7 Aug 18, 2021
773eada
add deploy operator
matancarmeli7 Aug 19, 2021
55bfc12
move deploy_operator to operator dir
matancarmeli7 Aug 22, 2021
512c38c
change deploy_objects path
matancarmeli7 Aug 22, 2021
96860e2
use docker manifest to search for tags
matancarmeli7 Aug 22, 2021
dd9b171
change deploy_objects to deployment
matancarmeli7 Aug 23, 2021
fcf3bda
Merge branch 'develop' into task/CSI-2625_add_another_stage_before_th…
matancarmeli7 Oct 3, 2021
98159ca
remove cds
matancarmeli7 Oct 3, 2021
914818a
change build_and_push_images stage
matancarmeli7 Oct 3, 2021
e480a64
insert specific python version and pip version
matancarmeli7 Oct 4, 2021
aba7bb0
add setup_yq.sh
matancarmeli7 Oct 4, 2021
ab28403
add pr comments answer
matancarmeli7 Oct 12, 2021
3642121
edit get_driver_image script
matancarmeli7 Oct 17, 2021
3ee4e46
remove backticks
matancarmeli7 Oct 31, 2021
f9c7828
change names of parameters
matancarmeli7 Nov 2, 2021
3ff23d6
align setup_ci with driver
matancarmeli7 Nov 2, 2021
1ed494f
fix spacing problem
matancarmeli7 Nov 2, 2021
8cea7ba
Merge branch 'develop' into task/CSI-2625_add_another_stage_before_th…
matancarmeli7 Feb 21, 2022
c0b3acd
test stuff
matancarmeli7 Feb 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
181 changes: 181 additions & 0 deletions .github/workflows/operator_ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
name: Operator Build
on:
push:
branches:
- develop
- master
pull_request:
branches:
- develop
- master
jobs:
prepare_env:
name: "Prepare env"
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9.7'
- uses: FranzDiebold/github-env-vars-action@v2
- name: Setup dependencies
id: setup_dependencies
run: |
build/ci/github_actions/setup_ci_dependencies.sh
env:
build_number: "${{ github.run_number }}"
- uses: actions/cache@v2
with:
path: ${{ env.pythonLocation }}
key: ${{ env.pythonLocation }}-${{ hashFiles('dev-requirements.txt') }}
- name: Save dependencies files
uses: actions/upload-artifact@v2
with:
name: ci_dependencies
path: |
/home/runner/.bash_profile
retention-days: 1
outputs:
branch_image_tag: "${{ steps.setup_dependencies.outputs.branch_image_tag }}"
operator_specific_tag_for_test: "${{ steps.setup_dependencies.outputs.operator_specific_tag_for_test }}"

unit_testing:
runs-on: ubuntu-latest
name: "Unit testing"
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Run unit tests
run: |
mkdir -p build/_output/reports && chmod 777 build/_output/reports
./build/ci/run_unittests.sh

run_olm_validation:
runs-on: ubuntu-latest
name: "Run OLM validation"
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Run OLM validation
run: |
./build/ci/run_olm_validation.sh

build_and_push_images:
name: "Build and push images"
runs-on: ubuntu-latest
needs:
- unit_testing
- run_olm_validation
- prepare_env
strategy:
matrix:
image_type: ['operator']
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/[email protected]
- uses: FranzDiebold/github-env-vars-action@v2
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: '${{ secrets.CSIBLOCK_DOCKER_REGISTRY_USERNAME }}'
Copy link
Contributor

Choose a reason for hiding this comment

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

I would avoid using the current registry/user name (csiblock) in our variables, since it can always change in the future

password: '${{ secrets.CSIBLOCK_DOCKER_REGISTRY_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: Build and push ${{ matrix.image_type }}
uses: docker/build-push-action@v2
with:
context: .
platforms: linux/amd64,linux/ppc64le,linux/s390x
push: true
tags: |
${{ secrets.CSIBLOCK_DOCKER_REGISTRY_USERNAME }}/ibm-block-csi-${{ matrix.image_type }}:${{ needs.prepare_env.outputs.operator_specific_tag_for_test }}
${{ secrets.CSIBLOCK_DOCKER_REGISTRY_USERNAME }}/ibm-block-csi-${{ matrix.image_type }}:${{ needs.prepare_env.outputs.branch_image_tag }}
file: build/Dockerfile.${{ 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:
operator_specific_tag_for_test: "${{ needs.prepare_env.outputs.operator_specific_tag_for_test }}"

deploy_csi_on_cluster:
runs-on: ubuntu-latest
name: "Deploy csi on cluster"
needs: build_and_push_images
env:
csiblock_docker_registry_username: ${{ secrets.CSIBLOCK_DOCKER_REGISTRY_USERNAME }}
controller_repository_for_test: '${{ secrets.CSIBLOCK_DOCKER_REGISTRY_USERNAME }}/ibm-block-csi-controller'
node_repository_for_test: '${{ secrets.CSIBLOCK_DOCKER_REGISTRY_USERNAME }}/ibm-block-csi-node'
operator_image_repository_for_test: '${{ secrets.CSIBLOCK_DOCKER_REGISTRY_USERNAME }}/ibm-block-csi-operator'
operator_specific_tag_for_test: "${{ needs.build_and_push_images.outputs.operator_specific_tag_for_test }}"
operator_image_for_test: "${{ secrets.CSIBLOCK_DOCKER_REGISTRY_USERNAME }}/ibm-block-csi-operator:${{ needs.build_and_push_images.outputs.operator_specific_tag_for_test }}"
operator_yaml: "deploy/installer/generated/ibm-block-csi-operator.yaml"
cr_yaml: "config/samples/csi.ibm.com_v1_ibmblockcsi_cr.yaml"
timeout-minutes: 7
steps:
- name: Checkout
uses: actions/checkout@v2
- 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 driver images tag from branch
id: driver_images_tag_from_branch
run: |
build/ci/github_actions/driver/get_driver_images_tag_from_branch.sh
env:
github_token: ${{ secrets.CSIBLOCK_GITHUB_TOKEN }}
- name: Create k8s Kind Cluster
uses: helm/[email protected]
with:
version: v0.11.1
- name: Wait for k8s cluster to be ready
run: |
build/ci/github_actions/wait_for_k8s_ready.sh
- name: Deploy ibm block csi operator
run: |
build/ci/github_actions/operator/deploy_operator.sh
- name: Deploy ibm block csi driver
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this under create_cluster?

run: |
build/ci/github_actions/driver/deploy_driver.sh
env:
driver_images_tag: "${{ steps.driver_images_tag_from_branch.outputs.branch_image_tag }}"
- name: Save driver pods logs to artifacts
if: always()
run: |
build/ci/github_actions/driver/save_driver_logs_to_artifacts.sh
- name: Upload driver pods logs
if: always()
uses: actions/upload-artifact@v2
with:
name: driver_logs
path: |
/tmp/*.txt
retention-days: 7
4 changes: 2 additions & 2 deletions build/ci/build_push_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
tags=$(build/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
[ "$GIT_BRANCH" = "develop" -o "$GIT_BRANCH" = "origin/develop" -o "$GIT_BRANCH" = "master" ] && tag_latest="true" || tag_latest="false"
Expand Down
9 changes: 9 additions & 0 deletions build/ci/get_image_tags_from_branch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash -xe
GIT_BRANCH=$1
oriyarde marked this conversation as resolved.
Show resolved Hide resolved
IMAGE_VERSION=$2
BUILD_NUMBER=$3
COMMIT_HASH=${4:0:7}
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_image_tag
103 changes: 103 additions & 0 deletions build/ci/github_actions/deployment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/bin/bash -xe
set +o pipefail

is_driver_ready=false
actual_driver_running_time_in_seconds=0
minimum_driver_running_time_in_seconds=10
containers_prefix=ibm-block-csi
declare -a driver_pods_types=(
"controller"
"node"
)

get_csi_pods (){
kubectl get pod -A -l csi
}

get_operator_pod (){
kubectl get pod -A -l app.kubernetes.io/name=ibm-block-csi-operator
}

get_image_pod_by_type (){
pod_type=$1
component_to_check=$2
containers_images=$(kubectl get pods $(get_csi_pods | grep $pod_type | awk '{print$2}') -o jsonpath='{range .spec.containers[*]}{.name},{.image} {end}')
for containers_image in $containers_images
do
if [[ "$containers_image" =~ "$component_to_check," ]]; then
echo $containers_image | awk -F , '{print$2}'
break
fi
done
}

wait_for_pod_to_start (){
driver_pod_type=$1
while [ "$(get_csi_pods | grep $driver_pod_type | wc -l)" -eq 0 ]; do
echo "The $driver_pod_type is not deployed"
sleep 1
done
}

wait_for_driver_deployment_to_start (){
for driver_pods_type in "${driver_pods_types[@]}"
do
wait_for_pod_to_start $driver_pods_type
done
}

wait_for_driver_deployment_to_finish (){
wait_for_pods_to_finish get_csi_pods
}

wait_for_operator_deployment_to_finish (){
wait_for_pods_to_finish get_operator_pod
}


wait_for_pods_to_finish (){
get_pods_command=$1
while [ $is_driver_ready == "false" ]; do
if [ "$($get_pods_command | 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
is_driver_ready=true
fi
else
actual_driver_running_time_in_seconds=0
fi
get_csi_pods
sleep 1
done
}

assert_expected_image_in_pod (){
pod_type=$1
expected_pod_image=$2
component_to_check=$containers_prefix-$pod_type
image_in_pod=$(get_image_pod_by_type $pod_type $component_to_check)
if [[ $image_in_pod != $expected_pod_image ]]; then
echo "$pod_type's image ($image_in_pod) is not the expected image ($expected_pod_image)"
exit 1
fi
}

assert_driver_images_in_pods (){
expected_node_image=$1
expected_controller_image=$2
declare -A drivers_components_in_k8s=(
["controller"]="$expected_controller_image"
["node"]="$expected_node_image"
)
for driver_component in ${!drivers_components_in_k8s[@]}; do
driver_component_expected_image=${drivers_components_in_k8s[${driver_component}]}
assert_expected_image_in_pod $driver_component $driver_component_expected_image
done
}

assert_operator_image_in_pod (){
operator_image_for_test=$1
kubectl apply -f $operator_yaml
wait_for_pod_to_start "operator"
assert_expected_image_in_pod "operator" $operator_image_for_test
}
35 changes: 35 additions & 0 deletions build/ci/github_actions/driver/deploy_driver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash -xel
set +o pipefail

expected_node_image=$node_repository_for_test:$driver_images_tag
expected_controller_image=$controller_repository_for_test:$driver_images_tag

install_worker_prerequisites() {
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
oriyarde marked this conversation as resolved.
Show resolved Hide resolved
}

edit_cr_images (){
chmod 547 $cr_yaml
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} |= \"${cr_image_value}\"" $cr_yaml -i
done
}

install_worker_prerequisites
edit_cr_images
cat $cr_yaml | grep repository:
cat $cr_yaml | grep tag:
kubectl apply -f $cr_yaml
source build/ci/github_actions/deployment.sh
wait_for_driver_deployment_to_start
assert_driver_images_in_pods $expected_node_image $expected_controller_image
wait_for_driver_deployment_to_finish
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash -xe
set +o pipefail

driver_images_tag_from_branch=latest
triggering_branch=$CI_ACTION_REF_NAME
target_image_tags=$(build/ci/get_image_tags_from_branch.sh ${triggering_branch})
branch_image_tag=$(echo $branch_image_tag | awk '{print$2}')

is_private_branch_component_image_exists(){
driver_component=$1
image_to_check=$csiblock_docker_registry_username/ibm-block-csi-$driver_component:$branch_image_tag
is_image_tag_exists=false
export driver_image_inspect=$(docker manifest inspect $image_to_check &> /dev/null; echo $?)
Copy link
Contributor

Choose a reason for hiding this comment

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

where is driver_image_inspect used?
why does it sound like an action? if I understand correctly, it is not a function

if [ $driver_image_inspect == "0" ]; then
echo true
else
echo false
fi
}

is_controller_image_tag_exists=$(is_private_branch_component_image_exists controller)
is_node_image_tag_exists=$(is_private_branch_component_image_exists node)

if [ $is_controller_image_tag_exists == "true" ] && [ $is_node_image_tag_exists == "true " ]; then
driver_images_tag_from_branch=$branch_image_tag
fi

echo "::set-output name=branch_image_tag::${driver_images_tag_from_branch}"
Loading