mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #20143 from roberthbailey/list-resources-gke
Fix list-resources.sh to work with the GKE provider
This commit is contained in:
commit
574f354b73
@ -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 <resource> <additional parameters to gcloud...>
|
||||
# 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=""
|
||||
|
Loading…
Reference in New Issue
Block a user