Set node labels from AWS instance tag (#3544)

Set kubernetes node labels from a given comma-separated list of `key=value` from AWS instance tag `kubespray-node-labels`.
pull/3706/head
Mateus Caruccio 2018-11-14 06:21:56 -02:00 committed by k8s-ci-robot
parent 92877e8bf8
commit 087b7fa38e
1 changed files with 9 additions and 2 deletions

View File

@ -45,15 +45,22 @@ class SearchEC2Tags(object):
instances = ec2.instances.filter(Filters=[{'Name': 'tag:'+tag_key, 'Values': tag_value}, {'Name': 'instance-state-name', 'Values': ['running']}])
for instance in instances:
node_labels_tag = list(filter(lambda t: t['Key'] == 'kubespray-node-labels', instance.tags))
node_labels = ''
if node_labels_tag:
node_labels = dict([ label.strip().split('=') for label in node_labels_tag[0]['Value'].split(',') ])
if self.vpc_visibility == "public":
hosts[group].append(instance.public_dns_name)
hosts['_meta']['hostvars'][instance.public_dns_name] = {
'ansible_ssh_host': instance.public_ip_address
'ansible_ssh_host': instance.public_ip_address,
'node_labels': node_labels
}
else:
hosts[group].append(instance.private_dns_name)
hosts['_meta']['hostvars'][instance.private_dns_name] = {
'ansible_ssh_host': instance.private_ip_address
'ansible_ssh_host': instance.private_ip_address,
'node_labels': node_labels
}
hosts['k8s-cluster'] = {'children':['kube-master', 'kube-node']}