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

call kube::golang::setup_env before setting up worktree, cleanup update-mocks.sh #117526

Merged
merged 4 commits into from Apr 22, 2023

Conversation

BenTheElder
Copy link
Member

@BenTheElder BenTheElder commented Apr 21, 2023

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?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Apr 21, 2023
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 21, 2023
@BenTheElder BenTheElder changed the title verify-mocks: call kube::golang::setup_env before setting up worktree call kube::golang::setup_env before setting up worktree Apr 21, 2023
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Apr 21, 2023
@BenTheElder BenTheElder changed the title call kube::golang::setup_env before setting up worktree call kube::golang::setup_env before setting up worktree, cleanup update-mocks.sh Apr 21, 2023
Copy link
Member

@thockin thockin left a 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.

@thockin
Copy link
Member

thockin commented Apr 21, 2023

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

@BenTheElder
Copy link
Member Author

I think you also want:

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.

Copy link
Member

@thockin thockin left a 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

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 21, 2023
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 50252e81b4f2a6f38be5d0118b347abc9effa2b1

@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@@ -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
Copy link
Member Author

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.

@thockin thockin added the sig/architecture Categorizes an issue or PR as relevant to SIG Architecture. label Apr 21, 2023
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. label Apr 21, 2023
@BenTheElder
Copy link
Member Author

/triage accepted
/priority important-soon
(since right now locally verify-mocks is broken, not that the priority label means much ...)

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Apr 21, 2023
@k8s-ci-robot k8s-ci-robot merged commit cb032ec into kubernetes:master Apr 22, 2023
12 of 13 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.28 milestone Apr 22, 2023
@BenTheElder BenTheElder deleted the mock-fun branch April 22, 2023 01:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note-none Denotes a PR that doesn't merit a release note. sig/architecture Categorizes an issue or PR as relevant to SIG Architecture. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

hack/verify-mocks.sh fails on cleanup
3 participants