Codegen subprojects: consolidate generate-*groups

They both still exist, with the same API as before, but now
generate-groups calls generate-internal-groups, which is a superset.
This commit is contained in:
Tim Hockin 2023-03-11 10:28:07 -08:00
parent 95e614b371
commit 5f7345deaa
No known key found for this signature in database
2 changed files with 28 additions and 82 deletions

View File

@ -25,7 +25,7 @@ if [ "$#" -lt 4 ] || [ "${1}" == "--help" ]; then
cat <<EOF
Usage: $(basename "$0") <generators> <output-package> <apis-package> <groups-versions> ...
<generators> the generators comma separated to run (deepcopy, defaulter,applyconfiguration,client,lister,informer).
<generators> the generators comma separated to run (deepcopy,defaulter,applyconfiguration,client,lister,informer).
<output-package> the output package name (e.g. github.com/example/project/pkg/generated).
<apis-package> the external types dir (e.g. github.com/example/api or github.com/example/project/pkg/apis).
<groups-versions> the groups and their versions in the format "groupA:v1,v2 groupB:v1 groupC:v2", relative
@ -58,81 +58,5 @@ if [ "${GENS}" = "all" ] || grep -qw "all" <<<"${GENS}"; then
GENS="${ALL}"
fi
(
# To support running this script from anywhere, first cd into this directory,
# and then install with forced module mode on and fully qualified name.
cd "$(dirname "${0}")"
GO111MODULE=on go install k8s.io/code-generator/cmd/{applyconfiguration-gen,client-gen,lister-gen,informer-gen,deepcopy-gen,defaulter-gen}
)
# Go installs the above commands to get installed in $GOBIN if defined, and $GOPATH/bin otherwise:
GOBIN="$(go env GOBIN)"
gobin="${GOBIN:-$(go env GOPATH)/bin}"
function codegen::join() { local IFS="$1"; shift; echo "$*"; }
# enumerate group versions
FQ_APIS=() # e.g. k8s.io/api/apps/v1
for GVs in ${GROUPS_WITH_VERSIONS}; do
IFS=: read -r G Vs <<<"${GVs}"
# enumerate versions
for V in ${Vs//,/ }; do
FQ_APIS+=("${APIS_PKG}/${G}/${V}")
done
done
if grep -qw "deepcopy" <<<"${GENS}"; then
echo "Generating deepcopy funcs"
"${gobin}/deepcopy-gen" \
--input-dirs "$(codegen::join , "${FQ_APIS[@]}")" \
-O zz_generated.deepcopy \
"$@"
fi
if grep -qw "defaulter" <<<"${GENS}"; then
echo "Generating defaulters"
"${gobin}/defaulter-gen" \
--input-dirs "$(codegen::join , "${FQ_APIS[@]}")" \
-O zz_generated.defaults \
"$@"
fi
if grep -qw "applyconfiguration" <<<"${GENS}"; then
echo "Generating apply configuration for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/${APPLYCONFIGURATION_PKG_NAME:-applyconfiguration}"
"${gobin}/applyconfiguration-gen" \
--input-dirs "$(codegen::join , "${FQ_APIS[@]}")" \
--output-package "${OUTPUT_PKG}/${APPLYCONFIGURATION_PKG_NAME:-applyconfiguration}" \
"$@"
fi
if grep -qw "client" <<<"${GENS}"; then
echo "Generating clientset for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}"
if grep -qw "applyconfiguration" <<<"${GENS}"; then
APPLY_CONFIGURATION_PACKAGE="${OUTPUT_PKG}/${APPLYCONFIGURATION_PKG_NAME:-applyconfiguration}"
fi
"${gobin}/client-gen" \
--clientset-name "${CLIENTSET_NAME_VERSIONED:-versioned}" \
--input-base "" \
--input "$(codegen::join , "${FQ_APIS[@]}")" \
--output-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}" \
--apply-configuration-package "${APPLY_CONFIGURATION_PACKAGE:-}" \
"$@"
fi
if grep -qw "lister" <<<"${GENS}"; then
echo "Generating listers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/listers"
"${gobin}/lister-gen" \
--input-dirs "$(codegen::join , "${FQ_APIS[@]}")" \
--output-package "${OUTPUT_PKG}/listers" \
"$@"
fi
if grep -qw "informer" <<<"${GENS}"; then
echo "Generating informers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/informers"
"${gobin}/informer-gen" \
--input-dirs "$(codegen::join , "${FQ_APIS[@]}")" \
--versioned-clientset-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}/${CLIENTSET_NAME_VERSIONED:-versioned}" \
--listers-package "${OUTPUT_PKG}/listers" \
--output-package "${OUTPUT_PKG}/informers" \
"$@"
fi
INT_APIS_PKG=""
exec "$(dirname "${BASH_SOURCE[0]}")/generate-internal-groups.sh" "${GENS}" "${OUTPUT_PKG}" "${INT_APIS_PKG}" "${APIS_PKG}" "${GROUPS_WITH_VERSIONS}" "$@"

View File

@ -25,9 +25,9 @@ if [ "$#" -lt 5 ] || [ "${1}" == "--help" ]; then
cat <<EOF
Usage: $(basename "$0") <generators> <output-package> <internal-apis-package> <extensiona-apis-package> <groups-versions> ...
<generators> the generators comma separated to run (deepcopy,defaulter,conversion,client,lister,informer,openapi).
<generators> the generators comma separated to run (applyconfiguration,client,conversion,deepcopy,defaulter,informer,lister,openapi).
<output-package> the output package name (e.g. github.com/example/project/pkg/generated).
<int-apis-package> the internal types dir (e.g. github.com/example/project/pkg/apis).
<int-apis-package> the internal types dir (e.g. github.com/example/project/pkg/apis) or "" if none.
<ext-apis-package> the external types dir (e.g. github.com/example/project/pkg/apis or githubcom/example/apis).
<groups-versions> the groups and their versions in the format "groupA:v1,v2 groupB:v1 groupC:v2", relative
to <api-package>.
@ -64,7 +64,19 @@ fi
# To support running this script from anywhere, first cd into this directory,
# and then install with forced module mode on and fully qualified name.
cd "$(dirname "${0}")"
GO111MODULE=on go install k8s.io/code-generator/cmd/{defaulter-gen,conversion-gen,client-gen,lister-gen,informer-gen,deepcopy-gen,openapi-gen}
BINS=(
applyconfiguration-gen
client-gen
conversion-gen
deepcopy-gen
defaulter-gen
informer-gen
lister-gen
openapi-gen
)
# Compile all the tools at once - it's slightly faster but also just simpler.
# shellcheck disable=2046 # printf word-splitting is intentional
GO111MODULE=on go install $(printf "k8s.io/code-generator/cmd/%s " "${BINS[@]}")
)
# Go installs the above commands to get installed in $GOBIN if defined, and $GOPATH/bin otherwise:
@ -114,6 +126,15 @@ if grep -qw "conversion" <<<"${GENS}"; then
"$@"
fi
if grep -qw "applyconfiguration" <<<"${GENS}"; then
echo "Generating apply configuration for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/${APPLYCONFIGURATION_PKG_NAME:-applyconfiguration}"
APPLY_CONFIGURATION_PACKAGE="${OUTPUT_PKG}/${APPLYCONFIGURATION_PKG_NAME:-applyconfiguration}"
"${gobin}/applyconfiguration-gen" \
--input-dirs "$(codegen::join , "${EXT_FQ_APIS[@]}")" \
--output-package "${APPLY_CONFIGURATION_PACKAGE}" \
"$@"
fi
if grep -qw "client" <<<"${GENS}"; then
echo "Generating clientset for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}"
"${gobin}/client-gen" \
@ -121,6 +142,7 @@ if grep -qw "client" <<<"${GENS}"; then
--input-base "" \
--input "$(codegen::join , "${EXT_FQ_APIS[@]}")" \
--output-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}" \
--apply-configuration-package "${APPLY_CONFIGURATION_PACKAGE:-}" \
"$@"
fi