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

caching tools for code gens #202

Merged
merged 1 commit into from
Apr 29, 2019
Merged
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
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
### Project specific
bin/
vendor/

hack/code-gen
hack/controller-gen

### mac
.DS_Store
Expand Down Expand Up @@ -51,4 +52,4 @@ Session.vim
# Auto-generated tag files
tags
# Persistent undo
[._]*.un~
[._]*.un~
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ download:
go mod download

.PHONY: prebuild
prebuild: generate fmt vet
prebuild: generate check-formatting

.PHONY: manager
# Build manager binary
Expand Down Expand Up @@ -83,6 +83,10 @@ deploy-clean:
manifests:
./hack/update_manifests.sh

.PHONY: manifests-clean
manifests-clean:
rm -rf hack/controller-gen

.PHONY: fmt
# Run go fmt against code
fmt:
Expand Down Expand Up @@ -116,6 +120,10 @@ imports:
generate:
./hack/update_codegen.sh

.PHONY: generate-clean
generate-clean:
rm -rf hack/code-gen

.PHONY: cli
# Build CLI
cli: prebuild
Expand Down Expand Up @@ -148,7 +156,7 @@ clean: cli-clean test-clean manager-clean deploy-clean

.PHONY: docker-build
# Build the docker image
docker-build: generate fmt vet manifests
docker-build: generate check-formatting manifests
docker build --build-arg git_version_arg=${GIT_VERSION_PATH}=${GIT_VERSION} \
--build-arg git_commit_arg=${GIT_COMMIT_PATH}=${GIT_COMMIT} \
--build-arg build_date_arg=${BUILD_DATE_PATH}=${BUILD_DATE} . -t ${DOCKER_IMG}:${DOCKER_TAG}
Expand Down
26 changes: 13 additions & 13 deletions hack/update_codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@ set -o errexit
set -o nounset
set -o pipefail

TMP_DIR=$(mktemp -d)

cleanup() {
rm -rf "${TMP_DIR}"
}
trap "cleanup" EXIT SIGINT

cleanup

# The following solution for making code generation work with go modules is
# borrowed and modified from https://github.com/heptio/contour/pull/1010.
# it has been modified to enable caching.
export GO111MODULE=on
VERSION=$(go list -m all | grep k8s.io/code-generator | rev | cut -d"-" -f1 | cut -d" " -f1 | rev)
git clone https://github.com/kubernetes/code-generator.git "${TMP_DIR}"
(cd "${TMP_DIR}" && git reset --hard "${VERSION}" && go mod init)
"${TMP_DIR}"/generate-groups.sh \
CODE_GEN_DIR="hack/code-gen/$VERSION"

if [ -d $CODE_GEN_DIR ] # for file "if [-f /home/rama/file]"
then
echo "Using cached code generator version: $VERSION"
else
git clone https://github.com/kubernetes/code-generator.git "${CODE_GEN_DIR}"
(cd "${CODE_GEN_DIR}" && git reset --hard "${VERSION}" && go mod init)
fi

"${CODE_GEN_DIR}"/generate-groups.sh \
all \
github.com/kudobuilder/kudo/pkg/client \
github.com/kudobuilder/kudo/pkg/apis \
"kudo:v1alpha1" \
--go-header-file hack/boilerplate.go.txt # must be last for some reason
--go-header-file hack/boilerplate.go.txt # must be last for some reason
25 changes: 12 additions & 13 deletions hack/update_manifests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@ set -o errexit
set -o nounset
set -o pipefail

TMP_DIR=$(mktemp -d)

cleanup() {
rm -rf "${TMP_DIR}"
}
trap "cleanup" EXIT SIGINT

cleanup

# The following solution for making code generation work with go modules is
# borrowed and modified from https://github.com/heptio/contour/pull/1010.
# it has been modified to enable caching.
export GO111MODULE=on
VERSION=$(go list -m all | grep sigs.k8s.io/controller-tools | rev | cut -d"-" -f1 | cut -d" " -f1 | rev)
git clone https://github.com/kubernetes-sigs/controller-tools.git "${TMP_DIR}"
(cd "${TMP_DIR}" && git reset --hard "${VERSION}" && go mod init)
CONTROLLER_GEN_DIR="hack/controller-gen/$VERSION"

if [ -d $CONTROLLER_GEN_DIR ] # for file "if [-f /home/rama/file]"
then
echo "Using cached controller generator version: $VERSION"
else
git clone https://github.com/kubernetes-sigs/controller-tools.git "${CONTROLLER_GEN_DIR}"
(cd "${CONTROLLER_GEN_DIR}" && git reset --hard "${VERSION}" && go mod init)
fi

go run "$TMP_DIR"/cmd/controller-gen/main.go rbac --output-dir=config/default/rbac
go run "$TMP_DIR"/cmd/controller-gen/main.go crd
go run "$CONTROLLER_GEN_DIR"/cmd/controller-gen/main.go rbac --output-dir=config/default/rbac
go run "$CONTROLLER_GEN_DIR"/cmd/controller-gen/main.go crd