New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Garbage collect LB resources for GCE #71812
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,22 +14,37 @@ | |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# A utility for deleting target pools and forwarding rules that are unattached to VMs | ||
# A utility for deleting stranded load balancer resources in GCE | ||
PROJECT=${PROJECT:-kubernetes-jenkins} | ||
REGION=${REGION:-us-central1} | ||
|
||
# Deleting external load balancer resources | ||
LIST=$(gcloud --project=${PROJECT} compute target-pools list --format='value(name)') | ||
|
||
result=0 | ||
for x in ${LIST}; do | ||
if ! gcloud compute --project=${PROJECT} target-pools get-health "${x}" --region=${REGION} 2>/dev/null >/dev/null; then | ||
echo DELETING "${x}" | ||
gcloud compute --project=${PROJECT} firewall-rules delete "k8s-fw-${x}" -q | ||
gcloud compute --project=${PROJECT} forwarding-rules delete "${x}" --region=${REGION} -q | ||
gcloud compute --project=${PROJECT} addresses delete "${x}" --region=${REGION} -q | ||
gcloud compute --project=${PROJECT} target-pools delete "${x}" --region=${REGION} -q | ||
result=1 | ||
fi | ||
# Check the existence of vm instance to see if the load balancer resources are | ||
# actively used. Only delete them if they are not. | ||
if ! gcloud compute --project=${PROJECT} target-pools get-health "${x}" --region=${REGION} 2>/dev/null >/dev/null; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add some comments here? Its hard to follow the logic. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added comments. |
||
echo DELETING LB "${x}" | ||
gcloud compute --project=${PROJECT} firewall-rules delete "k8s-fw-${x}" -q | ||
gcloud compute --project=${PROJECT} forwarding-rules delete "${x}" --region=${REGION} -q | ||
gcloud compute --project=${PROJECT} addresses delete "${x}" --region=${REGION} -q | ||
gcloud compute --project=${PROJECT} target-pools delete "${x}" --region=${REGION} -q | ||
fi | ||
done | ||
|
||
# Deleting internal load balancer resources | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is external L7 right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's an internal L4. |
||
ILB_LIST=$(gcloud --project=${PROJECT} compute backend-services list --format='value(name)') | ||
for x in ${ILB_LIST}; do | ||
# Check the existence of vm instance to see if the load balancer resources are | ||
# actively used. Only delete them if they are not. | ||
if ! gcloud compute --project=${PROJECT} backend-services get-health "${x}" --region=${REGION} 2>/dev/null >/dev/null; then | ||
echo DELETING internal LB "${x}" | ||
ig=$(gcloud compute --project=${PROJECT} backend-services list --regions=${REGION} 2>/dev/null | grep "${x}" | awk '{print $2}' | cut -d'/' -f3) | ||
zone=$(gcloud compute --project=${PROJECT} instance-groups unmanaged list | grep ${ig} | awk '{print $2}') | ||
gcloud compute --project=${PROJECT} firewall-rules delete "${x}" -q | ||
gcloud compute --project=${PROJECT} forwarding-rules delete "${x}" --region=${REGION} -q | ||
gcloud compute --project=${PROJECT} backend-services delete "${x}" --region=${REGION} -q | ||
gcloud compute --project=${PROJECT} instance-groups unmanaged delete "${ig}" --zone=${zone} -q | ||
fi | ||
done | ||
exit ${result} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is external L4 right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes. basically it's the gce resources created when user creates an external k8s LB.