Skip to content

Commit 2e5be31

Browse files
thockink8s-publishing-bot
authored andcommitted
EOL code-generator/generate-groups scripts
There's no easy way to make it work in the new model. Callers add flags to the commandline like: ``` "${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 "${SCRIPT_DIR}/../../../.." \ --go-header-file "${SCRIPT_DIR}/boilerplate.go.txt" ``` To support this we would need to parse these flags in these scripts and try to adapt them to the new CLI tool interfaces. Not impossible, but seeing as we deprecated these a few releases ago AND that we have other breaking changes to the tools, let's just rip this bandaid off? Kubernetes-commit: 7776496309c49f91c15ca929d6e27442ae6b83dc
1 parent 01a8118 commit 2e5be31

File tree

2 files changed

+6
-326
lines changed

2 files changed

+6
-326
lines changed

generate-groups.sh

+3-49
Original file line numberDiff line numberDiff line change
@@ -14,53 +14,7 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
set -o errexit
18-
set -o nounset
19-
set -o pipefail
20-
21-
# generate-groups generates everything for a project with external types only, e.g. a project based
22-
# on CustomResourceDefinitions.
23-
24-
if [ "$#" -lt 4 ] || [ "${1}" == "--help" ]; then
25-
cat <<EOF
26-
Usage: $(basename "$0") <generators> <output-package> <apis-package> <groups-versions> ...
27-
28-
<generators> the generators comma separated to run (deepcopy,defaulter,applyconfiguration,client,lister,informer).
29-
<output-package> the output package name (e.g. github.com/example/project/pkg/generated).
30-
<apis-package> the external types dir (e.g. github.com/example/api or github.com/example/project/pkg/apis).
31-
<groups-versions> the groups and their versions in the format "groupA:v1,v2 groupB:v1 groupC:v2", relative
32-
to <api-package>.
33-
... arbitrary flags passed to all generator binaries.
34-
35-
36-
Example:
37-
$(basename "$0") \
38-
deepcopy,client \
39-
github.com/example/project/pkg/client \
40-
github.com/example/project/pkg/apis \
41-
"foo:v1 bar:v1alpha1,v1beta1"
42-
EOF
43-
exit 0
44-
fi
45-
46-
GENS="$1"
47-
OUTPUT_PKG="$2"
48-
APIS_PKG="$3"
49-
GROUPS_WITH_VERSIONS="$4"
50-
shift 4
51-
52-
echo "WARNING: $(basename "$0") is deprecated."
53-
echo "WARNING: Please use k8s.io/code-generator/kube_codegen.sh instead."
17+
echo "ERROR: $(basename "$0") has been removed."
18+
echo "ERROR: Please use k8s.io/code-generator/kube_codegen.sh instead."
5419
echo
55-
56-
if [ "${GENS}" = "all" ] || grep -qw "all" <<<"${GENS}"; then
57-
ALL="applyconfiguration,client,deepcopy,informer,lister"
58-
echo "WARNING: Specifying \"all\" as a generator is deprecated."
59-
echo "WARNING: Please list the specific generators needed."
60-
echo "WARNING: \"all\" is now an alias for \"${ALL}\"; new code generators WILL NOT be added to this set"
61-
echo
62-
GENS="${ALL}"
63-
fi
64-
65-
INT_APIS_PKG=""
66-
exec "$(dirname "${BASH_SOURCE[0]}")/generate-internal-groups.sh" "${GENS}" "${OUTPUT_PKG}" "${INT_APIS_PKG}" "${APIS_PKG}" "${GROUPS_WITH_VERSIONS}" "$@"
20+
exit 1

generate-internal-groups.sh

+3-277
Original file line numberDiff line numberDiff line change
@@ -14,281 +14,7 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
set -o errexit
18-
set -o nounset
19-
set -o pipefail
20-
21-
# generate-internal-groups generates everything for a project with internal types, e.g. an
22-
# user-provided API server based on k8s.io/apiserver.
23-
24-
if [ "$#" -lt 5 ] || [ "${1}" == "--help" ]; then
25-
cat <<EOF
26-
Usage: $(basename "$0") <generators> <output-package> <internal-apis-package> <extensiona-apis-package> <groups-versions> ...
27-
28-
<generators> the generators comma separated to run (applyconfiguration,client,conversion,deepcopy,defaulter,informer,lister,openapi).
29-
<output-package> the output package name (e.g. github.com/example/project/pkg/generated).
30-
<int-apis-package> the internal types dir (e.g. github.com/example/project/pkg/apis) or "" if none.
31-
<ext-apis-package> the external types dir (e.g. github.com/example/project/pkg/apis or githubcom/example/apis).
32-
<groups-versions> the groups and their versions in the format "groupA:v1,v2 groupB:v1 groupC:v2", relative
33-
to <api-package>.
34-
... arbitrary flags passed to all generator binaries.
35-
36-
Example:
37-
$(basename "$0") \
38-
deepcopy,defaulter,conversion \
39-
github.com/example/project/pkg/client \
40-
github.com/example/project/pkg/apis \
41-
github.com/example/project/apis \
42-
"foo:v1 bar:v1alpha1,v1beta1"
43-
EOF
44-
exit 0
45-
fi
46-
47-
GENS="$1"
48-
OUTPUT_PKG="$2"
49-
INT_APIS_PKG="$3"
50-
EXT_APIS_PKG="$4"
51-
GROUPS_WITH_VERSIONS="$5"
52-
shift 5
53-
54-
echo "WARNING: $(basename "$0") is deprecated."
55-
echo "WARNING: Please use k8s.io/code-generator/kube_codegen.sh instead."
17+
echo "ERROR: $(basename "$0") has been removed."
18+
echo "ERROR: Please use k8s.io/code-generator/kube_codegen.sh instead."
5619
echo
57-
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-
64-
if [ "${GENS}" = "all" ] || grep -qw "all" <<<"${GENS}"; then
65-
ALL="client,conversion,deepcopy,defaulter,informer,lister,openapi"
66-
echo "WARNING: Specifying \"all\" as a generator is deprecated."
67-
echo "WARNING: Please list the specific generators needed."
68-
echo "WARNING: \"all\" is now an alias for \"${ALL}\"; new code generators WILL NOT be added to this set"
69-
echo
70-
GENS="${ALL}"
71-
fi
72-
73-
(
74-
# To support running this script from anywhere, first cd into this directory,
75-
# and then install with forced module mode on and fully qualified name.
76-
cd "$(dirname "${0}")"
77-
BINS=(
78-
applyconfiguration-gen
79-
client-gen
80-
conversion-gen
81-
deepcopy-gen
82-
defaulter-gen
83-
informer-gen
84-
lister-gen
85-
openapi-gen
86-
)
87-
# Compile all the tools at once - it's slightly faster but also just simpler.
88-
# shellcheck disable=2046 # printf word-splitting is intentional
89-
GO111MODULE=on go install $(printf "k8s.io/code-generator/cmd/%s " "${BINS[@]}")
90-
)
91-
92-
# Go installs the above commands to get installed in $GOBIN if defined, and $GOPATH/bin otherwise:
93-
GOBIN="$(go env GOBIN)"
94-
gobin="${GOBIN:-$(go env GOPATH)/bin}"
95-
96-
function git_find() {
97-
# Similar to find but faster and easier to understand. We want to include
98-
# modified and untracked files because this might be running against code
99-
# which is not tracked by git yet.
100-
git ls-files -cmo --exclude-standard "$@"
101-
}
102-
103-
function git_grep() {
104-
# We want to include modified and untracked files because this might be
105-
# running against code which is not tracked by git yet.
106-
git grep --untracked "$@"
107-
}
108-
function codegen::join() { local IFS="$1"; shift; echo "$*"; }
109-
110-
# enumerate group versions
111-
ALL_FQ_APIS=() # e.g. k8s.io/kubernetes/pkg/apis/apps k8s.io/api/apps/v1
112-
EXT_FQ_APIS=() # e.g. k8s.io/api/apps/v1
113-
GROUP_VERSIONS=() # e.g. apps/v1
114-
for GVs in ${GROUPS_WITH_VERSIONS}; do
115-
IFS=: read -r G Vs <<<"${GVs}"
116-
117-
if [ -n "${INT_APIS_PKG}" ]; then
118-
ALL_FQ_APIS+=("${INT_APIS_PKG}/${G}")
119-
fi
120-
121-
# enumerate versions
122-
for V in ${Vs//,/ }; do
123-
ALL_FQ_APIS+=("${EXT_APIS_PKG}/${G}/${V}")
124-
EXT_FQ_APIS+=("${EXT_APIS_PKG}/${G}/${V}")
125-
GROUP_VERSIONS+=("${G}/${V}")
126-
done
127-
done
128-
129-
CLIENTSET_PKG="${CLIENTSET_PKG_NAME:-clientset}"
130-
CLIENTSET_NAME="${CLIENTSET_NAME_VERSIONED:-versioned}"
131-
132-
if grep -qw "deepcopy" <<<"${GENS}"; then
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
141-
142-
echo "Generating deepcopy funcs"
143-
"${gobin}/deepcopy-gen" \
144-
--input-dirs "$(codegen::join , "${ALL_FQ_APIS[@]}")" \
145-
-O zz_generated.deepcopy \
146-
"$@"
147-
fi
148-
149-
if grep -qw "defaulter" <<<"${GENS}"; then
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
158-
159-
echo "Generating defaulters"
160-
"${gobin}/defaulter-gen" \
161-
--input-dirs "$(codegen::join , "${EXT_FQ_APIS[@]}")" \
162-
-O zz_generated.defaults \
163-
"$@"
164-
fi
165-
166-
if grep -qw "conversion" <<<"${GENS}"; then
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
175-
176-
echo "Generating conversions"
177-
"${gobin}/conversion-gen" \
178-
--input-dirs "$(codegen::join , "${ALL_FQ_APIS[@]}")" \
179-
-O zz_generated.conversion \
180-
"$@"
181-
fi
182-
183-
if grep -qw "applyconfiguration" <<<"${GENS}"; then
184-
APPLY_CONFIGURATION_PACKAGE="${OUTPUT_PKG}/${APPLYCONFIGURATION_PKG_NAME:-applyconfiguration}"
185-
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
197-
fi
198-
199-
echo "Generating apply configuration for ${GROUPS_WITH_VERSIONS} at ${APPLY_CONFIGURATION_PACKAGE}"
200-
"${gobin}/applyconfiguration-gen" \
201-
--input-dirs "$(codegen::join , "${EXT_FQ_APIS[@]}")" \
202-
--output-package "${APPLY_CONFIGURATION_PACKAGE}" \
203-
"$@"
204-
fi
205-
206-
if grep -qw "client" <<<"${GENS}"; then
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
218-
fi
219-
220-
echo "Generating clientset for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/${CLIENTSET_PKG}"
221-
"${gobin}/client-gen" \
222-
--clientset-name "${CLIENTSET_NAME}" \
223-
--input-base "" \
224-
--input "$(codegen::join , "${EXT_FQ_APIS[@]}")" \
225-
--output-package "${OUTPUT_PKG}/${CLIENTSET_PKG}" \
226-
--apply-configuration-package "${APPLY_CONFIGURATION_PACKAGE:-}" \
227-
"$@"
228-
fi
229-
230-
if grep -qw "lister" <<<"${GENS}"; then
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
245-
246-
echo "Generating listers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/listers"
247-
"${gobin}/lister-gen" \
248-
--input-dirs "$(codegen::join , "${EXT_FQ_APIS[@]}")" \
249-
--output-package "${OUTPUT_PKG}/listers" \
250-
"$@"
251-
fi
252-
253-
if grep -qw "informer" <<<"${GENS}"; then
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
265-
fi
266-
267-
echo "Generating informers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/informers"
268-
"${gobin}/informer-gen" \
269-
--input-dirs "$(codegen::join , "${EXT_FQ_APIS[@]}")" \
270-
--versioned-clientset-package "${OUTPUT_PKG}/${CLIENTSET_PKG}/${CLIENTSET_NAME}" \
271-
--listers-package "${OUTPUT_PKG}/listers" \
272-
--output-package "${OUTPUT_PKG}/informers" \
273-
"$@"
274-
fi
275-
276-
if grep -qw "openapi" <<<"${GENS}"; then
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
285-
286-
echo "Generating OpenAPI definitions for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/openapi"
287-
declare -a OPENAPI_EXTRA_PACKAGES
288-
"${gobin}/openapi-gen" \
289-
--input-dirs "$(codegen::join , "${EXT_FQ_APIS[@]}" "${OPENAPI_EXTRA_PACKAGES[@]+"${OPENAPI_EXTRA_PACKAGES[@]}"}")" \
290-
--input-dirs "k8s.io/apimachinery/pkg/apis/meta/v1,k8s.io/apimachinery/pkg/runtime,k8s.io/apimachinery/pkg/version" \
291-
--output-package "${OUTPUT_PKG}/openapi" \
292-
-O zz_generated.openapi \
293-
"$@"
294-
fi
20+
exit 1

0 commit comments

Comments
 (0)