cluster/gce: fix checks for empty strings.

In order to use -n, the value needs either be quoted or [[ .. ]] block
has to be used. Fix the comparisons that way.

To verify, consider this (analogous) script:

  #!/bin/bash

  subnetwork_url=""

  if [ -n ${subnetwork_url} ]; then
    echo "foo"
  fi

  if [[ -n ${subnetwork_url} ]]; then
    echo "bar"
  fi

Here "foo" is echoed by the script, even though the variable
subnetwork_url has a zero-length value.
This commit is contained in:
Ismo Puustinen 2018-02-02 11:26:22 +02:00
parent 2226b1de09
commit 6372bb2f28
2 changed files with 3 additions and 3 deletions

View File

@ -81,10 +81,10 @@ flex_clean() {
umount_silent ${MOUNTER_PATH}
rm -rf ${MOUNTER_PATH}
if [ -n ${IMAGE_URL:-} ]; then
if [[ -n ${IMAGE_URL:-} ]]; then
docker rmi -f ${IMAGE_URL} &> /dev/null || /bin/true
fi
if [ -n ${MOUNTER_DEFAULT_NAME:-} ]; then
if [[ -n ${MOUNTER_DEFAULT_NAME:-} ]]; then
docker rm -f ${MOUNTER_DEFAULT_NAME} &> /dev/null || /bin/true
fi
}

View File

@ -53,7 +53,7 @@ function detect-k8s-subnetwork() {
local subnetwork_url=$(gcloud compute instances describe \
${KUBE_MASTER} --project=${PROJECT} --zone=${ZONE} \
--format='value(networkInterfaces[0].subnetwork)')
if [ -n ${subnetwork_url} ]; then
if [[ -n ${subnetwork_url} ]]; then
IP_ALIAS_SUBNETWORK=$(echo ${subnetwork_url##*/})
fi
}