Skip to content

Commit

Permalink
Add secondary key for fetching az key (#1503)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntascii authored Mar 8, 2024
1 parent 1bc7c23 commit 33f47a6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion deploy-agent/deployd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
# 2: puppet applied successfully with changes
PUPPET_SUCCESS_EXIT_CODES = [0, 2]

__version__ = '1.2.59'
__version__ = '1.2.60'
20 changes: 14 additions & 6 deletions deploy-agent/deployd/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# 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.
Expand Down Expand Up @@ -34,7 +34,7 @@


class Client(BaseClient):
def __init__(self, config=None, hostname=None, ip=None, hostgroup=None,
def __init__(self, config=None, hostname=None, ip=None, hostgroup=None,
host_id=None, use_facter=None, use_host_info=False) -> None:
self._hostname = hostname
self._ip = ip
Expand Down Expand Up @@ -145,13 +145,18 @@ def _read_host_info(self) -> bool:
if IS_PINTEREST and self._use_host_info is False:
# Read new keys from facter always
az_key = self._config.get_facter_az_key()
secondary_az_key = self._config.get_facter_secondary_az_key()
asg_tag_key = self._config.get_facter_asg_tag_key()
ec2_tags_key = self._config.get_facter_ec2_tags_key()
stage_type_key = self._config.get_stage_type_key()
account_id_key = self._config.get_facter_account_id_key()
keys_to_fetch = set()
if not self._availability_zone and az_key:
keys_to_fetch.add(az_key)

if not self._availability_zone:
if az_key:
keys_to_fetch.add(az_key)
if secondary_az_key:
keys_to_fetch.add(secondary_az_key)

if not self._autoscaling_group:
keys_to_fetch.add(ec2_tags_key)
Expand All @@ -168,6 +173,9 @@ def _read_host_info(self) -> bool:
if not self._availability_zone:
self._availability_zone = facter_data.get(az_key, None)

if not self._availability_zone:
self._availability_zone = facter_data.get(secondary_az_key, None)

# Hosts brought up outside of ASG or Teletraan might not have ASG
# Note: on U14, facter -p ec2_tags.Autoscaling does not work.
# so need to read ec2_tags from facter and parse Autoscaling tag to cover this case
Expand All @@ -190,7 +198,7 @@ def _read_host_info(self) -> bool:

log.info("Host information is loaded. "
"Host name: {}, IP: {}, host id: {}, agent_version={}, autoscaling_group: {}, "
"availability_zone: {}, ec2_tags: {}, stage_type: {}, group: {}, account id: {}".format(self._hostname, self._ip, self._id,
"availability_zone: {}, ec2_tags: {}, stage_type: {}, group: {}, account id: {}".format(self._hostname, self._ip, self._id,
self._agent_version, self._autoscaling_group, self._availability_zone, self._ec2_tags, self._stage_type, self._hostgroup, self._account_id))

if not self._availability_zone:
Expand Down
3 changes: 3 additions & 0 deletions deploy-agent/deployd/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ def get_deploy_agent_version(self) -> str:
def get_facter_az_key(self) -> Optional[str]:
return self.get_var('availability_zone_key', None)

def get_facter_secondary_az_key(self) -> Optional[str]:
return self.get_var('secondary_availability_zone_key', 'ec2_metadata.placement.availability-zone')

def get_facter_ec2_tags_key(self) -> Optional[str]:
return self.get_var('ec2_tags_key', None)

Expand Down

0 comments on commit 33f47a6

Please sign in to comment.