#!/bin/bash # Copyright 2015 The Kubernetes Authors. # # 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. # A utility for deleting target pools and forwarding rules that are unattached to VMs global PROJECT := $(PROJECT:-kubernetes-jenkins) global REGION := $(REGION:-us-central1) global LIST := $[gcloud --project=$(PROJECT) compute target-pools list --format='value(name)] global result := '0' for x in [$(LIST)] { if ! gcloud compute --project=$(PROJECT) target-pools get-health $(x) --region=$(REGION) !2 >/dev/null >/dev/null { 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 global result := '1' } } exit $(result) (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:PROJECT) op: Equal rhs: { (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(kubernetes-jenkins)}) spids: [48 52] ) } spids: [47] ) ] spids: [47] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:REGION) op: Equal rhs: { (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(us-central1)}) spids: [55 59] ) } spids: [54] ) ] spids: [54] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:LIST) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(gcloud)} {(--project) (Lit_Other "=") (${ VSub_Name PROJECT)} {(compute)} {(target-pools)} {(list)} {(--format) (Lit_Other "=") (SQ <"value(name)">)} ) ] ) left_token: spids: [63 83] ) } spids: [62] ) ] spids: [62] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:result) op:Equal rhs:{(0)} spids:[86])] spids: [86] ) (ForEach iter_name: x iter_words: [{(${ VSub_Name LIST)}] do_arg_iter: False body: (DoGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (Pipeline children: [ (SimpleCommand words: [ {(gcloud)} {(compute)} {(--project) (Lit_Other "=") (${ VSub_Name PROJECT)} {(target-pools)} {(get-health)} {(DQ (${ VSub_Name x))} {(--region) (Lit_Other "=") (${ VSub_Name REGION)} ] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [133] ) (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [136] ) ] ) ] negated: True ) terminator: ) ] action: [ (C {(echo)} {(DELETING)} {(DQ (${ VSub_Name x))}) (C {(gcloud)} {(compute)} {(--project) (Lit_Other "=") (${ VSub_Name PROJECT)} {(firewall-rules)} {(delete)} {(DQ (k8s-fw-) (${ VSub_Name x))} {(-q)} ) (C {(gcloud)} {(compute)} {(--project) (Lit_Other "=") (${ VSub_Name PROJECT)} {(forwarding-rules)} {(delete)} {(DQ (${ VSub_Name x))} {(--region) (Lit_Other "=") (${ VSub_Name REGION)} {(-q)} ) (C {(gcloud)} {(compute)} {(--project) (Lit_Other "=") (${ VSub_Name PROJECT)} {(addresses)} {(delete)} {(DQ (${ VSub_Name x))} {(--region) (Lit_Other "=") (${ VSub_Name REGION)} {(-q)} ) (C {(gcloud)} {(compute)} {(--project) (Lit_Other "=") (${ VSub_Name PROJECT)} {(target-pools)} {(delete)} {(DQ (${ VSub_Name x))} {(--region) (Lit_Other "=") (${ VSub_Name REGION)} {(-q)} ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:result) op:Equal rhs:{(1)} spids:[265])] spids: [265] ) ] spids: [-1 140] ) ] spids: [-1 269] ) ] spids: [100 271] ) spids: [94 98] ) (C {(exit)} {(${ VSub_Name result)}) ] )