diff --git a/hack/generate-groups.sh b/hack/generate-groups.sh index 3e9276643ba..cfc2576a856 100755 --- a/hack/generate-groups.sh +++ b/hack/generate-groups.sh @@ -46,8 +46,12 @@ APIS_PKG="$3" GROUPS_WITH_VERSIONS="$4" shift 4 -GO111MODULE=off go get k8s.io/code-generator/cmd/{defaulter-gen,client-gen,lister-gen,informer-gen,deepcopy-gen,conversion-gen} - +( + # 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,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)" gobin="${GOBIN:-$(go env GOPATH)/bin}" @@ -67,7 +71,7 @@ done if [ "${GENS}" = "all" ] || grep -qw "deepcopy" <<<"${GENS}"; then echo "Generating deepcopy funcs" - "${gobin}/deepcopy-gen" --input-dirs "$(codegen::join , "${FQ_APIS[@]}")" -O zz_generated.deepcopy --bounding-dirs "${APIS_PKG}" "$@" + "${gobin}/deepcopy-gen" --input-dirs "$(codegen::join , "${FQ_APIS[@]}")" -O zz_generated.deepcopy "$@" fi if [ "${GENS}" = "all" ] || grep -qw "client" <<<"${GENS}"; then diff --git a/hack/generate-internal-groups.sh b/hack/generate-internal-groups.sh index b8d7c5de427..2c114a37039 100755 --- a/hack/generate-internal-groups.sh +++ b/hack/generate-internal-groups.sh @@ -47,11 +47,12 @@ EXT_APIS_PKG="$4" GROUPS_WITH_VERSIONS="$5" shift 5 -GO111MODULE=off go get k8s.io/code-generator/cmd/{defaulter-gen,client-gen,lister-gen,informer-gen,deepcopy-gen,conversion-gen,openapi-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}" +( + # 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} +) function codegen::join() { local IFS="$1"; shift; echo "$*"; } @@ -76,36 +77,36 @@ 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 --bounding-dirs "${INT_APIS_PKG},${EXT_APIS_PKG}" "$@" + "${GOPATH}/bin/deepcopy-gen" --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 "$@" + "${GOPATH}/bin/defaulter-gen" --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 "$@" + "${GOPATH}/bin/conversion-gen" --input-dirs "$(codegen::join , "${ALL_FQ_APIS[@]}")" -O zz_generated.conversion "$@" fi if [ "${GENS}" = "all" ] || grep -qw "client" <<<"${GENS}"; then echo "Generating clientset for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}" if [ -n "${INT_APIS_PKG}" ]; then IFS=" " read -r -a APIS <<< "$(printf '%s/ ' "${INT_FQ_APIS[@]}")" - "${gobin}/client-gen" --clientset-name "${CLIENTSET_NAME_INTERNAL:-internalversion}" --input-base "" --input "$(codegen::join , "${APIS[@]}")" --output-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}" "$@" + "${GOPATH}/bin/client-gen" --clientset-name "${CLIENTSET_NAME_INTERNAL:-internalversion}" --input-base "" --input "$(codegen::join , "${APIS[@]}")" --output-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}" "$@" fi - "${gobin}/client-gen" --clientset-name "${CLIENTSET_NAME_VERSIONED:-versioned}" --input-base "" --input "$(codegen::join , "${EXT_FQ_APIS[@]}")" --output-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}" "$@" + "${GOPATH}/bin/client-gen" --clientset-name "${CLIENTSET_NAME_VERSIONED:-versioned}" --input-base "" --input "$(codegen::join , "${EXT_FQ_APIS[@]}")" --output-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}" "$@" fi if [ "${GENS}" = "all" ] || grep -qw "lister" <<<"${GENS}"; then echo "Generating listers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/listers" - "${gobin}/lister-gen" --input-dirs "$(codegen::join , "${ALL_FQ_APIS[@]}")" --output-package "${OUTPUT_PKG}/listers" "$@" + "${GOPATH}/bin/lister-gen" --input-dirs "$(codegen::join , "${ALL_FQ_APIS[@]}")" --output-package "${OUTPUT_PKG}/listers" "$@" fi if [ "${GENS}" = "all" ] || grep -qw "informer" <<<"${GENS}"; then echo "Generating informers for ${GROUPS_WITH_VERSIONS} at ${OUTPUT_PKG}/informers" - "${gobin}/informer-gen" \ + "${GOPATH}/bin/informer-gen" \ --input-dirs "$(codegen::join , "${ALL_FQ_APIS[@]}")" \ --versioned-clientset-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}/${CLIENTSET_NAME_VERSIONED:-versioned}" \ --internal-clientset-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME:-clientset}/${CLIENTSET_NAME_INTERNAL:-internalversion}" \ @@ -117,8 +118,8 @@ fi if [ "${GENS}" = "all" ] || 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" \ - --input-dirs "$(codegen::join , "${EXT_FQ_APIS[@]}" "${OPENAPI_EXTRA_PACKAGES[@]}")" \ + "${GOPATH}/bin/openapi-gen" \ + --input-dirs "$(codegen::join , "${EXT_FQ_APIS[@]}" "${OPENAPI_EXTRA_PACKAGES[@]+"${OPENAPI_EXTRA_PACKAGES[@]}"}")" \ --input-dirs "k8s.io/apimachinery/pkg/apis/meta/v1,k8s.io/apimachinery/pkg/runtime,k8s.io/apimachinery/pkg/version" \ --output-package "${OUTPUT_PKG}/openapi" \ -O zz_generated.openapi \ diff --git a/hack/update-gencode.sh b/hack/update-gencode.sh index 31568008eaa..903f01ef5e6 100755 --- a/hack/update-gencode.sh +++ b/hack/update-gencode.sh @@ -26,12 +26,12 @@ SCRIPT_ROOT=$(unset CDPATH && cd $(dirname "${BASH_SOURCE[0]}")/.. && pwd) # --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. -bash vendor/k8s.io/code-generator/generate-groups.sh "deepcopy,client,informer,lister" \ +bash hack/generate-groups.sh "deepcopy,client,informer,lister" \ volcano.sh/apis/pkg/client volcano.sh/apis/pkg/apis \ "batch:v1alpha1 bus:v1alpha1 scheduling:v1beta1" \ --go-header-file ${SCRIPT_ROOT}/hack/boilerplate/boilerplate.go.txt -bash vendor/k8s.io/code-generator/generate-internal-groups.sh "deepcopy,conversion" \ +bash hack/generate-internal-groups.sh "deepcopy,conversion" \ volcano.sh/apis/pkg/apis/ volcano.sh/apis/pkg/apis volcano.sh/apis/pkg/apis\ "scheduling:v1beta1" \ --output-base "$(dirname "${BASH_SOURCE[0]}")/../../.." \