Merge pull request #113190 from BenTheElder/shell-fixups

assorted small shell script fixes
This commit is contained in:
Kubernetes Prow Robot 2022-10-20 03:34:57 -07:00 committed by GitHub
commit 687b001648
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 30 additions and 20 deletions

View File

@ -38,10 +38,12 @@ source "${KUBE_ROOT}/hack/lib/init.sh"
# Constants # Constants
readonly KUBE_BUILD_IMAGE_REPO=kube-build readonly KUBE_BUILD_IMAGE_REPO=kube-build
readonly KUBE_BUILD_IMAGE_CROSS_TAG="$(cat "${KUBE_ROOT}/build/build-image/cross/VERSION")" KUBE_BUILD_IMAGE_CROSS_TAG="$(cat "${KUBE_ROOT}/build/build-image/cross/VERSION")"
readonly KUBE_BUILD_IMAGE_CROSS_TAG
readonly KUBE_DOCKER_REGISTRY="${KUBE_DOCKER_REGISTRY:-registry.k8s.io}" readonly KUBE_DOCKER_REGISTRY="${KUBE_DOCKER_REGISTRY:-registry.k8s.io}"
readonly KUBE_BASE_IMAGE_REGISTRY="${KUBE_BASE_IMAGE_REGISTRY:-registry.k8s.io/build-image}" KUBE_BASE_IMAGE_REGISTRY="${KUBE_BASE_IMAGE_REGISTRY:-registry.k8s.io/build-image}"
readonly KUBE_BASE_IMAGE_REGISTRY
# This version number is used to cause everyone to rebuild their data containers # This version number is used to cause everyone to rebuild their data containers
# and build image. This is especially useful for automated build systems like # and build image. This is especially useful for automated build systems like
@ -49,12 +51,15 @@ readonly KUBE_BASE_IMAGE_REGISTRY="${KUBE_BASE_IMAGE_REGISTRY:-registry.k8s.io/b
# #
# Increment/change this number if you change the build image (anything under # Increment/change this number if you change the build image (anything under
# build/build-image) or change the set of volumes in the data container. # build/build-image) or change the set of volumes in the data container.
readonly KUBE_BUILD_IMAGE_VERSION_BASE="$(cat "${KUBE_ROOT}/build/build-image/VERSION")" KUBE_BUILD_IMAGE_VERSION_BASE="$(cat "${KUBE_ROOT}/build/build-image/VERSION")"
readonly KUBE_BUILD_IMAGE_VERSION_BASE
readonly KUBE_BUILD_IMAGE_VERSION="${KUBE_BUILD_IMAGE_VERSION_BASE}-${KUBE_BUILD_IMAGE_CROSS_TAG}" readonly KUBE_BUILD_IMAGE_VERSION="${KUBE_BUILD_IMAGE_VERSION_BASE}-${KUBE_BUILD_IMAGE_CROSS_TAG}"
# Make it possible to override the `kube-cross` image, and tag independent of `KUBE_BASE_IMAGE_REGISTRY` # Make it possible to override the `kube-cross` image, and tag independent of `KUBE_BASE_IMAGE_REGISTRY`
readonly KUBE_CROSS_IMAGE="${KUBE_CROSS_IMAGE:-"${KUBE_BASE_IMAGE_REGISTRY}/kube-cross"}" KUBE_CROSS_IMAGE="${KUBE_CROSS_IMAGE:-"${KUBE_BASE_IMAGE_REGISTRY}/kube-cross"}"
readonly KUBE_CROSS_VERSION="${KUBE_CROSS_VERSION:-"${KUBE_BUILD_IMAGE_CROSS_TAG}"}" readonly KUBE_CROSS_IMAGE
KUBE_CROSS_VERSION="${KUBE_CROSS_VERSION:-"${KUBE_BUILD_IMAGE_CROSS_TAG}"}"
readonly KUBE_CROSS_VERSION
# Here we map the output directories across both the local and remote _output # Here we map the output directories across both the local and remote _output
# directories: # directories:

View File

@ -2631,7 +2631,7 @@ function delete-subnetworks() {
# This value should be kept in sync with number of regions. # This value should be kept in sync with number of regions.
local parallelism=9 local parallelism=9
gcloud compute networks subnets list --network="${NETWORK}" --project "${NETWORK_PROJECT}" --format='value(region.basename())' | \ gcloud compute networks subnets list --network="${NETWORK}" --project "${NETWORK_PROJECT}" --format='value(region.basename())' | \
xargs -i -P ${parallelism} gcloud --quiet compute networks subnets delete "${NETWORK}" --project "${NETWORK_PROJECT}" --region="{}" || true xargs -I {} -P ${parallelism} gcloud --quiet compute networks subnets delete "${NETWORK}" --project "${NETWORK_PROJECT}" --region="{}" || true
elif [[ "${CREATE_CUSTOM_NETWORK:-}" == "true" ]]; then elif [[ "${CREATE_CUSTOM_NETWORK:-}" == "true" ]]; then
echo "Deleting custom subnet..." echo "Deleting custom subnet..."
gcloud --quiet compute networks subnets delete "${SUBNETWORK}" --project "${NETWORK_PROJECT}" --region="${REGION}" || true gcloud --quiet compute networks subnets delete "${SUBNETWORK}" --project "${NETWORK_PROJECT}" --region="${REGION}" || true

View File

@ -18,11 +18,12 @@
# A set of helpers for tests # A set of helpers for tests
readonly reset=$(tput sgr0) reset=$(tput sgr0)
readonly bold=$(tput bold) bold=$(tput bold)
readonly black=$(tput setaf 0) black=$(tput setaf 0)
readonly red=$(tput setaf 1) red=$(tput setaf 1)
readonly green=$(tput setaf 2) green=$(tput setaf 2)
readonly reset bold black red green
kube::test::clear_all() { kube::test::clear_all() {
if kube::test::if_supports_resource "rc" ; then if kube::test::if_supports_resource "rc" ; then

View File

@ -603,11 +603,9 @@ function kube::util::list_staging_repos() {
# Determines if docker can be run, failures may simply require that the user be added to the docker group. # Determines if docker can be run, failures may simply require that the user be added to the docker group.
function kube::util::ensure_docker_daemon_connectivity { function kube::util::ensure_docker_daemon_connectivity {
IFS=" " read -ra DOCKER <<< "${DOCKER_OPTS}" DOCKER_OPTS=${DOCKER_OPTS:-""}
# Expand ${DOCKER[@]} only if it's not unset. This is to work around IFS=" " read -ra docker_opts <<< "${DOCKER_OPTS}"
# Bash 3 issue with unbound variable. if ! docker "${docker_opts[@]:+"${docker_opts[@]}"}" info > /dev/null 2>&1 ; then
DOCKER=(docker ${DOCKER[@]:+"${DOCKER[@]}"})
if ! "${DOCKER[@]}" info > /dev/null 2>&1 ; then
cat <<'EOF' >&2 cat <<'EOF' >&2
Can't connect to 'docker' daemon. please fix and retry. Can't connect to 'docker' daemon. please fix and retry.

View File

@ -18,8 +18,9 @@ set -o errexit
set -o nounset set -o nounset
set -o pipefail set -o pipefail
readonly red=$(tput setaf 1) red=$(tput setaf 1)
readonly reset=$(tput sgr0) reset=$(tput sgr0)
readonly red reset
KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/../.. KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/../..
ALL_TARGETS=$(make -C "${KUBE_ROOT}" PRINT_HELP=y -rpn | sed -n -e '/^$/ { n ; /^[^ .#][^ ]*:/ { s/:.*$// ; p ; } ; }' | sort) ALL_TARGETS=$(make -C "${KUBE_ROOT}" PRINT_HELP=y -rpn | sed -n -e '/^$/ { n ; /^[^ .#][^ ]*:/ { s/:.*$// ; p ; } ; }' | sort)

View File

@ -41,7 +41,8 @@ fi
pushd "${KUBE_ROOT}" > /dev/null pushd "${KUBE_ROOT}" > /dev/null
# Setup a tmpdir to hold generated scripts and results # Setup a tmpdir to hold generated scripts and results
readonly tmpdir=$(mktemp -d -t verify-e2e-test-ownership.XXXX) tmpdir=$(mktemp -d -t verify-e2e-test-ownership.XXXX)
readonly tmpdir
trap 'rm -rf ${tmpdir}' EXIT trap 'rm -rf ${tmpdir}' EXIT
# input # input

View File

@ -70,7 +70,7 @@ ret=0
pushd "${KUBE_ROOT}" > /dev/null 2>&1 pushd "${KUBE_ROOT}" > /dev/null 2>&1
# Test for diffs # Test for diffs
_output="" _output=""
for file in ${TARGET_FILES[*]}; do for file in "${TARGET_FILES[@]}"; do
_output="${_output}$(diff -Naupr -I 'Auto generated by' "${KUBE_ROOT}/${file}" "${_kubetmp}/${file}")" || ret=1 _output="${_output}$(diff -Naupr -I 'Auto generated by' "${KUBE_ROOT}/${file}" "${_kubetmp}/${file}")" || ret=1
done done

View File

@ -39,6 +39,10 @@ disabled=(
# this lint disallows non-constant source, which we use extensively without # this lint disallows non-constant source, which we use extensively without
# any known bugs # any known bugs
1090 1090
# this lint warns when shellcheck cannot find a sourced file
# this wouldn't be a bad idea to warn on, but it fails on lots of path
# dependent sourcing, so just disable enforcing it
1091
# this lint prefers command -v to which, they are not the same # this lint prefers command -v to which, they are not the same
2230 2230
) )