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 5 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
72 changes: 72 additions & 0 deletions hack/check-files-alignment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/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
origin_crd_yaml_path=config/crd/bases/csi.ibm.com_ibmblockcsis.yaml
oriyarde marked this conversation as resolved.
Show resolved Hide resolved

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_full_operator_yaml_is_aligned(){
echo "check full operator yaml alignment"
declare -A yaml_kinds_by_origin_yaml_path=(
[$roles_yaml_path]="ClusterRole"
[$origin_crd_yaml_path]="CustomResourceDefinition"
["config/rbac/service_account.yaml"]="ServiceAccount"
["config/rbac/role_binding.yaml"]="ClusterRoleBinding"
["config/manager/manager.yaml"]="Deployment"
)
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_no_roles_diff (){
echo "check roles alignment"
are_manifest_files_exsists_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_exsists_in_current_csi_version
crd_files=$(get_bundle_crds)
for crd_file in $crd_files; do
diff $origin_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.

41 changes: 41 additions & 0 deletions hack/project_info.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/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//\"}
}

are_manifest_files_exsists_in_current_csi_version (){
oriyarde marked this conversation as resolved.
Show resolved Hide resolved
current_csi_version=$(get_current_csi_version)
if ! compgen -G "${PWD}/deploy/olm-catalog/*/$current_csi_version" > /dev/null; then
exit 0
fi
}

get_csv_files (){
current_csi_version=$(get_current_csi_version)
ls deploy/olm-catalog/*/$current_csi_version/manifests/ibm-block-csi-operator.v$current_csi_version.clusterserviceversion.yaml
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

Choose a reason for hiding this comment

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

I still see the wildcard.
what happens if there's only one bundle for the current csi version? I don't think the test should fail. it should test what it can, and allow separate additions

oriyarde marked this conversation as resolved.
Show resolved Hide resolved
}

get_bundle_crds (){
current_csi_version=$(get_current_csi_version)
oriyarde marked this conversation as resolved.
Show resolved Hide resolved
ls deploy/olm-catalog/*/$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