From 0078fce5bd6f892b7b8e8a7acd42e7104943d314 Mon Sep 17 00:00:00 2001 From: Ismo Puustinen Date: Mon, 18 Feb 2019 16:43:34 +0200 Subject: [PATCH] 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 --- hack/lib/util.sh | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/hack/lib/util.sh b/hack/lib/util.sh index 271e61fac5..2402b8d599 100755 --- a/hack/lib/util.sh +++ b/hack/lib/util.sh @@ -184,8 +184,10 @@ kube::util::find-binary-for-platform() { # The bazel go rules place some 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 \ - \( -path "*/${platform/\//_}*/${lookfor}" -o -path "*/${lookfor}" \) 2>/dev/null || true) ) + while IFS=$'\n' read -r location; do + locations+=("$location"); + done < <(find "${KUBE_ROOT}/bazel-bin/" -type f -executable \ + \( -path "*/${platform/\//_}*/${lookfor}" -o -path "*/${lookfor}" \) 2>/dev/null || true) # List most recently-updated location. local -r bin=$( (ls -t "${locations[@]}" 2>/dev/null || true) | head -1 ) @@ -264,18 +266,14 @@ kube::util::remove-gen-docs() { # * Special handling for groups suffixed with ".k8s.io": foo.k8s.io/v1 -> apis/foo/v1 # * Very special handling for when both group and version are "": / -> api kube::util::group-version-to-pkg-path() { - staging_apis=( - $( - cd "${KUBE_ROOT}/staging/src/k8s.io/api" && - find . -name types.go -exec dirname {} \; | sed "s|\./||g" | sort - )) - local group_version="$1" - if [[ " ${staging_apis[@]} " =~ " ${group_version/.*k8s.io/} " ]]; then - echo "vendor/k8s.io/api/${group_version/.*k8s.io/}" - return - fi + while IFS=$'\n' read -r api; do + if [[ "${api}" = "${group_version/.*k8s.io/}" ]]; then + echo "vendor/k8s.io/api/${group_version/.*k8s.io/}" + return + fi + done < <(cd "${KUBE_ROOT}/staging/src/k8s.io/api" && find . -name types.go -exec dirname {} \; | sed "s|\./||g" | sort) # "v1" is the API GroupVersion if [[ "${group_version}" == "v1" ]]; then