Skip to content

Commit f861e2c

Browse files
committed
Install toolchain files to location provided in KUBEBUILDER_ASSETS if set
Also use sudo only when necessary to create the location
1 parent 4201bc9 commit f861e2c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

hack/toolchain.sh

100755100644
+6-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
set -euo pipefail
33

44
K8S_VERSION="${K8S_VERSION:="1.29.x"}"
5-
KUBEBUILDER_ASSETS="/usr/local/kubebuilder/bin"
5+
KUBEBUILDER_ASSETS="${KUBEBUILDER_ASSETS:-/usr/local/kubebuilder/bin}"
6+
67

78
main() {
89
tools
@@ -32,8 +33,10 @@ tools() {
3233
}
3334

3435
kubebuilder() {
35-
sudo mkdir -p ${KUBEBUILDER_ASSETS}
36-
sudo chown "${USER}" ${KUBEBUILDER_ASSETS}
36+
if ! mkdir -p ${KUBEBUILDER_ASSETS}; then
37+
sudo mkdir -p ${KUBEBUILDER_ASSETS}
38+
sudo chown $(whoami) ${KUBEBUILDER_ASSETS}
39+
fi
3740
arch=$(go env GOARCH)
3841
ln -sf "$(setup-envtest use -p path "${K8S_VERSION}" --arch="${arch}" --bin-dir="${KUBEBUILDER_ASSETS}")"/* ${KUBEBUILDER_ASSETS}
3942
find $KUBEBUILDER_ASSETS

0 commit comments

Comments
 (0)