Fix some shellcheck warnings/errors in cluster/gce/util.sh

This patch fixes the use of arrays.

Change-Id: I6c7f7eaf89387ed96c7b2ddf4fbb4627ec2c6075
Signed-off-by: Joakim Roubert <joakim.roubert@axis.com>
This commit is contained in:
Joakim Roubert 2020-09-03 12:44:51 +02:00 committed by Joakim Roubert
parent 1a66eb7b8a
commit e924c3568e

View File

@ -1594,7 +1594,8 @@ function create-certs {
local -r primary_cn="${1}" local -r primary_cn="${1}"
# Determine extra certificate names for master # Determine extra certificate names for master
local octets=($(echo "${SERVICE_CLUSTER_IP_RANGE}" | sed -e 's|/.*||' -e 's/\./ /g')) local octets
kube::util::read-array octets < <(echo "${SERVICE_CLUSTER_IP_RANGE}" | sed -e 's|/.*||' -e 's/\./ /g')
((octets[3]+=1)) ((octets[3]+=1))
local -r service_ip=$(echo "${octets[*]}" | sed 's/ /./g') local -r service_ip=$(echo "${octets[*]}" | sed 's/ /./g')
local sans="" local sans=""
@ -2047,29 +2048,29 @@ function create-node-template() {
local gcloud="gcloud" local gcloud="gcloud"
local accelerator_args="" local accelerator_args=()
# VMs with Accelerators cannot be live migrated. # VMs with Accelerators cannot be live migrated.
# More details here - https://cloud.google.com/compute/docs/gpus/add-gpus#create-new-gpu-instance # More details here - https://cloud.google.com/compute/docs/gpus/add-gpus#create-new-gpu-instance
if [[ ! -z "${NODE_ACCELERATORS}" ]]; then if [[ -n "${NODE_ACCELERATORS}" ]]; then
accelerator_args="--maintenance-policy TERMINATE --restart-on-failure --accelerator ${NODE_ACCELERATORS}" accelerator_args+=(--maintenance-policy TERMINATE --restart-on-failure --accelerator "${NODE_ACCELERATORS}")
gcloud="gcloud beta" gcloud="gcloud beta"
fi fi
local preemptible_minions="" local preemptible_minions=()
if [[ "${PREEMPTIBLE_NODE}" == "true" ]]; then if [[ "${PREEMPTIBLE_NODE}" == "true" ]]; then
preemptible_minions="--preemptible --maintenance-policy TERMINATE" preemptible_minions+=(--preemptible --maintenance-policy TERMINATE)
fi fi
local local_ssds="" local local_ssds=()
local_ssd_ext_count=0 local_ssd_ext_count=0
if [[ ! -z ${NODE_LOCAL_SSDS_EXT:-} ]]; then if [[ -n ${NODE_LOCAL_SSDS_EXT:-} ]]; then
IFS=";" read -r -a ssdgroups <<< "${NODE_LOCAL_SSDS_EXT:-}" IFS=";" read -r -a ssdgroups <<< "${NODE_LOCAL_SSDS_EXT:-}"
for ssdgroup in "${ssdgroups[@]}" for ssdgroup in "${ssdgroups[@]}"
do do
IFS="," read -r -a ssdopts <<< "${ssdgroup}" IFS="," read -r -a ssdopts <<< "${ssdgroup}"
validate-node-local-ssds-ext "${ssdopts}" validate-node-local-ssds-ext "${ssdopts[@]}"
for ((i=1; i<=ssdopts[0]; i++)); do for ((i=1; i<=ssdopts[0]; i++)); do
local_ssds="$local_ssds--local-ssd=interface=${ssdopts[1]} " local_ssds+=("--local-ssd=interface=${ssdopts[1]}")
done done
done done
fi fi
@ -2086,7 +2087,8 @@ function create-node-template() {
address="no-address" address="no-address"
fi fi
local network=$(make-gcloud-network-argument \ local network
network=$(make-gcloud-network-argument \
"${NETWORK_PROJECT}" \ "${NETWORK_PROJECT}" \
"${REGION}" \ "${REGION}" \
"${NETWORK}" \ "${NETWORK}" \
@ -2095,11 +2097,11 @@ function create-node-template() {
"${ENABLE_IP_ALIASES:-}" \ "${ENABLE_IP_ALIASES:-}" \
"${IP_ALIAS_SIZE:-}") "${IP_ALIAS_SIZE:-}")
local node_image_flags="" local node_image_flags=()
if [[ "${os}" == 'linux' ]]; then if [[ "${os}" == 'linux' ]]; then
node_image_flags="--image-project ${NODE_IMAGE_PROJECT} --image ${NODE_IMAGE}" node_image_flags+=(--image-project "${NODE_IMAGE_PROJECT}" --image "${NODE_IMAGE}")
elif [[ "${os}" == 'windows' ]]; then elif [[ "${os}" == 'windows' ]]; then
node_image_flags="--image-project ${WINDOWS_NODE_IMAGE_PROJECT} --image ${WINDOWS_NODE_IMAGE}" node_image_flags+=(--image-project "${WINDOWS_NODE_IMAGE_PROJECT}" --image "${WINDOWS_NODE_IMAGE}")
else else
echo "Unknown OS ${os}" >&2 echo "Unknown OS ${os}" >&2
exit 1 exit 1
@ -2116,16 +2118,16 @@ function create-node-template() {
--machine-type "${machine_type}" \ --machine-type "${machine_type}" \
--boot-disk-type "${NODE_DISK_TYPE}" \ --boot-disk-type "${NODE_DISK_TYPE}" \
--boot-disk-size "${NODE_DISK_SIZE}" \ --boot-disk-size "${NODE_DISK_SIZE}" \
${node_image_flags} \ "${node_image_flags[@]}" \
--service-account "${NODE_SERVICE_ACCOUNT}" \ --service-account "${NODE_SERVICE_ACCOUNT}" \
--tags "${NODE_TAG}" \ --tags "${NODE_TAG}" \
${accelerator_args} \ "${accelerator_args[@]}" \
${local_ssds} \ "${local_ssds[@]}" \
--region "${REGION}" \ --region "${REGION}" \
${network} \ ${network} \
${preemptible_minions} \ "${preemptible_minions[@]}" \
$2 \ $2 \
--metadata-from-file $3 \ --metadata-from-file "$3" \
${metadata_flag} >&2; then ${metadata_flag} >&2; then
if (( attempt > 5 )); then if (( attempt > 5 )); then
echo -e "${color_red}Failed to create instance template ${template_name} ${color_norm}" >&2 echo -e "${color_red}Failed to create instance template ${template_name} ${color_norm}" >&2
@ -2420,7 +2422,7 @@ function delete-all-firewall-rules() {
# Ignores firewall rule arguments that do not exist in NETWORK_PROJECT. # Ignores firewall rule arguments that do not exist in NETWORK_PROJECT.
function delete-firewall-rules() { function delete-firewall-rules() {
for fw in $@; do for fw in "$@"; do
if [[ -n $(gcloud compute firewall-rules --project "${NETWORK_PROJECT}" describe "${fw}" --format='value(name)' 2>/dev/null || true) ]]; then if [[ -n $(gcloud compute firewall-rules --project "${NETWORK_PROJECT}" describe "${fw}" --format='value(name)' 2>/dev/null || true) ]]; then
gcloud compute firewall-rules delete --project "${NETWORK_PROJECT}" --quiet "${fw}" & gcloud compute firewall-rules delete --project "${NETWORK_PROJECT}" --quiet "${fw}" &
fi fi
@ -3501,10 +3503,10 @@ function kube-down() {
if [[ "${KUBE_DELETE_NODES:-}" != "false" ]]; then if [[ "${KUBE_DELETE_NODES:-}" != "false" ]]; then
# Find out what minions are running. # Find out what minions are running.
local -a minions local -a minions
minions=( $(gcloud compute instances list \ kube::util::read-array minions < <(gcloud compute instances list \
--project "${PROJECT}" \ --project "${PROJECT}" \
--filter="(name ~ '${NODE_INSTANCE_PREFIX}-.+' OR name ~ '${WINDOWS_NODE_INSTANCE_PREFIX}-.+') AND zone:(${ZONE})" \ --filter="(name ~ '${NODE_INSTANCE_PREFIX}-.+' OR name ~ '${WINDOWS_NODE_INSTANCE_PREFIX}-.+') AND zone:(${ZONE})" \
--format='value(name)') ) --format='value(name)')
# If any minions are running, delete them in batches. # If any minions are running, delete them in batches.
while (( "${#minions[@]}" > 0 )); do while (( "${#minions[@]}" > 0 )); do
echo Deleting nodes "${minions[*]::${batch}}" echo Deleting nodes "${minions[*]::${batch}}"
@ -3528,9 +3530,9 @@ function kube-down() {
# Note that this is currently a noop, as synchronously deleting the node MIG # Note that this is currently a noop, as synchronously deleting the node MIG
# first allows the master to cleanup routes itself. # first allows the master to cleanup routes itself.
local TRUNCATED_PREFIX="${INSTANCE_PREFIX:0:26}" local TRUNCATED_PREFIX="${INSTANCE_PREFIX:0:26}"
routes=( $(gcloud compute routes list --project "${NETWORK_PROJECT}" \ kube::util::read-array routes < <(gcloud compute routes list --project "${NETWORK_PROJECT}" \
--filter="name ~ '${TRUNCATED_PREFIX}-.{8}-.{4}-.{4}-.{4}-.{12}'" \ --filter="name ~ '${TRUNCATED_PREFIX}-.{8}-.{4}-.{4}-.{4}-.{12}'" \
--format='value(name)') ) --format='value(name)')
while (( "${#routes[@]}" > 0 )); do while (( "${#routes[@]}" > 0 )); do
echo Deleting routes "${routes[*]::${batch}}" echo Deleting routes "${routes[*]::${batch}}"
gcloud compute routes delete \ gcloud compute routes delete \
@ -3692,12 +3694,12 @@ function check-resources() {
echo "Looking for already existing resources" echo "Looking for already existing resources"
KUBE_RESOURCE_FOUND="" KUBE_RESOURCE_FOUND=""
if [[ -n "${INSTANCE_GROUPS[@]:-}" ]]; then if [[ -n "${INSTANCE_GROUPS[*]:-}" ]]; then
KUBE_RESOURCE_FOUND="Managed instance groups ${INSTANCE_GROUPS[@]}" KUBE_RESOURCE_FOUND="Managed instance groups ${INSTANCE_GROUPS[*]}"
return 1 return 1
fi fi
if [[ -n "${WINDOWS_INSTANCE_GROUPS[@]:-}" ]]; then if [[ -n "${WINDOWS_INSTANCE_GROUPS[*]:-}" ]]; then
KUBE_RESOURCE_FOUND="Managed instance groups ${WINDOWS_INSTANCE_GROUPS[@]}" KUBE_RESOURCE_FOUND="Managed instance groups ${WINDOWS_INSTANCE_GROUPS[*]}"
return 1 return 1
fi fi
@ -3722,10 +3724,10 @@ function check-resources() {
# Find out what minions are running. # Find out what minions are running.
local -a minions local -a minions
minions=( $(gcloud compute instances list \ kube::util::read-array minions < <(gcloud compute instances list \
--project "${PROJECT}" \ --project "${PROJECT}" \
--filter="(name ~ '${NODE_INSTANCE_PREFIX}-.+' OR name ~ '${WINDOWS_NODE_INSTANCE_PREFIX}-.+') AND zone:(${ZONE})" \ --filter="(name ~ '${NODE_INSTANCE_PREFIX}-.+' OR name ~ '${WINDOWS_NODE_INSTANCE_PREFIX}-.+') AND zone:(${ZONE})" \
--format='value(name)') ) --format='value(name)')
if (( "${#minions[@]}" > 0 )); then if (( "${#minions[@]}" > 0 )); then
KUBE_RESOURCE_FOUND="${#minions[@]} matching ${NODE_INSTANCE_PREFIX}-.+ or ${WINDOWS_NODE_INSTANCE_PREFIX}-.+" KUBE_RESOURCE_FOUND="${#minions[@]} matching ${NODE_INSTANCE_PREFIX}-.+ or ${WINDOWS_NODE_INSTANCE_PREFIX}-.+"
return 1 return 1
@ -3742,8 +3744,8 @@ function check-resources() {
fi fi
local -a routes local -a routes
routes=( $(gcloud compute routes list --project "${NETWORK_PROJECT}" \ kube::util::read-array routes < <(gcloud compute routes list --project "${NETWORK_PROJECT}" \
--filter="name ~ '${INSTANCE_PREFIX}-minion-.{4}'" --format='value(name)') ) --filter="name ~ '${INSTANCE_PREFIX}-minion-.{4}'" --format='value(name)')
if (( "${#routes[@]}" > 0 )); then if (( "${#routes[@]}" > 0 )); then
KUBE_RESOURCE_FOUND="${#routes[@]} routes matching ${INSTANCE_PREFIX}-minion-.{4}" KUBE_RESOURCE_FOUND="${#routes[@]} routes matching ${INSTANCE_PREFIX}-minion-.{4}"
return 1 return 1