diff --git a/Makefile b/Makefile index 3c2315785..2e4f7ba2b 100644 --- a/Makefile +++ b/Makefile @@ -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: diff --git a/build/ci/Dockerfile.unittest b/build/ci/Dockerfile.unittest index 13e0cf262..1faeabfde 100644 --- a/build/ci/Dockerfile.unittest +++ b/build/ci/Dockerfile.unittest @@ -22,6 +22,7 @@ WORKDIR $WORKDIR COPY Makefile . RUN go get github.com/onsi/ginkgo/ginkgo@v1.16.4 \ + && go get github.com/mikefarah/yq/v4 \ && make kustomize \ && make controller-gen diff --git a/hack/check-files-alignment.sh b/hack/check-files-alignment.sh new file mode 100755 index 000000000..fb9d88202 --- /dev/null +++ b/hack/check-files-alignment.sh @@ -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 +} + +verify_yaml_doc_in_multidoc_yaml(){ + yamls_dictionary=${1#*=} + eval "declare -A yaml_kinds_by_origin_yaml_path="${yamls_dictionary} + 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" + ) + 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 + 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 diff --git a/hack/check-generated-manifests.sh b/hack/check-generated-manifests.sh deleted file mode 100755 index 4fc00972b..000000000 --- a/hack/check-generated-manifests.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/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. -# - -project_dirname=ibm-block-csi-operator -cd .. -cp -r $project_dirname ./$project_dirname-expected -cd $project_dirname-expected/ -hack/update-config-yamls.sh -cd .. -diff -qr --exclude=bin $project_dirname $project_dirname-expected/ -rm -rf $project_dirname-expected/ diff --git a/hack/project_info.sh b/hack/project_info.sh new file mode 100755 index 000000000..8eb70d672 --- /dev/null +++ b/hack/project_info.sh @@ -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 +} + +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 +} diff --git a/hack/update-installer.sh b/hack/update-installer.sh index f8971d2fc..4efe2f81c 100755 --- a/hack/update-installer.sh +++ b/hack/update-installer.sh @@ -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