Merge pull request #73150 from rlenferink/patch-2

Improved some more bash script variable definitions
pull/564/head
Kubernetes Prow Robot 2019-01-23 12:20:17 -08:00 committed by GitHub
commit 4e340f450f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 72 additions and 72 deletions

View File

@ -48,9 +48,9 @@ kube::etcd::validate() {
# validate installed version is at least equal to minimum
version=$(etcd --version | tail -n +1 | head -n 1 | cut -d " " -f 3)
if [[ $(kube::etcd::version ${ETCD_VERSION}) -gt $(kube::etcd::version ${version}) ]]; then
export PATH=${KUBE_ROOT}/third_party/etcd:$PATH
export PATH=${KUBE_ROOT}/third_party/etcd:${PATH}
hash etcd
echo $PATH
echo "${PATH}"
version=$(etcd --version | head -n 1 | cut -d " " -f 3)
if [[ $(kube::etcd::version ${ETCD_VERSION}) -gt $(kube::etcd::version ${version}) ]]; then
kube::log::usage "etcd version ${ETCD_VERSION} or greater required."

View File

@ -88,10 +88,10 @@ readonly KUBE_NODE_BINARIES=("${KUBE_NODE_TARGETS[@]##*/}")
readonly KUBE_NODE_BINARIES_WIN=("${KUBE_NODE_BINARIES[@]/%/.exe}")
if [[ -n "${KUBE_BUILD_PLATFORMS:-}" ]]; then
IFS=" " read -ra KUBE_SERVER_PLATFORMS <<< "$KUBE_BUILD_PLATFORMS"
IFS=" " read -ra KUBE_NODE_PLATFORMS <<< "$KUBE_BUILD_PLATFORMS"
IFS=" " read -ra KUBE_TEST_PLATFORMS <<< "$KUBE_BUILD_PLATFORMS"
IFS=" " read -ra KUBE_CLIENT_PLATFORMS <<< "$KUBE_BUILD_PLATFORMS"
IFS=" " read -ra KUBE_SERVER_PLATFORMS <<< "${KUBE_BUILD_PLATFORMS}"
IFS=" " read -ra KUBE_NODE_PLATFORMS <<< "${KUBE_BUILD_PLATFORMS}"
IFS=" " read -ra KUBE_TEST_PLATFORMS <<< "${KUBE_BUILD_PLATFORMS}"
IFS=" " read -ra KUBE_CLIENT_PLATFORMS <<< "${KUBE_BUILD_PLATFORMS}"
readonly KUBE_SERVER_PLATFORMS
readonly KUBE_NODE_PLATFORMS
readonly KUBE_TEST_PLATFORMS
@ -268,11 +268,11 @@ kube::golang::is_statically_linked_library() {
[[ "$(go env GOHOSTOS)" == "darwin" && "$(go env GOOS)" == "darwin" &&
"$1" == *"/kubectl" ]] && return 1
if [[ -n "${KUBE_CGO_OVERRIDES:+x}" ]]; then
for e in "${KUBE_CGO_OVERRIDES[@]}"; do [[ "$1" == *"/$e" ]] && return 1; done;
for e in "${KUBE_CGO_OVERRIDES[@]}"; do [[ "${1}" == *"/${e}" ]] && return 1; done;
fi
for e in "${KUBE_STATIC_LIBRARIES[@]}"; do [[ "$1" == *"/$e" ]] && return 0; done;
for e in "${KUBE_STATIC_LIBRARIES[@]}"; do [[ "${1}" == *"/${e}" ]] && return 0; done;
if [[ -n "${KUBE_STATIC_OVERRIDES:+x}" ]]; then
for e in "${KUBE_STATIC_OVERRIDES[@]}"; do [[ "$1" == *"/$e" ]] && return 0; done;
for e in "${KUBE_STATIC_OVERRIDES[@]}"; do [[ "${1}" == *"/${e}" ]] && return 0; done;
fi
return 1;
}
@ -426,7 +426,7 @@ kube::golang::setup_env() {
# resultant binaries. Go will not let us use GOBIN with `go install` and
# cross-compiling, and `go install -o <file>` only works for a single pkg.
local subdir
subdir=$(kube::realpath . | sed "s|$KUBE_ROOT||")
subdir=$(kube::realpath . | sed "s|${KUBE_ROOT}||")
cd "${KUBE_GOPATH}/src/${KUBE_GO_PACKAGE}/${subdir}"
# Set GOROOT so binaries that parse code can work properly.
@ -458,7 +458,7 @@ kube::golang::place_bins() {
# The substitution on platform_src below will replace all slashes with
# underscores. It'll transform darwin/amd64 -> darwin_amd64.
local platform_src="/${platform//\//_}"
if [[ "$platform" == "$host_platform" ]]; then
if [[ "${platform}" == "${host_platform}" ]]; then
platform_src=""
rm -f "${THIS_PLATFORM_BIN}"
ln -s "${KUBE_OUTPUT_BINPATH}/${platform}" "${THIS_PLATFORM_BIN}"
@ -479,7 +479,7 @@ kube::golang::outfile_for_binary() {
local binary=$1
local platform=$2
local output_path="${KUBE_GOPATH}/bin"
if [[ "$platform" != "$host_platform" ]]; then
if [[ "${platform}" != "${host_platform}" ]]; then
output_path="${output_path}/${platform//\//_}"
fi
local bin=$(basename "${binary}")
@ -502,7 +502,7 @@ kube::golang::path_for_coverage_dummy_test() {
local package="$1"
local path="${KUBE_GOPATH}/src/${package}"
local name=$(basename "${package}")
echo "$path/zz_generated_${name}_test.go"
echo "${path}/zz_generated_${name}_test.go"
}
# Argument: the name of a Kubernetes package (e.g. k8s.io/kubernetes/cmd/kube-scheduler).

View File

@ -132,15 +132,15 @@ KUBE_NONSERVER_GROUP_VERSIONS="
function kube::readlinkdashf {
# run in a subshell for simpler 'cd'
(
if [[ -d "$1" ]]; then # This also catch symlinks to dirs.
cd "$1"
if [[ -d "${1}" ]]; then # This also catch symlinks to dirs.
cd "${1}"
pwd -P
else
cd "$(dirname "$1")"
cd "$(dirname "${1}")"
local f
f=$(basename "$1")
if [[ -L "$f" ]]; then
readlink "$f"
f=$(basename "${1}")
if [[ -L "${f}" ]]; then
readlink "${f}"
else
echo "$(pwd -P)/${f}"
fi
@ -176,9 +176,9 @@ function kube::readlinkdashf {
# testone $T/linkdir/linkfile
# testone $T/linkdir/linkdir
kube::realpath() {
if [[ ! -e "$1" ]]; then
echo "$1: No such file or directory" >&2
if [[ ! -e "${1}" ]]; then
echo "${1}: No such file or directory" >&2
return 1
fi
kube::readlinkdashf "$1"
kube::readlinkdashf "${1}"
}

View File

@ -37,7 +37,7 @@ kube::log::errexit() {
kube::log::error " ${i}: ${BASH_SOURCE[${i}+1]}:${BASH_LINENO[${i}]} ${FUNCNAME[${i}]}(...)"
done
fi
kube::log::error_exit "Error in ${BASH_SOURCE[1]}:${BASH_LINENO[0]}. '${BASH_COMMAND}' exited with status $err" "${1:-1}" 1
kube::log::error_exit "Error in ${BASH_SOURCE[1]}:${BASH_LINENO[0]}. '${BASH_COMMAND}' exited with status ${err}" "${1:-1}" 1
}
kube::log::install_errexit() {
@ -63,9 +63,9 @@ kube::log::stack() {
for ((i=1 ; i <= ${#FUNCNAME[@]} - ${stack_skip} ; i++))
do
local frame_no=$((i - 1 + stack_skip))
local source_file=${BASH_SOURCE[$frame_no]}
local source_file=${BASH_SOURCE[${frame_no}]}
local source_lineno=${BASH_LINENO[$((frame_no - 1))]}
local funcname=${FUNCNAME[$frame_no]}
local funcname=${FUNCNAME[${frame_no}]}
echo " ${i}: ${source_file}:${source_lineno} ${funcname}(...)" >&2
done
fi
@ -83,7 +83,7 @@ kube::log::error_exit() {
stack_skip=$((stack_skip + 1))
if [[ ${KUBE_VERBOSE} -ge 4 ]]; then
local source_file=${BASH_SOURCE[$stack_skip]}
local source_file=${BASH_SOURCE[${stack_skip}]}
local source_line=${BASH_LINENO[$((stack_skip - 1))]}
echo "!!! Error in ${source_file}:${source_line}" >&2
[[ -z ${1-} ]] || {
@ -101,10 +101,10 @@ kube::log::error_exit() {
# Log an error but keep going. Don't dump the stack or exit.
kube::log::error() {
timestamp=$(date +"[%m%d %H:%M:%S]")
echo "!!! $timestamp ${1-}" >&2
echo "!!! ${timestamp} ${1-}" >&2
shift
for message; do
echo " $message" >&2
echo " ${message}" >&2
done
}
@ -113,7 +113,7 @@ kube::log::usage() {
echo >&2
local message
for message; do
echo "$message" >&2
echo "${message}" >&2
done
echo >&2
}
@ -121,7 +121,7 @@ kube::log::usage() {
kube::log::usage_from_stdin() {
local messages=()
while read -r line; do
messages+=("$line")
messages+=("${line}")
done
kube::log::usage "${messages[@]}"
@ -135,21 +135,21 @@ kube::log::info() {
fi
for message; do
echo "$message"
echo "${message}"
done
}
# Just like kube::log::info, but no \n, so you can make a progress bar
kube::log::progress() {
for message; do
echo -e -n "$message"
echo -e -n "${message}"
done
}
kube::log::info_from_stdin() {
local messages=()
while read -r line; do
messages+=("$line")
messages+=("${line}")
done
kube::log::info "${messages[@]}"
@ -163,9 +163,9 @@ kube::log::status() {
fi
timestamp=$(date +"[%m%d %H:%M:%S]")
echo "+++ $timestamp $1"
echo "+++ ${timestamp} ${1}"
shift
for message; do
echo " $message"
echo " ${message}"
done
}

View File

@ -34,9 +34,9 @@ kube::swagger::gen_types_swagger_doc() {
echo "Generating swagger type docs for ${group_version} at ${gv_dir}"
echo -e "$(cat hack/boilerplate/boilerplate.generatego.txt)\n" > "$TMPFILE"
echo "package ${group_version##*/}" >> "$TMPFILE"
cat >> "$TMPFILE" <<EOF
echo -e "$(cat hack/boilerplate/boilerplate.generatego.txt)\n" > "${TMPFILE}"
echo "package ${group_version##*/}" >> "${TMPFILE}"
cat >> "${TMPFILE}" <<EOF
// This file contains a collection of methods that can be used from go-restful to
// generate Swagger API documentation for its models. Please read this PR for more
@ -54,10 +54,10 @@ EOF
go run cmd/genswaggertypedocs/swagger_type_docs.go -s \
"${gv_dir}/types.go" \
-f - \
>> "$TMPFILE"
>> "${TMPFILE}"
echo "// AUTO-GENERATED FUNCTIONS END HERE" >> "$TMPFILE"
echo "// AUTO-GENERATED FUNCTIONS END HERE" >> "${TMPFILE}"
gofmt -w -s "$TMPFILE"
mv "$TMPFILE" ""${gv_dir}"/types_swagger_doc_generated.go"
gofmt -w -s "${TMPFILE}"
mv "${TMPFILE}" ""${gv_dir}"/types_swagger_doc_generated.go"
}

View File

@ -35,8 +35,8 @@ kube::test::clear_all() {
# Defaults to 2 levels so you can call this to find your own caller
kube::test::get_caller() {
local levels=${1:-2}
local caller_file="${BASH_SOURCE[$levels]}"
local caller_line="${BASH_LINENO[$levels-1]}"
local caller_file="${BASH_SOURCE[${levels}]}"
local caller_line="${BASH_LINENO[${levels}-1]}"
echo "$(basename "${caller_file}"):${caller_line}"
}

View File

@ -45,9 +45,9 @@ kube::util::wait_for_url() {
}
local i
for i in $(seq 1 "$times"); do
for i in $(seq 1 "${times}"); do
local out
if out=$(curl --max-time "$maxtime" -gkfs "$url" 2>/dev/null); then
if out=$(curl --max-time "${maxtime}" -gkfs "${url}" 2>/dev/null); then
kube::log::status "On try ${i}, ${prefix}: ${out}"
return 0
fi
@ -441,11 +441,11 @@ kube::util::ensure_no_staging_repos_in_gopath() {
kube::util::ensure_single_dir_gopath
local error=0
for repo_file in "${KUBE_ROOT}"/staging/src/k8s.io/*; do
if [[ ! -d "$repo_file" ]]; then
if [[ ! -d "${repo_file}" ]]; then
# not a directory or there were no files
continue;
fi
repo="$(basename "$repo_file")"
repo="$(basename "${repo_file}")"
if [ -e "${GOPATH}/src/k8s.io/${repo}" ]; then
echo "k8s.io/${repo} exists in GOPATH. Remove before running godep-save.sh." 1>&2
error=1
@ -722,7 +722,7 @@ function kube::util::ensure-cfssl {
mkdir -p "${cfssldir}"
pushd "${cfssldir}" > /dev/null
echo "Unable to successfully run 'cfssl' from $PATH; downloading instead..."
echo "Unable to successfully run 'cfssl' from ${PATH}; downloading instead..."
kernel=$(uname -s)
case "${kernel}" in
Linux)

View File

@ -965,9 +965,9 @@ create_csi_crd() {
echo "create_csi_crd $1"
YAML_FILE=${KUBE_ROOT}/cluster/addons/storage-crds/$1.yaml
if [ -e $YAML_FILE ]; then
if [ -e "${YAML_FILE}" ]; then
echo "Create $1 crd"
${KUBECTL} --kubeconfig="${CERT_DIR}/admin.kubeconfig" create -f $YAML_FILE
${KUBECTL} --kubeconfig="${CERT_DIR}/admin.kubeconfig" create -f ${YAML_FILE}
else
echo "No $1 available."
fi

View File

@ -169,7 +169,7 @@ else
# Test using the host the script was run on
# Provided for backwards compatibility
go run test/e2e_node/runner/local/run_local.go \
--system-spec-name="$system_spec_name" --ginkgo-flags="$ginkgoflags" \
--system-spec-name="${system_spec_name}" --ginkgo-flags="${ginkgoflags}" \
--test-flags="--container-runtime=${runtime} \
--alsologtostderr --v 4 --report-dir=${artifacts} --node-name $(hostname) \
${test_args}" --build-dependencies=true 2>&1 | tee -i "${artifacts}/build-log.txt"

View File

@ -149,7 +149,7 @@ while getopts "hp:i:" opt ; do
exit 0
;;
p)
PARALLEL="$OPTARG"
PARALLEL="${OPTARG}"
if ! isnum "${PARALLEL}" || [[ "${PARALLEL}" -le 0 ]]; then
kube::log::usage "'$0': argument to -p must be numeric and greater than 0"
kube::test::usage
@ -166,7 +166,7 @@ while getopts "hp:i:" opt ; do
exit 1
;;
:)
kube::log::usage "Option -$OPTARG <value>"
kube::log::usage "Option -${OPTARG} <value>"
kube::test::usage
exit 1
;;
@ -223,15 +223,15 @@ verifyAndSuggestPackagePath() {
local original_package_path="$3"
local suggestion_package_path="$4"
if ! [ -d "$specified_package_path" ]; then
if ! [ -d "${specified_package_path}" ]; then
# Because k8s sets a localized $GOPATH for testing, seeing the actual
# directory can be confusing. Instead, just show $GOPATH if it exists in the
# $specified_package_path.
local printable_package_path=$(echo "$specified_package_path" | sed "s|$GOPATH|\$GOPATH|")
kube::log::error "specified test path '$printable_package_path' does not exist"
local printable_package_path=$(echo "${specified_package_path}" | sed "s|${GOPATH}|\${GOPATH}|")
kube::log::error "specified test path '${printable_package_path}' does not exist"
if [ -d "$alternative_package_path" ]; then
kube::log::info "try changing \"$original_package_path\" to \"$suggestion_package_path\""
if [ -d "${alternative_package_path}" ]; then
kube::log::info "try changing \"${original_package_path}\" to \"${suggestion_package_path}\""
fi
exit 1
fi
@ -241,13 +241,13 @@ verifyPathsToPackagesUnderTest() {
local packages_under_test=($@)
for package_path in "${packages_under_test[@]}"; do
local local_package_path="$package_path"
local go_package_path="$GOPATH/src/$package_path"
local local_package_path="${package_path}"
local go_package_path="${GOPATH}/src/${package_path}"
if [[ "${package_path:0:2}" == "./" ]] ; then
verifyAndSuggestPackagePath "$local_package_path" "$go_package_path" "$package_path" "${package_path:2}"
verifyAndSuggestPackagePath "${local_package_path}" "${go_package_path}" "${package_path}" "${package_path:2}"
else
verifyAndSuggestPackagePath "$go_package_path" "$local_package_path" "$package_path" "./$package_path"
verifyAndSuggestPackagePath "${go_package_path}" "${local_package_path}" "${package_path}" "./${package_path}"
fi
done
}
@ -317,7 +317,7 @@ runTests() {
# https://github.com/golang/go/issues/16540
cover_ignore_dirs="vendor/k8s.io/code-generator/cmd/generator|vendor/k8s.io/client-go/1.4/rest"
for path in $(echo ${cover_ignore_dirs} | sed 's/|/ /g'); do
echo -e "skipped\tk8s.io/kubernetes/$path"
echo -e "skipped\tk8s.io/kubernetes/${path}"
done
printf "%s\n" "${@}" \

View File

@ -61,17 +61,17 @@ BASH_TARGETS="
update-bazel"
for t in ${BASH_TARGETS}; do
echo -e "${color_yellow}Running $t${color_norm}"
echo -e "${color_yellow}Running ${t}${color_norm}"
if ${SILENT} ; then
if ! bash "${KUBE_ROOT}/hack/$t.sh" 1> /dev/null; then
echo -e "${color_red}Running $t FAILED${color_norm}"
if ! bash "${KUBE_ROOT}/hack/${t}.sh" 1> /dev/null; then
echo -e "${color_red}Running ${t} FAILED${color_norm}"
if ! ${ALL}; then
exit 1
fi
fi
else
if ! bash "${KUBE_ROOT}/hack/$t.sh"; then
echo -e "${color_red}Running $t FAILED${color_norm}"
if ! bash "${KUBE_ROOT}/hack/${t}.sh"; then
echo -e "${color_red}Running ${t} FAILED${color_norm}"
if ! ${ALL}; then
exit 1
fi

View File

@ -86,7 +86,7 @@ QUICK_CHECKS=$(ls ${QUICK_PATTERNS[@]/#/${KUBE_ROOT}\/hack\/} 2>/dev/null || tru
function is-excluded {
for e in ${EXCLUDED_CHECKS[@]}; do
if [[ $1 -ef "$e" ]]; then
if [[ $1 -ef "${e}" ]]; then
return
fi
done
@ -95,7 +95,7 @@ function is-excluded {
function is-quick {
for e in ${QUICK_CHECKS[@]}; do
if [[ $1 -ef "$e" ]]; then
if [[ $1 -ef "${e}" ]]; then
return
fi
done
@ -106,7 +106,7 @@ function is-explicitly-chosen {
local name="${1#verify-}"
name="${name%.*}"
for e in ${WHAT}; do
if [[ $e == "$name" ]]; then
if [[ "${e}" == "${name}" ]]; then
return
fi
done