Backport patch to expose instance availability-zone-id

https://github.com/coreos/afterburn/pull/748
This commit is contained in:
Sohan Kunkerkar 2022-06-13 10:19:43 -04:00 committed by Sohan Kunkerkar
parent 4098e19748
commit 4b76b61d7b
2 changed files with 79 additions and 1 deletions

View File

@ -0,0 +1,72 @@
From ba87d66582f4a3a5b25dcd1f810c477ad27feb87 Mon Sep 17 00:00:00 2001
From: Abhinav Dahiya <adahiya@lyft.com>
Date: Mon, 9 May 2022 09:42:56 -0700
Subject: [PATCH] providers/aws: expose instance availability-zone-id as
AWS_AVAILABILITY_ZONE_ID
ec2 instance metadata exposes the physical id for availability zone. Physical zone ids are useful
because they are same across AWS accounts and helpful when trying to decide if instances are actually
in the same zone when reconciling that between instances in different accounts.
See doc:
> https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-categories.html
```
placement/availability-zone-id The static Availability Zone ID in which the instance is launched. The Availability Zone ID is consistent across accounts. However, it might be different from the Availability Zone, which can vary by account. 2020-08-24
```
This is available in api versions starting 2020-08-24, and afterbun already uses 2021-01-03 [1].
[1]: https://github.com/coreos/afterburn/blob/640ce9790c4f2d56aa75d1e3ad63f8011bec4255/src/providers/aws/mod.rs#L83
---
src/providers/aws/mock_tests.rs | 3 +++
src/providers/aws/mod.rs | 5 +++++
2 files changed, 8 insertions(+)
diff --git a/src/providers/aws/mock_tests.rs b/src/providers/aws/mock_tests.rs
index fc8d3c0..97bcfc5 100644
--- a/src/providers/aws/mock_tests.rs
+++ b/src/providers/aws/mock_tests.rs
@@ -48,6 +48,7 @@ fn aws_get_maps() -> (
let ipv4_public = "test-ipv4-public";
let ipv6 = "test-ipv6";
let availability_zone = "test-availability-zone";
+ let availability_zone_id = "test-availability-zone-id";
let hostname = "test-hostname";
let public_hostname = "test-public-hostname";
let instance_id_doc = r#"{"region": "test-region"}"#;
@@ -61,6 +62,7 @@ fn aws_get_maps() -> (
"/meta-data/public-ipv4" => ipv4_public,
"/meta-data/ipv6" => ipv6,
"/meta-data/placement/availability-zone" => availability_zone,
+ "/meta-data/placement/availability-zone-id" => availability_zone_id,
"/meta-data/hostname" => hostname,
"/meta-data/public-hostname" => public_hostname,
"/dynamic/instance-identity/document" => instance_id_doc,
@@ -72,6 +74,7 @@ fn aws_get_maps() -> (
"AWS_IPV4_PUBLIC".to_string() => ipv4_public.to_string(),
"AWS_IPV6".to_string() => ipv6.to_string(),
"AWS_AVAILABILITY_ZONE".to_string() => availability_zone.to_string(),
+ "AWS_AVAILABILITY_ZONE_ID".to_string() => availability_zone_id.to_string(),
"AWS_HOSTNAME".to_string() => hostname.to_string(),
"AWS_PUBLIC_HOSTNAME".to_string() => public_hostname.to_string(),
"AWS_REGION".to_string() => region.to_string(),
diff --git a/src/providers/aws/mod.rs b/src/providers/aws/mod.rs
index 3ced742..60e78be 100644
--- a/src/providers/aws/mod.rs
+++ b/src/providers/aws/mod.rs
@@ -169,6 +169,11 @@ impl MetadataProvider for AwsProvider {
"AWS_AVAILABILITY_ZONE",
"meta-data/placement/availability-zone",
)?;
+ add_value(
+ &mut out,
+ "AWS_AVAILABILITY_ZONE_ID",
+ "meta-data/placement/availability-zone-id",
+ )?;
add_value(&mut out, "AWS_HOSTNAME", "meta-data/hostname")?;
add_value(&mut out, "AWS_PUBLIC_HOSTNAME", "meta-data/public-hostname")?;
--
2.35.1

View File

@ -8,7 +8,7 @@
Name: rust-%{crate}
Version: 5.3.0
Release: 1%{?dist}
Release: 2%{?dist}
Summary: Simple cloud provider agent
# Upstream license specification: Apache-2.0
@ -17,6 +17,8 @@ URL: https://crates.io/crates/afterburn
Source0: %{crates_source}
# not used on Fedora
Source1: https://github.com/coreos/%{crate}/releases/download/v%{version}/%{crate}-%{version}-vendor.tar.gz
# https://github.com/coreos/afterburn/pull/748
Patch0: 0001-providers-aws-expose-instance-availability-zone-id-a.patch
ExclusiveArch: %{rust_arches}
%if 0%{?rhel} && !0%{?eln}
@ -143,6 +145,10 @@ cp -a dracut/* %{buildroot}%{dracutmodulesdir}
%endif
%changelog
* Mon Jun 13 2022 Sohan Kunkerkar <skunkerk@redhat.com> - 5.3.0-2
- Backport patch to expose instance availability-zone-id
https://github.com/coreos/afterburn/pull/748
* Fri Apr 29 2022 Sohan Kunkerkar <skunkerk@redhat.com> - 5.3.0-1
- Update to 5.3.0