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 3418 | add the option to developers to do generation in thier local env #216

22 changes: 18 additions & 4 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,40 @@ 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-test-image
build-unit-test-image:
docker build -f build/ci/Dockerfile.unittest -t operator-unittests .

.PHONY: run-unit-test
run-unit-test:
oriyarde marked this conversation as resolved.
Show resolved Hide resolved
$(run_unit_tests_image) make test

.PHONY: test
test: update
hack/check-generated-manifests.sh
oriyarde marked this conversation as resolved.
Show resolved Hide resolved
ginkgo -r -v -skipPackage tests

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

.PHONY: update-generated-yamls
update-generated-yamls:
$(run_unit_tests_image) hack/update-genrated-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: 4 additions & 4 deletions build/ci/Dockerfile.unittest
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ 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

COPY . .
CMD ["make", "test"]
RUN go get github.com/onsi/ginkgo/ginkgo \
&& make kustomize \
&& make controller-gen
4 changes: 2 additions & 2 deletions build/ci/run_unittests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
# limitations under the License.
#

docker build -f build/ci/Dockerfile.unittest -t operator-unittests .
docker run --rm -t operator-unittests
make build-unit-test-image
make run-unit-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/generated/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: kustomize.config.k8s.io/v1beta1
oriyarde marked this conversation as resolved.
Show resolved Hide resolved
kind: Kustomization

resources:
- config/crd/bases/csi.ibm.com_ibmblockcsis.yaml
- config/manager/manager.yaml
- config/rbac/role.yaml
- config/rbac/role_binding.yaml
- config/rbac/service_account.yaml
oriyarde marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion hack/check-generated-manifests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ project_dirname=ibm-block-csi-operator
cd ..
cp -r $project_dirname ./$project_dirname-copy
oriyarde marked this conversation as resolved.
Show resolved Hide resolved
cd $project_dirname-copy/
hack/update-crds.sh
hack/update-genrated-yamls.sh
oriyarde marked this conversation as resolved.
Show resolved Hide resolved
cd ..
diff -qr --exclude=bin $project_dirname $project_dirname-copy/
rm -rf $project_dirname-copy/
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/generated/kustomization.yaml .
oriyarde marked this conversation as resolved.
Show resolved Hide resolved
kustomize build -o deploy/installer/generated/ibm-block-csi-operator.yaml
rm -rf kustomization.yaml
oriyarde marked this conversation as resolved.
Show resolved Hide resolved