Codegen: simpler k8s.io/code-generator/examples

This moves the hack/ directory and scripts to the examples dir, which is
a distinct module.  This avoids some Go unpleasantness around module
boundaries and just makes more sense.
This commit is contained in:
Tim Hockin 2023-03-05 11:45:42 -08:00
parent 5463fcd7dd
commit 893ec0ca45
No known key found for this signature in database
4 changed files with 23 additions and 25 deletions

View File

@ -35,7 +35,7 @@ UPDATE_API_KNOWN_VIOLATIONS="${UPDATE_API_KNOWN_VIOLATIONS:-}"
OUT_DIR="_output"
PRJ_SRC_PATH="k8s.io/kubernetes"
BOILERPLATE_FILENAME="vendor/k8s.io/code-generator/hack/boilerplate.go.txt"
BOILERPLATE_FILENAME="hack/boilerplate/boilerplate.generatego.txt"
APPLYCONFIG_PKG="k8s.io/client-go/applyconfigurations"
# Any time we call sort, we want it in the same locale.
@ -885,7 +885,7 @@ function codegen::subprojects() {
# Call generation on sub-projects.
# TODO(thockin): make these take a list of codegens and flags
local subs=(
vendor/k8s.io/code-generator/hack/update-codegen.sh
vendor/k8s.io/code-generator/examples/hack/update-codegen.sh
vendor/k8s.io/kube-aggregator/hack/update-codegen.sh
vendor/k8s.io/sample-apiserver/hack/update-codegen.sh
vendor/k8s.io/sample-controller/hack/update-codegen.sh

View File

@ -18,34 +18,36 @@ set -o errexit
set -o nounset
set -o pipefail
SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")"
SCRIPT_ROOT="${SCRIPT_DIR}/.."
CODEGEN_PKG="${CODEGEN_PKG:-"${SCRIPT_ROOT}/.."}"
# generate the code with:
# - --output-base because this script should also be able to run inside the vendor dir of
# k8s.io/kubernetes. The output-base is needed for the generators to output into the vendor dir
# instead of the $GOPATH directly. For normal projects this can be dropped.
"${SCRIPT_ROOT}/generate-internal-groups.sh" "client,conversion,deepcopy,defaulter,informer,lister,openapi" \
"${CODEGEN_PKG}/generate-internal-groups.sh" "client,conversion,deepcopy,defaulter,informer,lister,openapi" \
k8s.io/code-generator/examples/apiserver \
k8s.io/code-generator/examples/apiserver/apis \
k8s.io/code-generator/examples/apiserver/apis \
"example:v1 example2:v1 example3.io:v1" \
--output-base "$(dirname "${BASH_SOURCE[0]}")/../../.." \
--go-header-file "${SCRIPT_ROOT}/hack/boilerplate.go.txt"
"${SCRIPT_ROOT}/generate-groups.sh" "applyconfiguration,client,deepcopy,defaulter,informer,lister" \
--output-base "${SCRIPT_DIR}/../../../.." \
--go-header-file "${SCRIPT_DIR}/boilerplate.go.txt"
"${CODEGEN_PKG}/generate-groups.sh" "applyconfiguration,client,deepcopy,defaulter,informer,lister" \
k8s.io/code-generator/examples/crd \
k8s.io/code-generator/examples/crd/apis \
"example:v1 example2:v1" \
--output-base "$(dirname "${BASH_SOURCE[0]}")/../../.." \
--go-header-file "${SCRIPT_ROOT}/hack/boilerplate.go.txt"
"${SCRIPT_ROOT}/generate-groups.sh" "applyconfiguration,client,deepcopy,defaulter,informer,lister" \
--output-base "${SCRIPT_DIR}/../../../.." \
--go-header-file "${SCRIPT_DIR}/boilerplate.go.txt"
"${CODEGEN_PKG}/generate-groups.sh" "applyconfiguration,client,deepcopy,defaulter,informer,lister" \
k8s.io/code-generator/examples/MixedCase \
k8s.io/code-generator/examples/MixedCase/apis \
"example:v1" \
--output-base "$(dirname "${BASH_SOURCE[0]}")/../../.." \
--go-header-file "${SCRIPT_ROOT}/hack/boilerplate.go.txt"
"${SCRIPT_ROOT}/generate-groups.sh" "applyconfiguration,client,deepcopy,defaulter,informer,lister" \
--output-base "${SCRIPT_DIR}/../../../.." \
--go-header-file "${SCRIPT_DIR}/boilerplate.go.txt"
"${CODEGEN_PKG}/generate-groups.sh" "applyconfiguration,client,deepcopy,defaulter,informer,lister" \
k8s.io/code-generator/examples/HyphenGroup \
k8s.io/code-generator/examples/HyphenGroup/apis \
"example:v1" \
--output-base "$(dirname "${BASH_SOURCE[0]}")/../../.." \
--go-header-file "${SCRIPT_ROOT}/hack/boilerplate.go.txt"
--output-base "${SCRIPT_DIR}/../../../.." \
--go-header-file "${SCRIPT_DIR}/boilerplate.go.txt"

View File

@ -18,14 +18,12 @@ set -o errexit
set -o nounset
set -o pipefail
SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
DIFFROOT="${SCRIPT_ROOT}/examples"
TMP_DIFFROOT="${SCRIPT_ROOT}/_tmp/examples"
_tmp="${SCRIPT_ROOT}/_tmp"
SCRIPT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
DIFFROOT="${SCRIPT_ROOT}"
TMP_DIFFROOT="$(mktemp -d -t "$(basename "$0").XXXXXX")"
cleanup() {
rm -rf "${_tmp}"
rm -rf "${TMP_DIFFROOT}"
}
trap "cleanup" EXIT SIGINT
@ -38,9 +36,7 @@ cp -a "${DIFFROOT}"/* "${TMP_DIFFROOT}"
echo "diffing ${DIFFROOT} against freshly generated codegen"
ret=0
diff -Naupr "${DIFFROOT}" "${TMP_DIFFROOT}" || ret=$?
cp -a "${TMP_DIFFROOT}"/* "${DIFFROOT}"
if [[ $ret -eq 0 ]]
then
if [[ $ret -eq 0 ]]; then
echo "${DIFFROOT} up to date."
else
echo "${DIFFROOT} is out of date. Please run hack/update-codegen.sh"
@ -49,7 +45,7 @@ fi
# smoke test
echo "Smoke testing examples by compiling..."
pushd "./${SCRIPT_ROOT}/examples"
pushd "${SCRIPT_ROOT}"
go build "k8s.io/code-generator/examples/crd/..."
go build "k8s.io/code-generator/examples/apiserver/..."
go build "k8s.io/code-generator/examples/MixedCase/..."