Skip to content

Commit 0078fce

Browse files
committed
hack/lib/util.sh: don't implicitly convert "find" results into array.
Also fix array item comparison. Test script for the comparison change: #!/bin/bash staging_apis=(extensions/v1beta1 extensions/v1 extensions/v1alpha) group_versions=(v1 extensions/v1beta1 extensions/v1 extensions.k8s.io/v1) for group_version in ${group_versions[@]}; do # original code if [[ " ${staging_apis[@]} " =~ " ${group_version/.*k8s.io/} " ]]; then echo "orig: vendor/k8s.io/api/${group_version/.*k8s.io/}" fi # new code for api in ${staging_apis[@]}; do if [[ "${api}" = "${group_version/.*k8s.io/}" ]]; then echo "new: vendor/k8s.io/api/${group_version/.*k8s.io/}" fi done done Expected output: orig: vendor/k8s.io/api/extensions/v1beta1 new: vendor/k8s.io/api/extensions/v1beta1 orig: vendor/k8s.io/api/extensions/v1 new: vendor/k8s.io/api/extensions/v1 orig: vendor/k8s.io/api/extensions/v1 new: vendor/k8s.io/api/extensions/v1
1 parent edd8063 commit 0078fce

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

hack/lib/util.sh

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,10 @@ kube::util::find-binary-for-platform() {
184184
# The bazel go rules place some binaries in subtrees like
185185
# "bazel-bin/source/path/linux_amd64_pure_stripped/binaryname", so make sure
186186
# the platform name is matched in the path.
187-
locations+=($(find "${KUBE_ROOT}/bazel-bin/" -type f -executable \
188-
\( -path "*/${platform/\//_}*/${lookfor}" -o -path "*/${lookfor}" \) 2>/dev/null || true) )
187+
while IFS=$'\n' read -r location; do
188+
locations+=("$location");
189+
done < <(find "${KUBE_ROOT}/bazel-bin/" -type f -executable \
190+
\( -path "*/${platform/\//_}*/${lookfor}" -o -path "*/${lookfor}" \) 2>/dev/null || true)
189191

190192
# List most recently-updated location.
191193
local -r bin=$( (ls -t "${locations[@]}" 2>/dev/null || true) | head -1 )
@@ -264,18 +266,14 @@ kube::util::remove-gen-docs() {
264266
# * Special handling for groups suffixed with ".k8s.io": foo.k8s.io/v1 -> apis/foo/v1
265267
# * Very special handling for when both group and version are "": / -> api
266268
kube::util::group-version-to-pkg-path() {
267-
staging_apis=(
268-
$(
269-
cd "${KUBE_ROOT}/staging/src/k8s.io/api" &&
270-
find . -name types.go -exec dirname {} \; | sed "s|\./||g" | sort
271-
))
272-
273269
local group_version="$1"
274270

275-
if [[ " ${staging_apis[@]} " =~ " ${group_version/.*k8s.io/} " ]]; then
276-
echo "vendor/k8s.io/api/${group_version/.*k8s.io/}"
277-
return
278-
fi
271+
while IFS=$'\n' read -r api; do
272+
if [[ "${api}" = "${group_version/.*k8s.io/}" ]]; then
273+
echo "vendor/k8s.io/api/${group_version/.*k8s.io/}"
274+
return
275+
fi
276+
done < <(cd "${KUBE_ROOT}/staging/src/k8s.io/api" && find . -name types.go -exec dirname {} \; | sed "s|\./||g" | sort)
279277

280278
# "v1" is the API GroupVersion
281279
if [[ "${group_version}" == "v1" ]]; then

0 commit comments

Comments
 (0)