Unverified Commit 39fc3c49 authored by Kubernetes Prow Robot's avatar Kubernetes Prow Robot Committed by GitHub

Merge pull request #78082 from…

Merge pull request #78082 from cblecker/automated-cherry-pick-of-#77362-#77910-#77985-#78048-#78059-upstream-release-1.14 Automated cherry pick of #77362: Don't use mapfile as it isn't bash 3 compatible #77910: fix unbound array variable #77985: fix unbound variable release.sh #78048: Don't use declare -g in build #78059: Check KUBE_SERVER_PLATFORMS existence
parents 28f25269 defab15f
...@@ -137,8 +137,8 @@ readonly KUBE_NODE_BINARIES_WIN=("${KUBE_NODE_BINARIES[@]/%/.exe}") ...@@ -137,8 +137,8 @@ readonly KUBE_NODE_BINARIES_WIN=("${KUBE_NODE_BINARIES[@]/%/.exe}")
# NOTE: All functions that return lists should use newlines. # NOTE: All functions that return lists should use newlines.
# bash functions can't return arrays, and spaces are tricky, so newline # bash functions can't return arrays, and spaces are tricky, so newline
# separators are the preferred pattern. # separators are the preferred pattern.
# To transform a string of newline-separated items to an array, use mapfile -t: # To transform a string of newline-separated items to an array, use kube::util::read-array:
# mapfile -t FOO <<< "$(kube::golang::dups a b c a)" # kube::util::read-array FOO < <(kube::golang::dups a b c a)
# #
# ALWAYS remember to quote your subshells. Not doing so will break in # ALWAYS remember to quote your subshells. Not doing so will break in
# bash 4.3, and potentially cause other issues. # bash 4.3, and potentially cause other issues.
...@@ -163,6 +163,10 @@ kube::golang::dedup() { ...@@ -163,6 +163,10 @@ kube::golang::dedup() {
# to readonly. # to readonly.
# The configured vars will only contain platforms allowed by the # The configured vars will only contain platforms allowed by the
# KUBE_SUPPORTED* vars at the top of this file. # KUBE_SUPPORTED* vars at the top of this file.
declare -a KUBE_SERVER_PLATFORMS
declare -a KUBE_CLIENT_PLATFORMS
declare -a KUBE_NODE_PLATFORMS
declare -a KUBE_TEST_PLATFORMS
kube::golang::setup_platforms() { kube::golang::setup_platforms() {
if [[ -n "${KUBE_BUILD_PLATFORMS:-}" ]]; then if [[ -n "${KUBE_BUILD_PLATFORMS:-}" ]]; then
# KUBE_BUILD_PLATFORMS needs to be read into an array before the next # KUBE_BUILD_PLATFORMS needs to be read into an array before the next
...@@ -172,50 +176,56 @@ kube::golang::setup_platforms() { ...@@ -172,50 +176,56 @@ kube::golang::setup_platforms() {
# Deduplicate to ensure the intersection trick with kube::golang::dups # Deduplicate to ensure the intersection trick with kube::golang::dups
# is not defeated by duplicates in user input. # is not defeated by duplicates in user input.
mapfile -t platforms <<< "$(kube::golang::dedup "${platforms[@]}")" kube::util::read-array platforms < <(kube::golang::dedup "${platforms[@]}")
# Use kube::golang::dups to restrict the builds to the platforms in # Use kube::golang::dups to restrict the builds to the platforms in
# KUBE_SUPPORTED_*_PLATFORMS. Items should only appear at most once in each # 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. # set, so if they appear twice after the merge they are in the intersection.
mapfile -t KUBE_SERVER_PLATFORMS <<< "$(kube::golang::dups \ kube::util::read-array KUBE_SERVER_PLATFORMS < <(kube::golang::dups \
"${platforms[@]}" \ "${platforms[@]}" \
"${KUBE_SUPPORTED_SERVER_PLATFORMS[@]}" \ "${KUBE_SUPPORTED_SERVER_PLATFORMS[@]}" \
)" )
readonly KUBE_SERVER_PLATFORMS readonly KUBE_SERVER_PLATFORMS
mapfile -t KUBE_NODE_PLATFORMS <<< "$(kube::golang::dups \ kube::util::read-array KUBE_NODE_PLATFORMS < <(kube::golang::dups \
"${platforms[@]}" \ "${platforms[@]}" \
"${KUBE_SUPPORTED_NODE_PLATFORMS[@]}" \ "${KUBE_SUPPORTED_NODE_PLATFORMS[@]}" \
)" )
readonly KUBE_NODE_PLATFORMS readonly KUBE_NODE_PLATFORMS
mapfile -t KUBE_TEST_PLATFORMS <<< "$(kube::golang::dups \ kube::util::read-array KUBE_TEST_PLATFORMS < <(kube::golang::dups \
"${platforms[@]}" \ "${platforms[@]}" \
"${KUBE_SUPPORTED_TEST_PLATFORMS[@]}" \ "${KUBE_SUPPORTED_TEST_PLATFORMS[@]}" \
)" )
readonly KUBE_TEST_PLATFORMS readonly KUBE_TEST_PLATFORMS
mapfile -t KUBE_CLIENT_PLATFORMS <<< "$(kube::golang::dups \ kube::util::read-array KUBE_CLIENT_PLATFORMS < <(kube::golang::dups \
"${platforms[@]}" \ "${platforms[@]}" \
"${KUBE_SUPPORTED_CLIENT_PLATFORMS[@]}" \ "${KUBE_SUPPORTED_CLIENT_PLATFORMS[@]}" \
)" )
readonly KUBE_CLIENT_PLATFORMS readonly KUBE_CLIENT_PLATFORMS
elif [[ "${KUBE_FASTBUILD:-}" == "true" ]]; then elif [[ "${KUBE_FASTBUILD:-}" == "true" ]]; then
readonly KUBE_SERVER_PLATFORMS=(linux/amd64) KUBE_SERVER_PLATFORMS=(linux/amd64)
readonly KUBE_NODE_PLATFORMS=(linux/amd64) readonly KUBE_SERVER_PLATFORMS
KUBE_NODE_PLATFORMS=(linux/amd64)
readonly KUBE_NODE_PLATFORMS
if [[ "${KUBE_BUILDER_OS:-}" == "darwin"* ]]; then if [[ "${KUBE_BUILDER_OS:-}" == "darwin"* ]]; then
readonly KUBE_TEST_PLATFORMS=( KUBE_TEST_PLATFORMS=(
darwin/amd64 darwin/amd64
linux/amd64 linux/amd64
) )
readonly KUBE_CLIENT_PLATFORMS=( readonly KUBE_TEST_PLATFORMS
KUBE_CLIENT_PLATFORMS=(
darwin/amd64 darwin/amd64
linux/amd64 linux/amd64
) )
readonly KUBE_CLIENT_PLATFORMS
else else
readonly KUBE_TEST_PLATFORMS=(linux/amd64) KUBE_TEST_PLATFORMS=(linux/amd64)
readonly KUBE_CLIENT_PLATFORMS=(linux/amd64) readonly KUBE_TEST_PLATFORMS
KUBE_CLIENT_PLATFORMS=(linux/amd64)
readonly KUBE_CLIENT_PLATFORMS
fi fi
else else
KUBE_SERVER_PLATFORMS=("${KUBE_SUPPORTED_SERVER_PLATFORMS[@]}") KUBE_SERVER_PLATFORMS=("${KUBE_SUPPORTED_SERVER_PLATFORMS[@]}")
...@@ -292,7 +302,7 @@ kube::golang::server_test_targets() { ...@@ -292,7 +302,7 @@ kube::golang::server_test_targets() {
IFS=" " read -ra KUBE_TEST_SERVER_TARGETS <<< "$(kube::golang::server_test_targets)" IFS=" " read -ra KUBE_TEST_SERVER_TARGETS <<< "$(kube::golang::server_test_targets)"
readonly KUBE_TEST_SERVER_TARGETS readonly KUBE_TEST_SERVER_TARGETS
readonly KUBE_TEST_SERVER_BINARIES=("${KUBE_TEST_SERVER_TARGETS[@]##*/}") readonly KUBE_TEST_SERVER_BINARIES=("${KUBE_TEST_SERVER_TARGETS[@]##*/}")
readonly KUBE_TEST_SERVER_PLATFORMS=("${KUBE_SERVER_PLATFORMS[@]}") readonly KUBE_TEST_SERVER_PLATFORMS=("${KUBE_SERVER_PLATFORMS[@]:+"${KUBE_SERVER_PLATFORMS[@]}"}")
# Gigabytes necessary for parallel platform builds. # Gigabytes necessary for parallel platform builds.
# As of January 2018, RAM usage is exceeding 30G # As of January 2018, RAM usage is exceeding 30G
......
...@@ -817,6 +817,23 @@ function kube::util::require-jq { ...@@ -817,6 +817,23 @@ function kube::util::require-jq {
fi fi
} }
# 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
}
# Some useful colors. # Some useful colors.
if [[ -z "${color_start-}" ]]; then if [[ -z "${color_start-}" ]]; then
declare -r color_start="\033[" declare -r color_start="\033["
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment