diff --git a/cluster/gce/list-resources.sh b/cluster/gce/list-resources.sh index 6e70d9e2eac..963b9b26a25 100755 --- a/cluster/gce/list-resources.sh +++ b/cluster/gce/list-resources.sh @@ -31,6 +31,13 @@ REGION=${ZONE%-*} INSTANCE_PREFIX=${KUBE_GCE_INSTANCE_PREFIX:-${CLUSTER_NAME:-}} NETWORK=${KUBE_GCE_NETWORK:-${KUBE_GKE_NETWORK:-}} +# In GKE the instance prefix starts with "gke-". +if [[ "${KUBERNETES_PROVIDER:-}" == "gke" ]]; then + INSTANCE_PREFIX="gke-${CLUSTER_NAME}" + # Truncate to 26 characters for route prefix matching. + INSTANCE_PREFIX="${INSTANCE_PREFIX:0:26}" +fi + # Usage: gcloud-compute-list # GREP_REGEX is applied to the output of gcloud if set GREP_REGEX="" @@ -40,7 +47,6 @@ function gcloud-compute-list() { local attempt=1 local result="" while true; do - echo "Attempt ${attempt} to list ${resource} in GCE" if result=$(gcloud compute ${resource} list --project=${PROJECT} ${@:2} | grep "${GREP_REGEX}"); then echo "${result}" return @@ -59,7 +65,8 @@ echo "Project: ${PROJECT}" echo "Region: ${REGION}" echo "Zone: ${ZONE}" echo "Instance prefix: ${INSTANCE_PREFIX:-}" -echo "Network: ${NETWORK:-}" +echo "Network: ${NETWORK}" +echo "Provider: ${KUBERNETES_PROVIDER:-}" # List resources related to instances, filtering by the instance prefix if # provided. @@ -75,7 +82,7 @@ gcloud-compute-list disks ${ZONE:+"--zone=${ZONE}"} --regexp="${INSTANCE_PREFIX} gcloud-compute-list addresses ${REGION:+"--region=${REGION}"} --regexp="a.*|${INSTANCE_PREFIX}.*" # Match either the header or a line with the specified e2e network. # This assumes that the network name is the second field in the output. -GREP_REGEX="^NAME\|^[^\s]\+\s\+\(default\|${NETWORK}\)\s" +GREP_REGEX="^NAME\|^[^ ]\+[ ]\+\(default\|${NETWORK}\) " gcloud-compute-list routes --regexp="default.*|${INSTANCE_PREFIX}.*" gcloud-compute-list firewall-rules --regexp="default.*|k8s-fw.*|${INSTANCE_PREFIX}.*" GREP_REGEX=""