Change:
<!-- Please use this template while reporting a bug and provide as much info as possible. Not doing so may result in your bug not being addressed in a timely manner. Thanks! If the matter is security related, please disclose it privately via --This issue was moved from What happened: building kubernetes with make fails on mac after What you expected to happen: building should not fail How to reproduce it (as minimally and precisely as possible): build from a mac Anything else we need to know?: mapfile is not available on macOS bash. we should have a version check at minimum if we're going to use unsupported features (some of the code already does this) cc
/sig release
Ugh. Does the containerized build at least still work on Mac? Ideally we'd stick to that as the recommended approach, since we can at least guarantee a correct environment. I guess this is really Apple's fault, for refusing to upgrade the bash version on Macs (so they can avoid GPL) - the default on most Macs is 3.2.57, which dates to 2007 according to this blog post: I don't personally think we should support something that old. None of our CI uses a bash that old. It's ripe for breakage. You can install a newer version of bash via homebrew.
the containerized build does not because this code runs on the host. we should put a version check then, so we get a more understandable error.
Up until this point we have supported it by using instead, macOS's old system bash is annoying, but errors from deep within our bash waste more time supporting confused developers
IIRC even in CI you ran into a bash version problem in fact just yesterday (?) we could add a snippet like this to the main build if we don't want to switch to :
I worry about requiring brew and can imagine some folks systems might be managed in a way that disallow this. Still it's reaaaaally painful having to debug and trying to keep things running with the crufty OSX dev userspace. Given there are multiple snippets of brew install suggestions, it would be better imho to put them in one common top level place (ie: )
fair, On systems with restricted at least should work, if that doesn't work i'd expect the setup is just too restrictive to build at all (?) The check doesn't have to require homebrew per se either, even just "Sorry building on macOS is unsupported" is more helpful than:
Fix inbound:
/assign

Discussion:
# NOTE: All functions that return lists should use newlines. # bash functions can't return arrays, and spaces are tricky, so newline # separators are the preferred pattern. <del> # To transform a string of newline-separated items to an array, use mapfile -t: # mapfile -t FOO <<< "$(kube::golang::dups a b c a)" </del> <ins> # To transform a string of newline-separated items to an array, use kube::util::read-array: # kube::util::read-array FOO < <(kube::golang::dups a b c a) </ins> # # ALWAYS remember to quote your subshells. Not doing so will break in # bash 4.3, and potentially cause other issues.

# Deduplicate to ensure the intersection trick with kube::golang::dups # is not defeated by duplicates in user input. <del> mapfile -t platforms <<< "$(kube::golang::dedup "${platforms[@]}")" </del> <ins> kube::util::read-array platforms < <(kube::golang::dedup "${platforms[@]}") </ins> # Use kube::golang::dups to restrict the builds to the platforms in # KUBE_SUPPORTED_*_PLATFORMS. Items should only appear at most once in each # set, so if they appear twice after the merge they are in the intersection. <del> mapfile -t KUBE_SERVER_PLATFORMS <<< "$(kube::golang::dups  </del> <ins> kube::util::read-array KUBE_SERVER_PLATFORMS < <(kube::golang::dups  </ins> "${platforms[@]}"  "${KUBE_SUPPORTED_SERVER_PLATFORMS[@]}"  <del> )" </del> <ins> ) </ins> readonly KUBE_SERVER_PLATFORMS <del> mapfile -t KUBE_NODE_PLATFORMS <<< "$(kube::golang::dups  </del> <ins> kube::util::read-array KUBE_NODE_PLATFORMS < <(kube::golang::dups  </ins> "${platforms[@]}"  "${KUBE_SUPPORTED_NODE_PLATFORMS[@]}"  <del> )" </del> <ins> ) </ins> readonly KUBE_NODE_PLATFORMS <del> mapfile -t KUBE_TEST_PLATFORMS <<< "$(kube::golang::dups  </del> <ins> kube::util::read-array KUBE_TEST_PLATFORMS < <(kube::golang::dups  </ins> "${platforms[@]}"  "${KUBE_SUPPORTED_TEST_PLATFORMS[@]}"  <del> )" </del> <ins> ) </ins> readonly KUBE_TEST_PLATFORMS <del> mapfile -t KUBE_CLIENT_PLATFORMS <<< "$(kube::golang::dups  </del> <ins> kube::util::read-array KUBE_CLIENT_PLATFORMS < <(kube::golang::dups  </ins> "${platforms[@]}"  "${KUBE_SUPPORTED_CLIENT_PLATFORMS[@]}"  <del> )" </del> <ins> ) </ins> readonly KUBE_CLIENT_PLATFORMS elif [[ "${KUBE_FASTBUILD:-}" == "true" ]]; then

fi } <ins> # kube::util::read-array # Reads in stdin and adds it line by line to the array provided. This can be # used instead of "mapfile -t", and is bash 3 compatible. # # Assumed vars: #   $1 (name of array to create/modify) # # Example usage: # kube::util::read-array files < <(ls -1) # function kube::util::read-array { local i=0 unset -v "$1" while IFS= read -r "$1[i++]"; do :; done eval "[[ ${$1[--i]} ]]" || unset "$1[i]" # ensures last element isn't empty } </ins> # Some useful colors. if [[ -z "${color_start-}" ]]; then declare -r color_start="033["