From 68935e0798b36c2d506b1a3d082bff5fa7d7c3bf Mon Sep 17 00:00:00 2001 From: Justin Santa Barbara Date: Wed, 25 Mar 2015 05:36:47 -0700 Subject: [PATCH] Remove load balancers as part of kube-down.sh --- cluster/aws/util.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cluster/aws/util.sh b/cluster/aws/util.sh index 0b726f55682..69a9c2ba503 100644 --- a/cluster/aws/util.sh +++ b/cluster/aws/util.sh @@ -23,6 +23,7 @@ source "${KUBE_ROOT}/cluster/aws/${KUBE_CONFIG_FILE-"config-default.sh"}" export AWS_DEFAULT_REGION=${ZONE} AWS_CMD="aws --output json ec2" +AWS_ELB_CMD="aws --output json elb" MASTER_INTERNAL_IP=172.20.0.9 @@ -56,6 +57,12 @@ function get_sec_group_id { python -c 'import json,sys; lst = [str(group["GroupId"]) for group in json.load(sys.stdin)["SecurityGroups"] if group["GroupName"] == "kubernetes-sec-group"]; print "".join(lst)' } +function get_elbs_in_vpc { + # ELB doesn't seem to be on the same platform as the rest of AWS; doesn't support filtering + $AWS_ELB_CMD describe-load-balancers | \ + python -c "import json,sys; lst = [str(lb['LoadBalancerName']) for lb in json.load(sys.stdin)['LoadBalancerDescriptions'] if lb['VPCId'] == '$1']; print '\n'.join(lst)" +} + function expect_instance_states { python -c "import json,sys; lst = [str(instance['InstanceId']) for reservation in json.load(sys.stdin)['Reservations'] for instance in reservation['Instances'] if instance['State']['Name'] != '$1']; print ' '.join(lst)" } @@ -694,6 +701,11 @@ function kube-down { echo "Deleting VPC" vpc_id=$($AWS_CMD describe-vpcs | get_vpc_id) if [[ -n "${vpc_id}" ]]; then + elb_ids=$(get_elbs_in_vpc ${vpc_id}) + for elb_id in ${elb_ids}; do + $AWS_ELB_CMD delete-load-balancer --load-balancer-name=${elb_id} + done + default_sg_id=$($AWS_CMD --output text describe-security-groups \ --filters Name=vpc-id,Values=$vpc_id Name=group-name,Values=default \ --query SecurityGroups[].GroupId \