diff --git a/cluster/clientbin.sh b/cluster/clientbin.sh index b34a6e65866..a03a2ca3e36 100755 --- a/cluster/clientbin.sh +++ b/cluster/clientbin.sh @@ -84,9 +84,14 @@ function get_bin() { "${KUBE_ROOT}/_output/bin/${bin}" "${KUBE_ROOT}/_output/dockerized/bin/${host_os}/${host_arch}/${bin}" "${KUBE_ROOT}/_output/local/bin/${host_os}/${host_arch}/${bin}" - "${KUBE_ROOT}/bazel-bin/${srcdir}/${bin}" "${KUBE_ROOT}/platforms/${host_os}/${host_arch}/${bin}" ) + # Also search for binary in bazel build tree. + # The bazel go rules place binaries in subtrees like + # "bazel-bin/source/path/linux_amd64_pure_stripped/binaryname", so make sure + # the platform name is matched in the path. + locations+=($(find "${KUBE_ROOT}/bazel-bin/${srcdir}" -type f -executable \ + -path "*/${host_os}_${host_arch}*/${bin}" 2>/dev/null || true) ) echo $( (ls -t "${locations[@]}" 2>/dev/null || true) | head -1 ) } diff --git a/hack/lib/util.sh b/hack/lib/util.sh index 3595a0c6650..0035ced815f 100755 --- a/hack/lib/util.sh +++ b/hack/lib/util.sh @@ -148,10 +148,11 @@ kube::util::find-binary-for-platform() { "${KUBE_ROOT}/platforms/${platform}/${lookfor}" ) # Also search for binary in bazel build tree. - # In some cases we have to name the binary $BINARY_bin, since there was a - # directory named $BINARY next to it. + # The bazel go rules place binaries in subtrees like + # "bazel-bin/source/path/linux_amd64_pure_stripped/binaryname", so make sure + # the platform name is matched in the path. locations+=($(find "${KUBE_ROOT}/bazel-bin/" -type f -executable \ - \( -name "${lookfor}" -o -name "${lookfor}_bin" \) 2>/dev/null || true) ) + -path "*/${platform/\//_}*/${lookfor}" 2>/dev/null || true) ) # List most recently-updated location. local -r bin=$( (ls -t "${locations[@]}" 2>/dev/null || true) | head -1 )