Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Task/csi 3503 add verification scrips only #226

Draft
wants to merge 9 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@ run-unit-tests:
$(run_unit_tests_image) make test

.PHONY: test
test: check-generated-manifests update
test: check-files-alignment update
ginkgo -r -v -skipPackage tests

.PHONY: update
update: kustomize
hack/update-all.sh

.PHONY: check-generated-manifests
check-generated-manifests:
hack/check-generated-manifests.sh
.PHONY: check-files-alignment
check-files-alignment:
hack/check-files-alignment.sh

.PHONY: update-generated-yamls
update-generated-yamls:
Expand Down
1 change: 1 addition & 0 deletions build/ci/Dockerfile.unittest
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ WORKDIR $WORKDIR
COPY Makefile .

RUN go get github.com/onsi/ginkgo/[email protected] \
&& go get github.com/mikefarah/yq/v4 \
&& make kustomize \
&& make controller-gen

Expand Down
78 changes: 78 additions & 0 deletions hack/check-files-alignment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash -e

#
# Copyright 2019 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

source hack/project_info.sh
roles_yaml_path=config/rbac/role.yaml
crd_yaml_path=config/crd/bases/csi.ibm.com_ibmblockcsis.yaml

check_generation (){
echo "check generation"
project_dirname=ibm-block-csi-operator
cd ..
cp -r $project_dirname ./$project_dirname-expected
cd $project_dirname-expected/
make update
cd ..
diff -qr --exclude=bin $project_dirname $project_dirname-expected/
rm -rf $project_dirname-expected/
cd $project_dirname
ArbelNathan marked this conversation as resolved.
Show resolved Hide resolved
}
Comment on lines +23 to +34
Copy link
Contributor

@oriyarde oriyarde Dec 22, 2021

Choose a reason for hiding this comment

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

Suggested change
check_generation (){
echo "check generation"
project_dirname=ibm-block-csi-operator
cd ..
cp -r $project_dirname ./$project_dirname-expected
cd $project_dirname-expected/
make update
cd ..
diff -qr --exclude=bin $project_dirname $project_dirname-expected/
rm -rf $project_dirname-expected/
cd $project_dirname
}
check_generation ()(
echo "check generation"
project_path=$PWD
cp -r $project_path $project_path-expected
cd $project_path-expected
make update
diff -qr --exclude=bin $project_path $project_path-expected/
cd ..
rm -rf $project_path-expected/
)

would this work? less cd (+ absolute paths are more accurate + no hardcoded project name)


verify_yaml_doc_in_multidoc_yaml(){
yamls_dictionary=${1#*=}
eval "declare -A yaml_kinds_by_origin_yaml_path="${yamls_dictionary}
Copy link
Contributor

Choose a reason for hiding this comment

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

https://stackoverflow.com/a/3467959

Avoid eval like the plague

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried without it and I didn't manage to find a solution, the variable pass between the functions interrupted it, you sent an example without a function

Copy link
Contributor

Choose a reason for hiding this comment

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

for orignial_yaml in ${!yaml_kinds_by_origin_yaml_path[@]}; do
export resource_type=${yaml_kinds_by_origin_yaml_path[${orignial_yaml}]}
diff <(yq e '... comments=""' $orignial_yaml) <(yq eval '(. | select(.kind == env(resource_type)))' $operator_yaml_path)
done
}

verify_full_operator_yaml_is_aligned(){
echo "check full operator yaml alignment"
declare -A yaml_kinds_by_origin_yaml_path=(
[$roles_yaml_path]="ClusterRole"
[$crd_yaml_path]="CustomResourceDefinition"
["config/rbac/service_account.yaml"]="ServiceAccount"
["config/rbac/role_binding.yaml"]="ClusterRoleBinding"
["config/manager/manager.yaml"]="Deployment"
Comment on lines +48 to +52
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need the kinds hardcoded? can't we find them dynamically?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will open a ticket

Copy link
Contributor

Choose a reason for hiding this comment

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

to add resource_type=$(yq e .kind $original_yaml)?

)
verify_yaml_doc_in_multidoc_yaml "$(declare -p yaml_kinds_by_origin_yaml_path)"
}

verify_no_roles_diff (){
echo "check roles alignment"
are_manifest_files_exist_in_current_csi_version
csv_files=$(get_csv_files)
for csv_file in $csv_files; do
diff <(yq e .rules $roles_yaml_path) <(yq e .spec.install.spec.clusterPermissions[0].rules $csv_file)
done
}

verify_no_crds_diff (){
echo "check crds alignment"
are_manifest_files_exist_in_current_csi_version
Copy link
Contributor

Choose a reason for hiding this comment

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

code dup

crd_files=$(get_bundle_crds)
for crd_file in $crd_files; do
diff $crd_yaml_path $crd_file
done
}

check_generation
verify_full_operator_yaml_is_aligned
verify_no_roles_diff
verify_no_crds_diff
26 changes: 0 additions & 26 deletions hack/check-generated-manifests.sh

This file was deleted.

42 changes: 42 additions & 0 deletions hack/project_info.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash -e

#
# Copyright 2019 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

operator_yaml_path=deploy/installer/generated/ibm-block-csi-operator.yaml

get_current_csi_version (){
current_csi_version=$(cat version/version.go | grep -i driverversion | awk -F = '{print $2}')
echo ${current_csi_version//\"}
}

current_csi_version=$(get_current_csi_version)

are_manifest_files_exist_in_current_csi_version (){
if ! compgen -G "${PWD}/deploy/olm-catalog/*/$current_csi_version" > /dev/null; then
exit 0
fi
}

get_csv_files (){
ls deploy/olm-catalog/ibm-block-csi-operator-community/$current_csi_version/manifests/ibm-block-csi-operator.v$current_csi_version.clusterserviceversion.yaml
ls deploy/olm-catalog/ibm-block-csi-operator/$current_csi_version/manifests/ibm-block-csi-operator.clusterserviceversion.yaml
Comment on lines +35 to +36
Copy link
Contributor

@oriyarde oriyarde Dec 22, 2021

Choose a reason for hiding this comment

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

consider moving the olm-catalog path to a common "const"

}

get_bundle_crds (){
ls deploy/olm-catalog/ibm-block-csi-operator-community/$current_csi_version/manifests/csi.ibm.com_ibmblockcsis.yaml
ls deploy/olm-catalog/ibm-block-csi-operator/$current_csi_version/manifests/csi.ibm.com_ibmblockcsis.yaml
}
3 changes: 2 additions & 1 deletion hack/update-installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# Combine all the operator related yamls in the deploy
# folder into one file.

source hack/project_info.sh
yes | cp deploy/installer/kustomization.yaml .
kustomize build -o deploy/installer/generated/ibm-block-csi-operator.yaml
kustomize build -o $operator_yaml_path
rm -f kustomization.yaml