From 5c6b065f335e23ae080a4cbdff3b54f32d50ae87 Mon Sep 17 00:00:00 2001 From: Derek Su Date: Fri, 24 Nov 2023 03:16:59 +0000 Subject: [PATCH] k8s: fix generate_code.sh Fix "unbound variable" error if GOPATH is not set correctly. Signed-off-by: Derek Su --- k8s/generate_code.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/k8s/generate_code.sh b/k8s/generate_code.sh index e37cc2d928..db526d82c4 100755 --- a/k8s/generate_code.sh +++ b/k8s/generate_code.sh @@ -14,9 +14,16 @@ CODE_GENERATOR_VERSION="v0.18.0" CRDS_DIR="crds" CONTROLLER_TOOLS_VERSION="v0.7.0" KUSTOMIZE_VERSION="kustomize/v3.10.0" +GOPATH="${GOPATH:-}" -if [[ -z "${GOPATH}" ]]; then - GOPATH=~/go + +if [[ -z "$GOPATH" ]]; then + GOPATH="$(go env GOPATH)" + + if [[ -z "$GOPATH" ]]; then + echo "GOPATH is not set" + exit 1 + fi fi # https://github.com/kubernetes/code-generator/blob/v0.18.0/generate-groups.sh