21
21
22
22
# Tag the resources ...
23
23
def lambda_handler (event , context ):
24
- filter = [{'Name' :'tag:kubernetes.io/cluster/' + cluster , 'Values' :['owned' ]}]
24
+ kubeClusterTagKey = 'kubernetes.io/cluster/' + cluster
25
+ kubeClusterTagValue = 'owned'
26
+ filter = [{'Name' :'tag:' + kubeClusterTagKey , 'Values' :[kubeClusterTagValue ]}]
25
27
26
28
ec2 = boto3 .resource ('ec2' , region_name = region )
27
29
@@ -135,7 +137,7 @@ def lambda_handler(event, context):
135
137
asgs = autoscaling .describe_auto_scaling_groups (MaxRecords = 100 )
136
138
for asg in asgs ['AutoScalingGroups' ]:
137
139
for tag in asg ['Tags' ]:
138
- if tag ['Key' ] == 'KubernetesCluster' and tag ['Value' ] == cluster :
140
+ if tag ['Key' ] == kubeClusterTagKey and tag ['Value' ] == kubeClusterTagValue :
139
141
newTags = prepare_new_tags (asg ['Tags' ])
140
142
141
143
if len (newTags ) > 0 :
@@ -153,7 +155,7 @@ def lambda_handler(event, context):
153
155
for elb in elbs ['LoadBalancerDescriptions' ]:
154
156
tags = loadbalancing .describe_tags (LoadBalancerNames = [elb ['LoadBalancerName' ]])
155
157
for tag in tags ['TagDescriptions' ][0 ]['Tags' ]:
156
- if tag ['Key' ] == 'KubernetesCluster' and tag ['Value' ] == cluster :
158
+ if tag ['Key' ] == kubeClusterTagKey and tag ['Value' ] == kubeClusterTagValue :
157
159
newTags = prepare_new_tags (tags ['TagDescriptions' ][0 ]['Tags' ])
158
160
if len (newTags ) > 0 :
159
161
LOGGER .info ("Adding tags to load balancer %s" , elb ['LoadBalancerName' ])
0 commit comments