From 201653aa870a1dda817496f39e4ef1da24cf68af Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Fri, 10 Mar 2023 21:14:14 -0800 Subject: [PATCH 1/7] Trivial change to reduce diffs This just makes it easier to diff generate-groups and generate-internal-groups --- .../k8s.io/code-generator/generate-internal-groups.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/staging/src/k8s.io/code-generator/generate-internal-groups.sh b/staging/src/k8s.io/code-generator/generate-internal-groups.sh index 3dd2c231666..3aa268a84b5 100755 --- a/staging/src/k8s.io/code-generator/generate-internal-groups.sh +++ b/staging/src/k8s.io/code-generator/generate-internal-groups.sh @@ -80,21 +80,24 @@ done if [ "${GENS}" = "all" ] || grep -qw "deepcopy" <<<"${GENS}"; then echo "Generating deepcopy funcs" "${gobin}/deepcopy-gen" \ - --input-dirs "$(codegen::join , "${ALL_FQ_APIS[@]}")" -O zz_generated.deepcopy \ + --input-dirs "$(codegen::join , "${ALL_FQ_APIS[@]}")" \ + -O zz_generated.deepcopy \ "$@" fi if [ "${GENS}" = "all" ] || grep -qw "defaulter" <<<"${GENS}"; then echo "Generating defaulters" "${gobin}/defaulter-gen" \ - --input-dirs "$(codegen::join , "${EXT_FQ_APIS[@]}")" -O zz_generated.defaults \ + --input-dirs "$(codegen::join , "${EXT_FQ_APIS[@]}")" \ + -O zz_generated.defaults \ "$@" fi if [ "${GENS}" = "all" ] || grep -qw "conversion" <<<"${GENS}"; then echo "Generating conversions" "${gobin}/conversion-gen" \ - --input-dirs "$(codegen::join , "${ALL_FQ_APIS[@]}")" -O zz_generated.conversion \ + --input-dirs "$(codegen::join , "${ALL_FQ_APIS[@]}")" \ + -O zz_generated.conversion \ "$@" fi From 5200f4b0d36cb0862abf1450de86c52e47ce9bfa Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Fri, 10 Mar 2023 21:27:44 -0800 Subject: [PATCH 2/7] Codegen subprojects: reify 'all' into explicit --- .../examples/client-go/hack/update-codegen.sh | 2 +- staging/src/k8s.io/code-generator/generate-groups.sh | 4 ++-- staging/src/k8s.io/code-generator/hack/update-codegen.sh | 8 ++++---- .../src/k8s.io/sample-apiserver/hack/update-codegen.sh | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/staging/src/k8s.io/apiextensions-apiserver/examples/client-go/hack/update-codegen.sh b/staging/src/k8s.io/apiextensions-apiserver/examples/client-go/hack/update-codegen.sh index 577c4e6b9f0..e3d87c3f10e 100755 --- a/staging/src/k8s.io/apiextensions-apiserver/examples/client-go/hack/update-codegen.sh +++ b/staging/src/k8s.io/apiextensions-apiserver/examples/client-go/hack/update-codegen.sh @@ -25,7 +25,7 @@ CODEGEN_PKG=${CODEGEN_PKG:-$(cd "${SCRIPT_ROOT}"; ls -d -1 ./vendor/k8s.io/code- # --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. -"${CODEGEN_PKG}/generate-groups.sh" all \ +"${CODEGEN_PKG}/generate-groups.sh" "applyconfiguration,client,deepcopy,informer,lister" \ k8s.io/apiextensions-apiserver/examples/client-go/pkg/client \ k8s.io/apiextensions-apiserver/examples/client-go/pkg/apis \ cr:v1 \ diff --git a/staging/src/k8s.io/code-generator/generate-groups.sh b/staging/src/k8s.io/code-generator/generate-groups.sh index a511ef17284..8e993294c63 100755 --- a/staging/src/k8s.io/code-generator/generate-groups.sh +++ b/staging/src/k8s.io/code-generator/generate-groups.sh @@ -25,7 +25,7 @@ if [ "$#" -lt 4 ] || [ "${1}" == "--help" ]; then cat < ... - the generators comma separated to run (deepcopy,defaulter,applyconfiguration,client,lister,informer) or "all". + the generators comma separated to run (deepcopy,applyconfiguration,client,lister,informer) or "all". the output package name (e.g. github.com/example/project/pkg/generated). the external types dir (e.g. github.com/example/api or github.com/example/project/pkg/apis). the groups and their versions in the format "groupA:v1,v2 groupB:v1 groupC:v2", relative @@ -50,7 +50,7 @@ shift 4 # 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,defaulter-gen,client-gen,lister-gen,informer-gen,deepcopy-gen} + GO111MODULE=on go install k8s.io/code-generator/cmd/{applyconfiguration-gen,client-gen,lister-gen,informer-gen,deepcopy-gen} ) # Go installs the above commands to get installed in $GOBIN if defined, and $GOPATH/bin otherwise: GOBIN="$(go env GOBIN)" diff --git a/staging/src/k8s.io/code-generator/hack/update-codegen.sh b/staging/src/k8s.io/code-generator/hack/update-codegen.sh index ce0f073a61a..ff4dd288aa2 100755 --- a/staging/src/k8s.io/code-generator/hack/update-codegen.sh +++ b/staging/src/k8s.io/code-generator/hack/update-codegen.sh @@ -24,26 +24,26 @@ SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. # - --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" all \ +"${SCRIPT_ROOT}/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" all \ +"${SCRIPT_ROOT}/generate-groups.sh" "applyconfiguration,client,deepcopy,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" all \ +"${SCRIPT_ROOT}/generate-groups.sh" "applyconfiguration,client,deepcopy,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" all \ +"${SCRIPT_ROOT}/generate-groups.sh" "applyconfiguration,client,deepcopy,informer,lister" \ k8s.io/code-generator/examples/HyphenGroup \ k8s.io/code-generator/examples/HyphenGroup/apis \ "example:v1" \ diff --git a/staging/src/k8s.io/sample-apiserver/hack/update-codegen.sh b/staging/src/k8s.io/sample-apiserver/hack/update-codegen.sh index 9fd4e236dc0..c3b4e45659d 100755 --- a/staging/src/k8s.io/sample-apiserver/hack/update-codegen.sh +++ b/staging/src/k8s.io/sample-apiserver/hack/update-codegen.sh @@ -25,7 +25,7 @@ CODEGEN_PKG=${CODEGEN_PKG:-$(cd "${SCRIPT_ROOT}"; ls -d -1 ./vendor/k8s.io/code- # --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. -"${CODEGEN_PKG}/generate-groups.sh" all \ +"${CODEGEN_PKG}/generate-groups.sh" "applyconfiguration,client,deepcopy,informer,lister" \ k8s.io/sample-apiserver/pkg/generated \ k8s.io/sample-apiserver/pkg/apis \ "wardle:v1alpha1,v1beta1" \ From 8b68e063e1491df575f59ca9c7782dda1e1f64ed Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Fri, 10 Mar 2023 21:46:31 -0800 Subject: [PATCH 3/7] Codegen subprojects: regen defaulters when needed If you manually remove generated defaults, they do not get regenerated without this. --- .../apiextensions-apiserver/hack/update-codegen.sh | 2 +- staging/src/k8s.io/code-generator/generate-groups.sh | 12 ++++++++++-- .../src/k8s.io/code-generator/hack/update-codegen.sh | 6 +++--- .../k8s.io/kube-aggregator/hack/update-codegen.sh | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/staging/src/k8s.io/apiextensions-apiserver/hack/update-codegen.sh b/staging/src/k8s.io/apiextensions-apiserver/hack/update-codegen.sh index 8261e98d56a..f5dc31758ca 100755 --- a/staging/src/k8s.io/apiextensions-apiserver/hack/update-codegen.sh +++ b/staging/src/k8s.io/apiextensions-apiserver/hack/update-codegen.sh @@ -23,7 +23,7 @@ CODEGEN_PKG=${CODEGEN_PKG:-$(cd "${SCRIPT_ROOT}"; ls -d -1 ./vendor/k8s.io/code- CLIENTSET_NAME_VERSIONED=clientset \ CLIENTSET_PKG_NAME=clientset \ -"${CODEGEN_PKG}/generate-groups.sh" "deepcopy,client,lister,informer" \ +"${CODEGEN_PKG}/generate-groups.sh" "deepcopy,defaulter,client,lister,informer" \ k8s.io/apiextensions-apiserver/pkg/client \ k8s.io/apiextensions-apiserver/pkg/apis \ "apiextensions:v1beta1,v1" \ diff --git a/staging/src/k8s.io/code-generator/generate-groups.sh b/staging/src/k8s.io/code-generator/generate-groups.sh index 8e993294c63..63fb68bb6be 100755 --- a/staging/src/k8s.io/code-generator/generate-groups.sh +++ b/staging/src/k8s.io/code-generator/generate-groups.sh @@ -25,7 +25,7 @@ if [ "$#" -lt 4 ] || [ "${1}" == "--help" ]; then cat < ... - the generators comma separated to run (deepcopy,applyconfiguration,client,lister,informer) or "all". + the generators comma separated to run (deepcopy, defaulter,applyconfiguration,client,lister,informer) or "all". the output package name (e.g. github.com/example/project/pkg/generated). the external types dir (e.g. github.com/example/api or github.com/example/project/pkg/apis). the groups and their versions in the format "groupA:v1,v2 groupB:v1 groupC:v2", relative @@ -50,7 +50,7 @@ shift 4 # 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} + 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)" @@ -77,6 +77,14 @@ if [ "${GENS}" = "all" ] || grep -qw "deepcopy" <<<"${GENS}"; then "$@" fi +if [ "${GENS}" = "all" ] || grep -qw "defaulter" <<<"${GENS}"; then + echo "Generating defaulters" + "${gobin}/defaulter-gen" \ + --input-dirs "$(codegen::join , "${FQ_APIS[@]}")" \ + -O zz_generated.defaults \ + "$@" +fi + if [ "${GENS}" = "all" ] || grep -qw "applyconfiguration" <<<"${GENS}"; then echo "Generating apply configuration for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/${APPLYCONFIGURATION_PKG_NAME:-applyconfiguration}" "${gobin}/applyconfiguration-gen" \ diff --git a/staging/src/k8s.io/code-generator/hack/update-codegen.sh b/staging/src/k8s.io/code-generator/hack/update-codegen.sh index ff4dd288aa2..27cfd431b33 100755 --- a/staging/src/k8s.io/code-generator/hack/update-codegen.sh +++ b/staging/src/k8s.io/code-generator/hack/update-codegen.sh @@ -31,19 +31,19 @@ SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. "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,informer,lister" \ +"${SCRIPT_ROOT}/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,informer,lister" \ +"${SCRIPT_ROOT}/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,informer,lister" \ +"${SCRIPT_ROOT}/generate-groups.sh" "applyconfiguration,client,deepcopy,defaulter,informer,lister" \ k8s.io/code-generator/examples/HyphenGroup \ k8s.io/code-generator/examples/HyphenGroup/apis \ "example:v1" \ diff --git a/staging/src/k8s.io/kube-aggregator/hack/update-codegen.sh b/staging/src/k8s.io/kube-aggregator/hack/update-codegen.sh index f85abd44ccc..ef04f9bd650 100755 --- a/staging/src/k8s.io/kube-aggregator/hack/update-codegen.sh +++ b/staging/src/k8s.io/kube-aggregator/hack/update-codegen.sh @@ -23,7 +23,7 @@ CODEGEN_PKG=${CODEGEN_PKG:-$(cd "${SCRIPT_ROOT}"; ls -d -1 ./vendor/k8s.io/code- CLIENTSET_NAME_VERSIONED=clientset \ CLIENTSET_PKG_NAME=clientset_generated \ -"${CODEGEN_PKG}/generate-groups.sh" "deepcopy,client,lister,informer" \ +"${CODEGEN_PKG}/generate-groups.sh" "deepcopy,defaulter,client,lister,informer" \ k8s.io/kube-aggregator/pkg/client \ k8s.io/kube-aggregator/pkg/apis \ "apiregistration:v1beta1,v1" \ From a94ed5b8ac863b1d408d3a3ae713a8a5d4f3368d Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Fri, 10 Mar 2023 21:59:37 -0800 Subject: [PATCH 4/7] Codegen metrics: include v1beta2 This is why these scripts are terrible - open-coded lists always drift. We will have to tackle that later. --- staging/src/k8s.io/metrics/hack/update-codegen.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/staging/src/k8s.io/metrics/hack/update-codegen.sh b/staging/src/k8s.io/metrics/hack/update-codegen.sh index 633146dbf94..7c4f1cbd827 100755 --- a/staging/src/k8s.io/metrics/hack/update-codegen.sh +++ b/staging/src/k8s.io/metrics/hack/update-codegen.sh @@ -32,7 +32,7 @@ CODEGEN_PKG=${CODEGEN_PKG:-$(cd "${SCRIPT_ROOT}"; ls -d -1 ./vendor/k8s.io/code- k8s.io/metrics/pkg/client \ k8s.io/metrics/pkg/apis \ k8s.io/metrics/pkg/apis \ - "metrics:v1alpha1,v1beta1 custom_metrics:v1beta1 external_metrics:v1beta1" \ + "metrics:v1alpha1,v1beta1 custom_metrics:v1beta1,v1beta2 external_metrics:v1beta1" \ --output-base "$(dirname "${BASH_SOURCE[0]}")/../../.." \ --go-header-file "${SCRIPT_ROOT}/hack/boilerplate.go.txt" "${CODEGEN_PKG}/generate-groups.sh" "client" \ From 95e614b371744ec80ef995a87e5a63c9e246378f Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Sat, 11 Mar 2023 09:54:09 -0800 Subject: [PATCH 5/7] Codegen subprojects: deprecate "all" in scripts Replace "all" with the historical meaning of it in the generate-groups scripts. --- .../k8s.io/code-generator/generate-groups.sh | 34 ++++++++++++------ .../generate-internal-groups.sh | 35 +++++++++++++------ 2 files changed, 47 insertions(+), 22 deletions(-) diff --git a/staging/src/k8s.io/code-generator/generate-groups.sh b/staging/src/k8s.io/code-generator/generate-groups.sh index 63fb68bb6be..9436bff016a 100755 --- a/staging/src/k8s.io/code-generator/generate-groups.sh +++ b/staging/src/k8s.io/code-generator/generate-groups.sh @@ -25,7 +25,7 @@ if [ "$#" -lt 4 ] || [ "${1}" == "--help" ]; then cat < ... - the generators comma separated to run (deepcopy, defaulter,applyconfiguration,client,lister,informer) or "all". + the generators comma separated to run (deepcopy, defaulter,applyconfiguration,client,lister,informer). the output package name (e.g. github.com/example/project/pkg/generated). the external types dir (e.g. github.com/example/api or github.com/example/project/pkg/apis). the groups and their versions in the format "groupA:v1,v2 groupB:v1 groupC:v2", relative @@ -33,9 +33,12 @@ Usage: $(basename "$0") ... - the generators comma separated to run (deepcopy,defaulter,conversion,client,lister,informer,openapi) or "all". + the generators comma separated to run (deepcopy,defaulter,conversion,client,lister,informer,openapi). the output package name (e.g. github.com/example/project/pkg/generated). the internal types dir (e.g. github.com/example/project/pkg/apis). the external types dir (e.g. github.com/example/project/pkg/apis or githubcom/example/apis). @@ -33,9 +33,13 @@ Usage: $(basename "$0") . ... arbitrary flags passed to all generator binaries. -Examples: - $(basename "$0") all github.com/example/project/pkg/client github.com/example/project/pkg/apis github.com/example/project/pkg/apis "foo:v1 bar:v1alpha1,v1beta1" - $(basename "$0") deepcopy,defaulter,conversion github.com/example/project/pkg/client github.com/example/project/pkg/apis github.com/example/project/apis "foo:v1 bar:v1alpha1,v1beta1" +Example: + $(basename "$0") \ + deepcopy,defaulter,conversion \ + github.com/example/project/pkg/client \ + github.com/example/project/pkg/apis \ + github.com/example/project/apis \ + "foo:v1 bar:v1alpha1,v1beta1" EOF exit 0 fi @@ -47,6 +51,15 @@ EXT_APIS_PKG="$4" GROUPS_WITH_VERSIONS="$5" shift 5 +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." + echo "WARNING: Please list the specific generators needed." + echo "WARNING: \"all\" is now an alias for \"${ALL}\"" + echo + 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. @@ -77,7 +90,7 @@ for GVs in ${GROUPS_WITH_VERSIONS}; do done done -if [ "${GENS}" = "all" ] || grep -qw "deepcopy" <<<"${GENS}"; then +if grep -qw "deepcopy" <<<"${GENS}"; then echo "Generating deepcopy funcs" "${gobin}/deepcopy-gen" \ --input-dirs "$(codegen::join , "${ALL_FQ_APIS[@]}")" \ @@ -85,7 +98,7 @@ if [ "${GENS}" = "all" ] || grep -qw "deepcopy" <<<"${GENS}"; then "$@" fi -if [ "${GENS}" = "all" ] || grep -qw "defaulter" <<<"${GENS}"; then +if grep -qw "defaulter" <<<"${GENS}"; then echo "Generating defaulters" "${gobin}/defaulter-gen" \ --input-dirs "$(codegen::join , "${EXT_FQ_APIS[@]}")" \ @@ -93,7 +106,7 @@ if [ "${GENS}" = "all" ] || grep -qw "defaulter" <<<"${GENS}"; then "$@" fi -if [ "${GENS}" = "all" ] || grep -qw "conversion" <<<"${GENS}"; then +if grep -qw "conversion" <<<"${GENS}"; then echo "Generating conversions" "${gobin}/conversion-gen" \ --input-dirs "$(codegen::join , "${ALL_FQ_APIS[@]}")" \ @@ -101,7 +114,7 @@ if [ "${GENS}" = "all" ] || grep -qw "conversion" <<<"${GENS}"; then "$@" fi -if [ "${GENS}" = "all" ] || grep -qw "client" <<<"${GENS}"; then +if grep -qw "client" <<<"${GENS}"; then echo "Generating clientset for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}" "${gobin}/client-gen" \ --clientset-name "${CLIENTSET_NAME_VERSIONED:-versioned}" \ @@ -111,7 +124,7 @@ if [ "${GENS}" = "all" ] || grep -qw "client" <<<"${GENS}"; then "$@" fi -if [ "${GENS}" = "all" ] || grep -qw "lister" <<<"${GENS}"; then +if grep -qw "lister" <<<"${GENS}"; then echo "Generating listers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/listers" "${gobin}/lister-gen" \ --input-dirs "$(codegen::join , "${EXT_FQ_APIS[@]}")" \ @@ -119,7 +132,7 @@ if [ "${GENS}" = "all" ] || grep -qw "lister" <<<"${GENS}"; then "$@" fi -if [ "${GENS}" = "all" ] || grep -qw "informer" <<<"${GENS}"; then +if grep -qw "informer" <<<"${GENS}"; then echo "Generating informers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/informers" "${gobin}/informer-gen" \ --input-dirs "$(codegen::join , "${EXT_FQ_APIS[@]}")" \ @@ -129,7 +142,7 @@ if [ "${GENS}" = "all" ] || grep -qw "informer" <<<"${GENS}"; then "$@" fi -if [ "${GENS}" = "all" ] || grep -qw "openapi" <<<"${GENS}"; then +if grep -qw "openapi" <<<"${GENS}"; then echo "Generating OpenAPI definitions for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/openapi" declare -a OPENAPI_EXTRA_PACKAGES "${gobin}/openapi-gen" \ From 5f7345deaac946d8fa060e866ea0d20aadbef462 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Sat, 11 Mar 2023 10:28:07 -0800 Subject: [PATCH 6/7] 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. --- .../k8s.io/code-generator/generate-groups.sh | 82 +------------------ .../generate-internal-groups.sh | 28 ++++++- 2 files changed, 28 insertions(+), 82 deletions(-) diff --git a/staging/src/k8s.io/code-generator/generate-groups.sh b/staging/src/k8s.io/code-generator/generate-groups.sh index 9436bff016a..487f75da187 100755 --- a/staging/src/k8s.io/code-generator/generate-groups.sh +++ b/staging/src/k8s.io/code-generator/generate-groups.sh @@ -25,7 +25,7 @@ if [ "$#" -lt 4 ] || [ "${1}" == "--help" ]; then cat < ... - the generators comma separated to run (deepcopy, defaulter,applyconfiguration,client,lister,informer). + the generators comma separated to run (deepcopy,defaulter,applyconfiguration,client,lister,informer). the output package name (e.g. github.com/example/project/pkg/generated). the external types dir (e.g. github.com/example/api or github.com/example/project/pkg/apis). 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}" "$@" diff --git a/staging/src/k8s.io/code-generator/generate-internal-groups.sh b/staging/src/k8s.io/code-generator/generate-internal-groups.sh index 32ee4d1e070..ae5bf1f5b67 100755 --- a/staging/src/k8s.io/code-generator/generate-internal-groups.sh +++ b/staging/src/k8s.io/code-generator/generate-internal-groups.sh @@ -25,9 +25,9 @@ if [ "$#" -lt 5 ] || [ "${1}" == "--help" ]; then cat < ... - the generators comma separated to run (deepcopy,defaulter,conversion,client,lister,informer,openapi). + the generators comma separated to run (applyconfiguration,client,conversion,deepcopy,defaulter,informer,lister,openapi). the output package name (e.g. github.com/example/project/pkg/generated). - the internal types dir (e.g. github.com/example/project/pkg/apis). + the internal types dir (e.g. github.com/example/project/pkg/apis) or "" if none. the external types dir (e.g. github.com/example/project/pkg/apis or githubcom/example/apis). the groups and their versions in the format "groupA:v1,v2 groupB:v1 groupC:v2", relative to . @@ -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 From af29cca6cededbfa1fb51264b69687a9d3c01f48 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Tue, 11 Apr 2023 12:44:40 -0700 Subject: [PATCH 7/7] Codegen: new tools will not become part of 'all' --- staging/src/k8s.io/code-generator/generate-groups.sh | 2 +- staging/src/k8s.io/code-generator/generate-internal-groups.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/staging/src/k8s.io/code-generator/generate-groups.sh b/staging/src/k8s.io/code-generator/generate-groups.sh index 487f75da187..742719c7a9d 100755 --- a/staging/src/k8s.io/code-generator/generate-groups.sh +++ b/staging/src/k8s.io/code-generator/generate-groups.sh @@ -53,7 +53,7 @@ if [ "${GENS}" = "all" ] || grep -qw "all" <<<"${GENS}"; then ALL="applyconfiguration,client,deepcopy,informer,lister" echo "WARNING: Specifying \"all\" as a generator is deprecated." echo "WARNING: Please list the specific generators needed." - echo "WARNING: \"all\" is now an alias for \"${ALL}\"" + echo "WARNING: \"all\" is now an alias for \"${ALL}\"; new code generators WILL NOT be added to this set" echo GENS="${ALL}" fi diff --git a/staging/src/k8s.io/code-generator/generate-internal-groups.sh b/staging/src/k8s.io/code-generator/generate-internal-groups.sh index ae5bf1f5b67..c953375bc92 100755 --- a/staging/src/k8s.io/code-generator/generate-internal-groups.sh +++ b/staging/src/k8s.io/code-generator/generate-internal-groups.sh @@ -55,7 +55,7 @@ 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." echo "WARNING: Please list the specific generators needed." - echo "WARNING: \"all\" is now an alias for \"${ALL}\"" + echo "WARNING: \"all\" is now an alias for \"${ALL}\"; new code generators WILL NOT be added to this set" echo GENS="${ALL}" fi