From 554857da97fbee1241bd32776aab8a695df108f8 Mon Sep 17 00:00:00 2001 From: shlo Date: Sat, 17 Aug 2019 10:28:08 +0800 Subject: [PATCH] add cluster name into filer if specifed in environment variable (#5085) --- contrib/aws_inventory/kubespray-aws-inventory.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/contrib/aws_inventory/kubespray-aws-inventory.py b/contrib/aws_inventory/kubespray-aws-inventory.py index b80704faa..91a848b62 100755 --- a/contrib/aws_inventory/kubespray-aws-inventory.py +++ b/contrib/aws_inventory/kubespray-aws-inventory.py @@ -42,8 +42,11 @@ class SearchEC2Tags(object): region = os.environ['REGION'] ec2 = boto3.resource('ec2', region) - - instances = ec2.instances.filter(Filters=[{'Name': 'tag:'+tag_key, 'Values': tag_value}, {'Name': 'instance-state-name', 'Values': ['running']}]) + filters = [{'Name': 'tag:'+tag_key, 'Values': tag_value}, {'Name': 'instance-state-name', 'Values': ['running']}] + cluster_name = os.getenv('CLUSTER_NAME') + if cluster_name: + filters.append({'Name': 'tag-key', 'Values': ['kubernetes.io/cluster/'+cluster_name]}) + instances = ec2.instances.filter(Filters=filters) for instance in instances: ##Suppose default vpc_visibility is private