diff --git a/cluster-autoscaler/hack/update-codegen.sh b/cluster-autoscaler/hack/update-codegen.sh index b7793d6fc777..483393415b02 100755 --- a/cluster-autoscaler/hack/update-codegen.sh +++ b/cluster-autoscaler/hack/update-codegen.sh @@ -23,19 +23,30 @@ set -o errexit set -o nounset set -o pipefail -SCRIPT_ROOT=$(realpath $(dirname "${BASH_SOURCE[0]}"))/.. -CODEGEN_PKG="../vendor/k8s.io/code-generator" -pushd "${SCRIPT_ROOT}/apis" - -chmod +x "${CODEGEN_PKG}"/generate-groups.sh -chmod +x "${CODEGEN_PKG}"/generate-internal-groups.sh - -bash "${CODEGEN_PKG}"/generate-groups.sh "applyconfiguration,client,deepcopy,informer,lister" \ - k8s.io/autoscaler/cluster-autoscaler/apis/provisioningrequest/client \ - k8s.io/autoscaler/cluster-autoscaler/apis/provisioningrequest \ - autoscaling.x-k8s.io:v1beta1 \ - --go-header-file "${SCRIPT_ROOT}"/../hack/boilerplate/boilerplate.generatego.txt - -chmod -x "${CODEGEN_PKG}"/generate-groups.sh -chmod -x "${CODEGEN_PKG}"/generate-internal-groups.sh -popd +GO_CMD=${1:-go} +CURRENT_DIR=$(dirname "${BASH_SOURCE[0]}") +REPO_ROOT="$(git rev-parse --show-toplevel)" +CODEGEN_PKG=$($GO_CMD list -m -mod=readonly -f "{{.Dir}}" k8s.io/code-generator) +cd "${CURRENT_DIR}/.." + +# shellcheck source=/dev/null +source "${CODEGEN_PKG}/kube_codegen.sh" + +kube::codegen::gen_helpers \ + --boilerplate "${REPO_ROOT}/hack/boilerplate/boilerplate.generatego.txt" \ + "${REPO_ROOT}/cluster-autoscaler/apis/provisioningrequest" + +echo "Ran gen helpers, moving on to generating client code..." + +kube::codegen::gen_client \ + --output-pkg k8s.io/autoscaler/cluster-autoscaler/apis/provisioningrequest/client \ + --output-dir "${REPO_ROOT}/cluster-autoscaler/apis/provisioningrequest/client" \ + --boilerplate "${REPO_ROOT}/hack/boilerplate/boilerplate.generatego.txt" \ + --with-watch \ + --with-applyconfig \ + "${REPO_ROOT}/cluster-autoscaler/apis/provisioningrequest" + +echo "Generated client code, running `go mod tidy`..." + +# We need to clean up the go.mod file since code-generator adds temporary library to the go.mod file. +"${GO_CMD}" mod tidy