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
call kube::golang::setup_env before setting up worktree, cleanup update-mocks.sh #117526
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you also want:
diff --git a/hack/lib/golang.sh b/hack/lib/golang.sh
index 94a2efc47e9..fc7d9661e88 100755
--- a/hack/lib/golang.sh
+++ b/hack/lib/golang.sh
@@ -18,7 +18,7 @@
# The golang package that we are building.
readonly KUBE_GO_PACKAGE=k8s.io/kubernetes
-readonly KUBE_GOPATH="${KUBE_OUTPUT}/go"
+export KUBE_GOPATH="${KUBE_GOPATH:-"${KUBE_OUTPUT}/go"}"
# The server platform we are building on.
readonly KUBE_SUPPORTED_SERVER_PLATFORMS=(
I'd also copy the comment about GOCACHE from the codegen scripts and stick it all over.
my scratch notes - let me know if you want to punt it. Your other cleanups in mocks are good too. diff --git a/hack/lib/golang.sh b/hack/lib/golang.sh
index 94a2efc47e9..fc7d9661e88 100755
--- a/hack/lib/golang.sh
+++ b/hack/lib/golang.sh
@@ -18,7 +18,7 @@
# The golang package that we are building.
readonly KUBE_GO_PACKAGE=k8s.io/kubernetes
-readonly KUBE_GOPATH="${KUBE_OUTPUT}/go"
+export KUBE_GOPATH="${KUBE_GOPATH:-"${KUBE_OUTPUT}/go"}"
# The server platform we are building on.
readonly KUBE_SUPPORTED_SERVER_PLATFORMS=(
diff --git a/hack/verify-internal-modules.sh b/hack/verify-internal-modules.sh
index 8ec9678e17f..28496bc3847 100755
--- a/hack/verify-internal-modules.sh
+++ b/hack/verify-internal-modules.sh
@@ -23,13 +23,15 @@ source "${KUBE_ROOT}/hack/lib/init.sh"
kube::util::ensure_clean_working_dir
+# This sets up the environment, like GOCACHE, which keeps the worktree cleaner.
+kube::golang::setup_env
+
_tmpdir="$(kube::realpath "$(mktemp -d -t verify-internal-modules.XXXXXX)")"
-#kube::util::trap_add "rm -rf ${_tmpdir}" EXIT
+kube::util::trap_add "rm -rf ${_tmpdir}" EXIT
_tmp_gopath="${_tmpdir}/go"
_tmp_kuberoot="${_tmp_gopath}/src/k8s.io/kubernetes"
git worktree add -f "${_tmp_kuberoot}" HEAD
-kube::util::trap_add "git worktree remove -f ${_tmp_kuberoot}" EXIT
pushd "${_tmp_kuberoot}" >/dev/null
./hack/update-internal-modules.sh
diff --git a/hack/verify-licenses.sh b/hack/verify-licenses.sh
index 0987e714ea3..2f943255a01 100755
--- a/hack/verify-licenses.sh
+++ b/hack/verify-licenses.sh
@@ -26,26 +26,23 @@ KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${KUBE_ROOT}/hack/lib/init.sh"
source "${KUBE_ROOT}/hack/lib/util.sh"
+# This sets up the environment, like GOCACHE, which keeps the worktree cleaner.
+kube::golang::setup_env
-kube::golang::verify_go_version
kube::util::ensure-temp-dir
-
# Creating a new repository tree
# Deleting vendor directory to make go-licenses fetch license URLs from go-packages source repository
git worktree add -f "${KUBE_TEMP}"/tmp_test_licenses/kubernetes HEAD >/dev/null 2>&1 || true
cd "${KUBE_TEMP}"/tmp_test_licenses/kubernetes && rm -rf vendor
-
# Ensure that we find the binaries we build before anything else.
export GOBIN="${KUBE_OUTPUT_BINPATH}"
PATH="${GOBIN}:${PATH}"
-
# Explicitly opt into go modules, even though we're inside a GOPATH directory
export GO111MODULE=on
-
allowed_licenses=()
packages_flagged=()
packages_url_missing=()
diff --git a/hack/verify-mocks.sh b/hack/verify-mocks.sh
index 07452c7e7db..8806eae45cc 100755
--- a/hack/verify-mocks.sh
+++ b/hack/verify-mocks.sh
@@ -32,6 +32,9 @@ export GO111MODULE=on
kube::util::ensure_clean_working_dir
+# This sets up the environment, like GOCACHE, which keeps the worktree cleaner.
+kube::golang::setup_env
+
_tmpdir="$(kube::realpath "$(mktemp -d -t "$(basename "$0").XXXXXX")")"
git worktree add -f -q "${_tmpdir}" HEAD
kube::util::trap_add "git worktree remove -f ${_tmpdir}" EXIT
diff --git a/hack/verify-yamlfmt.sh b/hack/verify-yamlfmt.sh
index cea2c7edde3..774ed63b255 100755
--- a/hack/verify-yamlfmt.sh
+++ b/hack/verify-yamlfmt.sh
@@ -29,6 +29,9 @@ source "${KUBE_ROOT}/hack/lib/init.sh"
kube::util::ensure_clean_working_dir
+# This sets up the environment, like GOCACHE, which keeps the worktree cleaner.
+kube::golang::setup_env
+
_tmpdir="$(kube::realpath "$(mktemp -d -t "$(basename "$0").XXXXXX")")"
git worktree add -f -q "${_tmpdir}" HEAD
kube::util::trap_add "git worktree remove -f ${_tmpdir}" EXIT |
Agree, slightly modified: 18ae393 -readonly KUBE_GOPATH="${KUBE_OUTPUT}/go"
+readonly KUBE_GOPATH="${KUBE_GOPATH:-"${KUBE_OUTPUT}/go"}"
+export KUBE_GOPATH We can export and still set readonly. Added the GOCACHE comment everywhere and the other changes suggested. |
- remove unused tempdir - use mktemp instead of creating tmpfile in repo - normalize indent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are now on my list of people to send horrible shell PRs too. We thank you for your service.
/lgtm
/approve
LGTM label has been added. Git tree hash: 50252e81b4f2a6f38be5d0118b347abc9effa2b1
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: BenTheElder, thockin The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@@ -26,7 +26,7 @@ kube::util::ensure_clean_working_dir | |||
kube::golang::setup_env | |||
|
|||
_tmpdir="$(kube::realpath "$(mktemp -d -t verify-internal-modules.XXXXXX)")" | |||
#kube::util::trap_add "rm -rf ${_tmpdir}" EXIT | |||
kube::util::trap_add "rm -rf ${_tmpdir:?}" EXIT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thockin lost your LGTM pulling this one out
Also adding :?
because even though we just set _tmpdir we should encourage the habit of rm -rf ${foo:?}
to prevent accidents like rm -rf "${foo:}/"
where $foo is unset.
/triage accepted |
What type of PR is this?
/kind cleanup
Alternate to #117525
Fixes #117272
Ensures we persist GOCACHE etc through git worktree.
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: