mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-06 02:34:03 +00:00
Add script to use gcloud to print GCP resources used.
This commit is contained in:
parent
7ba48583fa
commit
004c3bc7ad
68
cluster/gce/list-resources.sh
Executable file
68
cluster/gce/list-resources.sh
Executable file
@ -0,0 +1,68 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright 2015 The Kubernetes Authors All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# Calls gcloud to print out a variety of Google Cloud Platform resources used by
|
||||
# Kubernetes. Can be run before/after test runs and compared to track leaking
|
||||
# resources.
|
||||
|
||||
# PROJECT must be set in the environment.
|
||||
# If ZONE, KUBE_GCE_INSTANCE_PREFIX, CLUSTER_NAME, KUBE_GCE_NETWORK, or
|
||||
# KUBE_GKE_NETWORK is set, they will be used to filter the results.
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
ZONE=${ZONE:-}
|
||||
REGION=${ZONE%-*}
|
||||
INSTANCE_PREFIX=${KUBE_GCE_INSTANCE_PREFIX:-${CLUSTER_NAME:-}}
|
||||
NETWORK=${KUBE_GCE_NETWORK:-${KUBE_GKE_NETWORK:-}}
|
||||
|
||||
# Usage: gcloud-compute-list <resource> <additional parameters to gcloud...>
|
||||
# GREP_REGEX is applied to the output of gcloud if set
|
||||
GREP_REGEX=""
|
||||
function gcloud-compute-list() {
|
||||
local -r resource=$1
|
||||
echo -e "\n\n[ ${resource} ]"
|
||||
gcloud compute ${resource} list --project=${PROJECT} ${@:2} | grep "${GREP_REGEX}"
|
||||
}
|
||||
|
||||
echo "Project: ${PROJECT}"
|
||||
echo "Region: ${REGION}"
|
||||
echo "Zone: ${ZONE}"
|
||||
echo "Instance prefix: ${INSTANCE_PREFIX:-}"
|
||||
echo "Network: ${NETWORK:-}"
|
||||
|
||||
# List resources related to instances, filtering by the instance prefix if
|
||||
# provided.
|
||||
gcloud-compute-list instance-templates --regexp="${INSTANCE_PREFIX}.*"
|
||||
gcloud-compute-list instance-groups ${ZONE:+"--zone=${ZONE}"} --regexp="${INSTANCE_PREFIX}.*"
|
||||
gcloud-compute-list instances ${ZONE:+"--zone=${ZONE}"} --regexp="${INSTANCE_PREFIX}.*"
|
||||
|
||||
# List disk resources, filterying by instance prefix if provided.
|
||||
gcloud-compute-list disks ${ZONE:+"--zone=${ZONE}"} --regexp="${INSTANCE_PREFIX}.*"
|
||||
|
||||
# List network resources. We include names starting with "a", corresponding to
|
||||
# those that Kubernetes creates.
|
||||
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"
|
||||
gcloud-compute-list routes --regexp="default.*|${INSTANCE_PREFIX}.*"
|
||||
gcloud-compute-list firewall-rules --regexp="default.*|k8s-fw.*|${INSTANCE_PREFIX}.*"
|
||||
GREP_REGEX=""
|
||||
gcloud-compute-list forwarding-rules ${REGION:+"--region=${REGION}"}
|
||||
gcloud-compute-list target-pools ${REGION:+"--region=${REGION}"}
|
Loading…
Reference in New Issue
Block a user