codegen: don't nuke files if only verifying

The code generation tools support verification only with the
--verify-only option, but this now fails because the files are nuked
ahead of time.

Signed-off-by: Stephen Kitt <skitt@redhat.com>
This commit is contained in:
Stephen Kitt 2024-02-13 13:38:05 +01:00
parent dbd3f3564a
commit 1b1b902f81
No known key found for this signature in database
GPG Key ID: 1CC5FA453662A71D

View File

@ -55,6 +55,12 @@ echo "WARNING: $(basename "$0") is deprecated."
echo "WARNING: Please use k8s.io/code-generator/kube_codegen.sh instead."
echo
# If verification only is requested, avoid deleting files
verify_only=""
for ((i = 1; i <= $#; i++)); do
if [ "${!i}" = --verify-only ]; then verify_only=1; fi
done
if [ "${GENS}" = "all" ] || grep -qw "all" <<<"${GENS}"; then
ALL="client,conversion,deepcopy,defaulter,informer,lister,openapi"
echo "WARNING: Specifying \"all\" as a generator is deprecated."
@ -124,12 +130,14 @@ CLIENTSET_PKG="${CLIENTSET_PKG_NAME:-clientset}"
CLIENTSET_NAME="${CLIENTSET_NAME_VERSIONED:-versioned}"
if grep -qw "deepcopy" <<<"${GENS}"; then
if [ ! "$verify_only" ]; then
# Nuke existing files
for dir in $(GO111MODULE=on go list -f '{{.Dir}}' "${ALL_FQ_APIS[@]}"); do
pushd "${dir}" >/dev/null
git_find -z ':(glob)**'/zz_generated.deepcopy.go | xargs -0 rm -f
popd >/dev/null
done
fi
echo "Generating deepcopy funcs"
"${gobin}/deepcopy-gen" \
@ -139,12 +147,14 @@ if grep -qw "deepcopy" <<<"${GENS}"; then
fi
if grep -qw "defaulter" <<<"${GENS}"; then
if [ ! "$verify_only" ]; then
# Nuke existing files
for dir in $(GO111MODULE=on go list -f '{{.Dir}}' "${ALL_FQ_APIS[@]}"); do
pushd "${dir}" >/dev/null
git_find -z ':(glob)**'/zz_generated.defaults.go | xargs -0 rm -f
popd >/dev/null
done
fi
echo "Generating defaulters"
"${gobin}/defaulter-gen" \
@ -154,12 +164,14 @@ if grep -qw "defaulter" <<<"${GENS}"; then
fi
if grep -qw "conversion" <<<"${GENS}"; then
if [ ! "$verify_only" ]; then
# Nuke existing files
for dir in $(GO111MODULE=on go list -f '{{.Dir}}' "${ALL_FQ_APIS[@]}"); do
pushd "${dir}" >/dev/null
git_find -z ':(glob)**'/zz_generated.conversion.go | xargs -0 rm -f
popd >/dev/null
done
fi
echo "Generating conversions"
"${gobin}/conversion-gen" \
@ -171,6 +183,7 @@ fi
if grep -qw "applyconfiguration" <<<"${GENS}"; then
APPLY_CONFIGURATION_PACKAGE="${OUTPUT_PKG}/${APPLYCONFIGURATION_PKG_NAME:-applyconfiguration}"
if [ ! "$verify_only" ]; then
# Nuke existing files
root="$(GO111MODULE=on go list -f '{{.Dir}}' "${APPLY_CONFIGURATION_PACKAGE}" 2>/dev/null || true)"
if [ -n "${root}" ]; then
@ -181,6 +194,7 @@ if grep -qw "applyconfiguration" <<<"${GENS}"; then
| xargs -0 rm -f
popd >/dev/null
fi
fi
echo "Generating apply configuration for ${GROUPS_WITH_VERSIONS} at ${APPLY_CONFIGURATION_PACKAGE}"
"${gobin}/applyconfiguration-gen" \
@ -190,6 +204,7 @@ if grep -qw "applyconfiguration" <<<"${GENS}"; then
fi
if grep -qw "client" <<<"${GENS}"; then
if [ ! "$verify_only" ]; then
# Nuke existing files
root="$(GO111MODULE=on go list -f '{{.Dir}}' "${OUTPUT_PKG}/${CLIENTSET_PKG}/${CLIENTSET_NAME}" 2>/dev/null || true)"
if [ -n "${root}" ]; then
@ -200,6 +215,7 @@ if grep -qw "client" <<<"${GENS}"; then
| xargs -0 rm -f
popd >/dev/null
fi
fi
echo "Generating clientset for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/${CLIENTSET_PKG}"
"${gobin}/client-gen" \
@ -212,6 +228,7 @@ if grep -qw "client" <<<"${GENS}"; then
fi
if grep -qw "lister" <<<"${GENS}"; then
if [ ! "$verify_only" ]; then
# Nuke existing files
for gv in "${GROUP_VERSIONS[@]}"; do
root="$(GO111MODULE=on go list -f '{{.Dir}}' "${OUTPUT_PKG}/listers/${gv}" 2>/dev/null || true)"
@ -224,6 +241,7 @@ if grep -qw "lister" <<<"${GENS}"; then
popd >/dev/null
fi
done
fi
echo "Generating listers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/listers"
"${gobin}/lister-gen" \
@ -233,6 +251,7 @@ if grep -qw "lister" <<<"${GENS}"; then
fi
if grep -qw "informer" <<<"${GENS}"; then
if [ ! "$verify_only" ]; then
# Nuke existing files
root="$(GO111MODULE=on go list -f '{{.Dir}}' "${OUTPUT_PKG}/informers/externalversions" 2>/dev/null || true)"
if [ -n "${root}" ]; then
@ -243,6 +262,7 @@ if grep -qw "informer" <<<"${GENS}"; then
| xargs -0 rm -f
popd >/dev/null
fi
fi
echo "Generating informers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/informers"
"${gobin}/informer-gen" \
@ -254,12 +274,14 @@ if grep -qw "informer" <<<"${GENS}"; then
fi
if grep -qw "openapi" <<<"${GENS}"; then
if [ ! "$verify_only" ]; then
# Nuke existing files
for dir in $(GO111MODULE=on go list -f '{{.Dir}}' "${FQ_APIS[@]}"); do
pushd "${dir}" >/dev/null
git_find -z ':(glob)**'/zz_generated.openapi.go | xargs -0 rm -f
popd >/dev/null
done
fi
echo "Generating OpenAPI definitions for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/openapi"
declare -a OPENAPI_EXTRA_PACKAGES