Skip to content

Commit 497e71f

Browse files
authored
Merge branch 'trigger' into clean-ext-build-env
2 parents 818289a + 6f7d064 commit 497e71f

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

postgres-appliance/scripts/configure_spilo.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ def deep_update(a, b):
396396

397397

398398
def get_provider():
399-
provider = os.environ.get('SPILO_PROVIDER', PROVIDER_LOCAL)
399+
provider = os.environ.get('SPILO_PROVIDER')
400400
if provider:
401401
if provider in {PROVIDER_AWS, PROVIDER_GOOGLE, PROVIDER_OPENSTACK, PROVIDER_LOCAL}:
402402
return provider
@@ -411,18 +411,23 @@ def get_provider():
411411
logging.info("Figuring out my environment (Google? AWS? Openstack? Local?)")
412412
response = requests.put(
413413
url='http://169.254.169.254/latest/api/token',
414-
headers={'X-aws-ec2-metadata-token-ttl-seconds': '60'}
414+
headers={'X-aws-ec2-metadata-token-ttl-seconds': '60'},
415+
timeout=2
415416
)
417+
if not response.ok:
418+
logging.info("Failed to get IMDS token (status %s), assuming local Docker setup", response.status_code)
419+
return PROVIDER_LOCAL
416420
token = response.text
417421
r = requests.get(
418422
url='http://169.254.169.254',
419-
headers={'X-aws-ec2-metadata-token': token}
423+
headers={'X-aws-ec2-metadata-token': token},
424+
timeout=2
420425
)
421426
if r.headers.get('Metadata-Flavor', '') == 'Google':
422427
return PROVIDER_GOOGLE
423428
else:
424429
# accessible on Openstack, will fail on AWS
425-
r = requests.get('http://169.254.169.254/openstack/latest/meta_data.json')
430+
r = requests.get('http://169.254.169.254/openstack/latest/meta_data.json', timeout=2)
426431
if r.ok:
427432
# make sure the response is parsable - https://github.com/Azure/aad-pod-identity/issues/943 and
428433
# https://github.com/zalando/spilo/issues/542
@@ -432,7 +437,8 @@ def get_provider():
432437
# is accessible from both AWS and Openstack, Possiblity of misidentification if previous try fails
433438
r = requests.get(
434439
url='http://169.254.169.254/latest/meta-data/ami-id',
435-
headers={'X-aws-ec2-metadata-token': token}
440+
headers={'X-aws-ec2-metadata-token': token},
441+
timeout=2
436442
)
437443
return PROVIDER_AWS if r.ok else PROVIDER_UNSUPPORTED
438444
except (requests.exceptions.ConnectTimeout, requests.exceptions.ConnectionError, requests.exceptions.ReadTimeout):

0 commit comments

Comments
 (0)