Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid to depend on local env when installing the code-generators #1810

Merged
merged 1 commit into from
May 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions hack/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,25 @@ set -o pipefail
SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
ROOT_PKG=github.com/kubeflow/training-operator

# Grab code-generator version from go.sum
CODEGEN_VERSION=$(grep 'k8s.io/code-generator' go.mod | awk '{print $2}')
CODEGEN_PKG=$(echo $(go env GOPATH)"/pkg/mod/k8s.io/code-generator@${CODEGEN_VERSION}")
GET_PKG_LOCATION() {
pkg_name="${1:-}"

pkg_location="$(go list -m -f '{{.Dir}}' "${pkg_name}" 2>/dev/null)"
if [ "${pkg_location}" = "" ]; then
echo "${pkg_name} is missing. Running 'go mod download'."

if [[ ! -d ${CODEGEN_PKG} ]]; then
echo "${CODEGEN_PKG} is missing. Running 'go mod download'."
go mod download
fi
pkg_location=$(go list -m -f '{{.Dir}}' "${pkg_name}")
fi
echo "${pkg_location}"
}

# Grab code-generator version from go.sum
CODEGEN_PKG="$(GET_PKG_LOCATION "k8s.io/code-generator")"
echo ">> Using ${CODEGEN_PKG}"

# Grab openapi-gen version from go.mod
OPENAPI_VERSION=$(grep 'k8s.io/kube-openapi' go.mod | awk '{print $2}')
OPENAPI_PKG=$(echo $(go env GOPATH)"/pkg/mod/k8s.io/kube-openapi@${OPENAPI_VERSION}")

if [[ ! -d ${OPENAPI_PKG} ]]; then
echo "${OPENAPI_PKG} is missing. Running 'go mod download'."
go mod download
fi

OPENAPI_PKG="$(GET_PKG_LOCATION 'k8s.io/kube-openapi')"
echo ">> Using ${OPENAPI_PKG}"

# code-generator does work with go.mod but makes assumptions about
Expand Down