mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
Fix list-resources.sh to work with the GKE provider. Also update
the grep command to work for versions of grep that don't understand '\s'.
This commit is contained in:
parent
3328cfe1c5
commit
a8cad507db
@ -31,6 +31,13 @@ REGION=${ZONE%-*}
|
|||||||
INSTANCE_PREFIX=${KUBE_GCE_INSTANCE_PREFIX:-${CLUSTER_NAME:-}}
|
INSTANCE_PREFIX=${KUBE_GCE_INSTANCE_PREFIX:-${CLUSTER_NAME:-}}
|
||||||
NETWORK=${KUBE_GCE_NETWORK:-${KUBE_GKE_NETWORK:-}}
|
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 <resource> <additional parameters to gcloud...>
|
# Usage: gcloud-compute-list <resource> <additional parameters to gcloud...>
|
||||||
# GREP_REGEX is applied to the output of gcloud if set
|
# GREP_REGEX is applied to the output of gcloud if set
|
||||||
GREP_REGEX=""
|
GREP_REGEX=""
|
||||||
@ -40,7 +47,6 @@ function gcloud-compute-list() {
|
|||||||
local attempt=1
|
local attempt=1
|
||||||
local result=""
|
local result=""
|
||||||
while true; do
|
while true; do
|
||||||
echo "Attempt ${attempt} to list ${resource} in GCE"
|
|
||||||
if result=$(gcloud compute ${resource} list --project=${PROJECT} ${@:2} | grep "${GREP_REGEX}"); then
|
if result=$(gcloud compute ${resource} list --project=${PROJECT} ${@:2} | grep "${GREP_REGEX}"); then
|
||||||
echo "${result}"
|
echo "${result}"
|
||||||
return
|
return
|
||||||
@ -59,7 +65,8 @@ echo "Project: ${PROJECT}"
|
|||||||
echo "Region: ${REGION}"
|
echo "Region: ${REGION}"
|
||||||
echo "Zone: ${ZONE}"
|
echo "Zone: ${ZONE}"
|
||||||
echo "Instance prefix: ${INSTANCE_PREFIX:-}"
|
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
|
# List resources related to instances, filtering by the instance prefix if
|
||||||
# provided.
|
# 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}.*"
|
gcloud-compute-list addresses ${REGION:+"--region=${REGION}"} --regexp="a.*|${INSTANCE_PREFIX}.*"
|
||||||
# Match either the header or a line with the specified e2e network.
|
# 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.
|
# 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 routes --regexp="default.*|${INSTANCE_PREFIX}.*"
|
||||||
gcloud-compute-list firewall-rules --regexp="default.*|k8s-fw.*|${INSTANCE_PREFIX}.*"
|
gcloud-compute-list firewall-rules --regexp="default.*|k8s-fw.*|${INSTANCE_PREFIX}.*"
|
||||||
GREP_REGEX=""
|
GREP_REGEX=""
|
||||||
|
Loading…
Reference in New Issue
Block a user