Skip to content

Commit

Permalink
CSI 3418 | add the option to developers to do generation in thier loc…
Browse files Browse the repository at this point in the history
…al env (#216)

* add the option to developers to do generation in thier local env

Signed-off-by: matancarmeli7 <[email protected]>

* add commands to docker

Signed-off-by: matancarmeli7 <[email protected]>

* remove clean bin function

Signed-off-by: matancarmeli7 <[email protected]>

* rename update-yamls.sh script

Signed-off-by: matancarmeli7 <[email protected]>

* change usnit tests make name

Signed-off-by: matancarmeli7 <[email protected]>

* update kusromiztion.yaml patrh for genrated operator

Signed-off-by: matancarmeli7 <[email protected]>

* remove make from run_unittests.sh

Signed-off-by: matancarmeli7 <[email protected]>

* Pr

Signed-off-by: matancarmeli7 <[email protected]>

* set ginkgo version

Signed-off-by: matancarmeli7 <[email protected]>

* move go get dependencies in unittests dockerfile

Signed-off-by: matancarmeli7 <[email protected]>

* use the check-generated-manifests

Signed-off-by: matancarmeli7 <[email protected]>
  • Loading branch information
matancarmeli7 authored Oct 25, 2021
1 parent 4151340 commit 3c8d55c
Show file tree
Hide file tree
Showing 8 changed files with 805 additions and 966 deletions.
29 changes: 23 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ manifests: controller-gen kustomize## Generate WebhookConfiguration, ClusterRole
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
CONTROLLER_GEN = controller-gen
controller-gen: ## Download controller-gen locally if necessary.
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])

KUSTOMIZE = $(shell pwd)/bin/kustomize
KUSTOMIZE = kustomize
kustomize: ## Download kustomize locally if necessary.
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])

Expand All @@ -55,26 +55,43 @@ TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
go get $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef

# custom
run_unit_tests_image=docker run --rm -v $(CURDIR):/go/src/github.com/IBM/ibm-block-csi-operator -t operator-unittests

.PHONY: olm-validation
olm-validation:
build/ci/olm_validation.sh

.PHONY: build-unit-tests-image
build-unit-tests-image:
docker build -f build/ci/Dockerfile.unittest -t operator-unittests .

.PHONY: run-unit-tests
run-unit-tests:
$(run_unit_tests_image) make test

.PHONY: test
test: update
hack/check-generated-manifests.sh
test: check-generated-manifests update
ginkgo -r -v -skipPackage tests

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

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

.PHONY: update-generated-yamls
update-generated-yamls:
$(run_unit_tests_image) hack/update-config-yamls.sh
$(run_unit_tests_image) hack/update-installer.sh

.PHONY: list
list:
@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$'
8 changes: 6 additions & 2 deletions build/ci/Dockerfile.unittest
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ ENV GO111MODULE=on \
WORKDIR=/go/src/github.com/IBM/ibm-block-csi-operator
ENV CR_YAML=$WORKDIR/config/samples/csi.ibm.com_v1_ibmblockcsi_cr.yaml
WORKDIR $WORKDIR
COPY Makefile .

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

COPY . .
CMD ["make", "test"]

CMD ["make", "test"]
256 changes: 248 additions & 8 deletions config/crd/bases/csi.ibm.com_ibmblockcsis.yaml

Large diffs are not rendered by default.

1,375 changes: 511 additions & 864 deletions deploy/installer/generated/ibm-block-csi-operator.yaml

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions deploy/installer/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- config/crd/bases/csi.ibm.com_ibmblockcsis.yaml
- config/rbac/service_account.yaml
- config/rbac/role.yaml
- config/rbac/role_binding.yaml
- config/manager/manager.yaml
10 changes: 5 additions & 5 deletions hack/check-generated-manifests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

project_dirname=ibm-block-csi-operator
cd ..
cp -r $project_dirname ./$project_dirname-copy
cd $project_dirname-copy/
hack/update-crds.sh
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-copy/
rm -rf $project_dirname-copy/
diff -qr --exclude=bin $project_dirname $project_dirname-expected/
rm -rf $project_dirname-expected/
File renamed without changes.
84 changes: 3 additions & 81 deletions hack/update-installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,84 +19,6 @@
# Combine all the operator related yamls in the deploy
# folder into one file.

CURRENT_PATH=$(dirname "$BASH_SOURCE")
DEPLOY_PATH=$CURRENT_PATH/../deploy
CONFIG_PATH=$CURRENT_PATH/../config
CRD_PATH=$CONFIG_PATH/crd/bases

declare -a operator_deploy_files=(
"crd/bases/csi.ibm.com_ibmblockcsis.yaml"
"manager/manager.yaml"
"rbac/role.yaml"
"rbac/role_binding.yaml"
"rbac/service_account.yaml"
)

TARGET_FILE_NAME=ibm-block-csi-operator.yaml
TARGET_FILE=$DEPLOY_PATH/installer/generated/$TARGET_FILE_NAME

excluded_files=("csi_driver.yaml" $TARGET_FILE_NAME)
excluded_crds=("csi.ibm.com_configs_crd.yaml" "csi.ibm.com_nodeinfos_crd.yaml")

function contains()
{
local i
for i in "${@:2}"
do
[[ "$i" == "$1" ]] && return 0; # 0 is true
done
return 1 # 1 is false
}

echo "generate operator installer"

printf "# Code generated by $(basename $0). DO NOT EDIT.\n\n" > $TARGET_FILE

for file_name in $(ls $CRD_PATH)
do
file=$CRD_PATH/$file_name
if test -f $file
then
if [[ $file == *_crd.yaml ]] && !(contains $file_name "${excluded_crds[@]}")
then
cat $file >> $TARGET_FILE
printf "\n---\n" >> $TARGET_FILE
else
echo "skip $file_name"
fi
else
echo "skip $file_name, it is not a file"
fi
done

for file_name in "${operator_deploy_files[@]}"
do
file=$CONFIG_PATH/$file_name
if test -f $file
then
if !(contains $file_name "${excluded_files[@]}")
then
# remove the commented-out lines
sed -e '/^[ \t]*#/d' $file >> $TARGET_FILE
printf "\n---\n" >> $TARGET_FILE
else
echo "skip $file_name"
fi
else
echo "skip $file_name, it is not a file"
fi
done

# delete the last "---"
os=`uname`
# arch=`uname -i`

if [[ $os == "Darwin" ]]
then
sed -i '' -e '$d' $TARGET_FILE
sed -i '' -e '$d' $TARGET_FILE
elif [[ $os == "Linux" ]]
then
sed -i '$d' $TARGET_FILE
sed -i '$d' $TARGET_FILE
fi
yes | cp deploy/installer/kustomization.yaml .
kustomize build -o deploy/installer/generated/ibm-block-csi-operator.yaml
rm -f kustomization.yaml

0 comments on commit 3c8d55c

Please sign in to comment.