Skip to content

Commit a9bce21

Browse files
skittk8s-publishing-bot
authored andcommitted
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 <[email protected]> Kubernetes-commit: 4e0e378180d8c8c6165f8980305eafbbd29c940e
1 parent 07ba736 commit a9bce21

File tree

1 file changed

+85
-63
lines changed

1 file changed

+85
-63
lines changed

generate-internal-groups.sh

Lines changed: 85 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ echo "WARNING: $(basename "$0") is deprecated."
5555
echo "WARNING: Please use k8s.io/code-generator/kube_codegen.sh instead."
5656
echo
5757

58+
# If verification only is requested, avoid deleting files
59+
verify_only=""
60+
for ((i = 1; i <= $#; i++)); do
61+
if [ "${!i}" = --verify-only ]; then verify_only=1; fi
62+
done
63+
5864
if [ "${GENS}" = "all" ] || grep -qw "all" <<<"${GENS}"; then
5965
ALL="client,conversion,deepcopy,defaulter,informer,lister,openapi"
6066
echo "WARNING: Specifying \"all\" as a generator is deprecated."
@@ -124,12 +130,14 @@ CLIENTSET_PKG="${CLIENTSET_PKG_NAME:-clientset}"
124130
CLIENTSET_NAME="${CLIENTSET_NAME_VERSIONED:-versioned}"
125131

126132
if grep -qw "deepcopy" <<<"${GENS}"; then
127-
# Nuke existing files
128-
for dir in $(GO111MODULE=on go list -f '{{.Dir}}' "${ALL_FQ_APIS[@]}"); do
129-
pushd "${dir}" >/dev/null
130-
git_find -z ':(glob)**'/zz_generated.deepcopy.go | xargs -0 rm -f
131-
popd >/dev/null
132-
done
133+
if [ ! "$verify_only" ]; then
134+
# Nuke existing files
135+
for dir in $(GO111MODULE=on go list -f '{{.Dir}}' "${ALL_FQ_APIS[@]}"); do
136+
pushd "${dir}" >/dev/null
137+
git_find -z ':(glob)**'/zz_generated.deepcopy.go | xargs -0 rm -f
138+
popd >/dev/null
139+
done
140+
fi
133141

134142
echo "Generating deepcopy funcs"
135143
"${gobin}/deepcopy-gen" \
@@ -139,12 +147,14 @@ if grep -qw "deepcopy" <<<"${GENS}"; then
139147
fi
140148

141149
if grep -qw "defaulter" <<<"${GENS}"; then
142-
# Nuke existing files
143-
for dir in $(GO111MODULE=on go list -f '{{.Dir}}' "${ALL_FQ_APIS[@]}"); do
144-
pushd "${dir}" >/dev/null
145-
git_find -z ':(glob)**'/zz_generated.defaults.go | xargs -0 rm -f
146-
popd >/dev/null
147-
done
150+
if [ ! "$verify_only" ]; then
151+
# Nuke existing files
152+
for dir in $(GO111MODULE=on go list -f '{{.Dir}}' "${ALL_FQ_APIS[@]}"); do
153+
pushd "${dir}" >/dev/null
154+
git_find -z ':(glob)**'/zz_generated.defaults.go | xargs -0 rm -f
155+
popd >/dev/null
156+
done
157+
fi
148158

149159
echo "Generating defaulters"
150160
"${gobin}/defaulter-gen" \
@@ -154,12 +164,14 @@ if grep -qw "defaulter" <<<"${GENS}"; then
154164
fi
155165

156166
if grep -qw "conversion" <<<"${GENS}"; then
157-
# Nuke existing files
158-
for dir in $(GO111MODULE=on go list -f '{{.Dir}}' "${ALL_FQ_APIS[@]}"); do
159-
pushd "${dir}" >/dev/null
160-
git_find -z ':(glob)**'/zz_generated.conversion.go | xargs -0 rm -f
161-
popd >/dev/null
162-
done
167+
if [ ! "$verify_only" ]; then
168+
# Nuke existing files
169+
for dir in $(GO111MODULE=on go list -f '{{.Dir}}' "${ALL_FQ_APIS[@]}"); do
170+
pushd "${dir}" >/dev/null
171+
git_find -z ':(glob)**'/zz_generated.conversion.go | xargs -0 rm -f
172+
popd >/dev/null
173+
done
174+
fi
163175

164176
echo "Generating conversions"
165177
"${gobin}/conversion-gen" \
@@ -171,15 +183,17 @@ fi
171183
if grep -qw "applyconfiguration" <<<"${GENS}"; then
172184
APPLY_CONFIGURATION_PACKAGE="${OUTPUT_PKG}/${APPLYCONFIGURATION_PKG_NAME:-applyconfiguration}"
173185

174-
# Nuke existing files
175-
root="$(GO111MODULE=on go list -f '{{.Dir}}' "${APPLY_CONFIGURATION_PACKAGE}" 2>/dev/null || true)"
176-
if [ -n "${root}" ]; then
177-
pushd "${root}" >/dev/null
178-
git_grep -l --null \
179-
-e '^// Code generated by applyconfiguration-gen. DO NOT EDIT.$' \
180-
':(glob)**/*.go' \
181-
| xargs -0 rm -f
182-
popd >/dev/null
186+
if [ ! "$verify_only" ]; then
187+
# Nuke existing files
188+
root="$(GO111MODULE=on go list -f '{{.Dir}}' "${APPLY_CONFIGURATION_PACKAGE}" 2>/dev/null || true)"
189+
if [ -n "${root}" ]; then
190+
pushd "${root}" >/dev/null
191+
git_grep -l --null \
192+
-e '^// Code generated by applyconfiguration-gen. DO NOT EDIT.$' \
193+
':(glob)**/*.go' \
194+
| xargs -0 rm -f
195+
popd >/dev/null
196+
fi
183197
fi
184198

185199
echo "Generating apply configuration for ${GROUPS_WITH_VERSIONS} at ${APPLY_CONFIGURATION_PACKAGE}"
@@ -190,15 +204,17 @@ if grep -qw "applyconfiguration" <<<"${GENS}"; then
190204
fi
191205

192206
if grep -qw "client" <<<"${GENS}"; then
193-
# Nuke existing files
194-
root="$(GO111MODULE=on go list -f '{{.Dir}}' "${OUTPUT_PKG}/${CLIENTSET_PKG}/${CLIENTSET_NAME}" 2>/dev/null || true)"
195-
if [ -n "${root}" ]; then
196-
pushd "${root}" >/dev/null
197-
git_grep -l --null \
198-
-e '^// Code generated by client-gen. DO NOT EDIT.$' \
199-
':(glob)**/*.go' \
200-
| xargs -0 rm -f
201-
popd >/dev/null
207+
if [ ! "$verify_only" ]; then
208+
# Nuke existing files
209+
root="$(GO111MODULE=on go list -f '{{.Dir}}' "${OUTPUT_PKG}/${CLIENTSET_PKG}/${CLIENTSET_NAME}" 2>/dev/null || true)"
210+
if [ -n "${root}" ]; then
211+
pushd "${root}" >/dev/null
212+
git_grep -l --null \
213+
-e '^// Code generated by client-gen. DO NOT EDIT.$' \
214+
':(glob)**/*.go' \
215+
| xargs -0 rm -f
216+
popd >/dev/null
217+
fi
202218
fi
203219

204220
echo "Generating clientset for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/${CLIENTSET_PKG}"
@@ -212,18 +228,20 @@ if grep -qw "client" <<<"${GENS}"; then
212228
fi
213229

214230
if grep -qw "lister" <<<"${GENS}"; then
215-
# Nuke existing files
216-
for gv in "${GROUP_VERSIONS[@]}"; do
217-
root="$(GO111MODULE=on go list -f '{{.Dir}}' "${OUTPUT_PKG}/listers/${gv}" 2>/dev/null || true)"
218-
if [ -n "${root}" ]; then
219-
pushd "${root}" >/dev/null
220-
git_grep -l --null \
221-
-e '^// Code generated by lister-gen. DO NOT EDIT.$' \
222-
':(glob)**/*.go' \
223-
| xargs -0 rm -f
224-
popd >/dev/null
225-
fi
226-
done
231+
if [ ! "$verify_only" ]; then
232+
# Nuke existing files
233+
for gv in "${GROUP_VERSIONS[@]}"; do
234+
root="$(GO111MODULE=on go list -f '{{.Dir}}' "${OUTPUT_PKG}/listers/${gv}" 2>/dev/null || true)"
235+
if [ -n "${root}" ]; then
236+
pushd "${root}" >/dev/null
237+
git_grep -l --null \
238+
-e '^// Code generated by lister-gen. DO NOT EDIT.$' \
239+
':(glob)**/*.go' \
240+
| xargs -0 rm -f
241+
popd >/dev/null
242+
fi
243+
done
244+
fi
227245

228246
echo "Generating listers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/listers"
229247
"${gobin}/lister-gen" \
@@ -233,15 +251,17 @@ if grep -qw "lister" <<<"${GENS}"; then
233251
fi
234252

235253
if grep -qw "informer" <<<"${GENS}"; then
236-
# Nuke existing files
237-
root="$(GO111MODULE=on go list -f '{{.Dir}}' "${OUTPUT_PKG}/informers/externalversions" 2>/dev/null || true)"
238-
if [ -n "${root}" ]; then
239-
pushd "${root}" >/dev/null
240-
git_grep -l --null \
241-
-e '^// Code generated by informer-gen. DO NOT EDIT.$' \
242-
':(glob)**/*.go' \
243-
| xargs -0 rm -f
244-
popd >/dev/null
254+
if [ ! "$verify_only" ]; then
255+
# Nuke existing files
256+
root="$(GO111MODULE=on go list -f '{{.Dir}}' "${OUTPUT_PKG}/informers/externalversions" 2>/dev/null || true)"
257+
if [ -n "${root}" ]; then
258+
pushd "${root}" >/dev/null
259+
git_grep -l --null \
260+
-e '^// Code generated by informer-gen. DO NOT EDIT.$' \
261+
':(glob)**/*.go' \
262+
| xargs -0 rm -f
263+
popd >/dev/null
264+
fi
245265
fi
246266

247267
echo "Generating informers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/informers"
@@ -254,12 +274,14 @@ if grep -qw "informer" <<<"${GENS}"; then
254274
fi
255275

256276
if grep -qw "openapi" <<<"${GENS}"; then
257-
# Nuke existing files
258-
for dir in $(GO111MODULE=on go list -f '{{.Dir}}' "${FQ_APIS[@]}"); do
259-
pushd "${dir}" >/dev/null
260-
git_find -z ':(glob)**'/zz_generated.openapi.go | xargs -0 rm -f
261-
popd >/dev/null
262-
done
277+
if [ ! "$verify_only" ]; then
278+
# Nuke existing files
279+
for dir in $(GO111MODULE=on go list -f '{{.Dir}}' "${FQ_APIS[@]}"); do
280+
pushd "${dir}" >/dev/null
281+
git_find -z ':(glob)**'/zz_generated.openapi.go | xargs -0 rm -f
282+
popd >/dev/null
283+
done
284+
fi
263285

264286
echo "Generating OpenAPI definitions for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/openapi"
265287
declare -a OPENAPI_EXTRA_PACKAGES

0 commit comments

Comments
 (0)