Skip to content

Commit

Permalink
Fetch the hostname from env variables when running in EKS
Browse files Browse the repository at this point in the history
Summary:
## This stack

In prod we always read the hostname from `/etc/fbwhoami`. In AWS we provide a custom, hardcoded [`/etc/fbwhoami`](https://fburl.com/code/4nf1tdqi) that hardcodes the hostname.

That wasn't a problem so far because we only ran once instance, but now we are starting to run multiple.

## This diff

Read the hostname from an environment variable (`HOSTNAME`) that is guaranteed to exist on EKS. To avoid any ambiguity, we will only honor it if we are certain to be running on AWS.

This logic is applicable to OSS as well, and guaranteed to work; so we might as well make it unconditional.

Reviewed By: RajivTS

Differential Revision: D70567737

fbshipit-source-id: b3d8351e60989e9f07adcf685b1587b71eebe4de
  • Loading branch information
andreacampi authored and facebook-github-bot committed Mar 5, 2025
1 parent 5bb551c commit 8d02f5b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions shed/hostname/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ use anyhow::Result;

/// Returns hostname as reported by the system
pub fn get_hostname() -> Result<String> {
if let Ok(aws) = std::env::var("AWS_REGION") {
if !aws.is_empty() {
if let Ok(hostname) = std::env::var("HOSTNAME") {
// we are running in AWS and probably in EKS, we can trust the HOSTNAME env var
return Ok(hostname);
}
}
}

#[cfg(not(fbcode_build))]
{
Ok(::real_hostname::get()?.to_string_lossy().into_owned())
Expand Down

0 comments on commit 8d02f5b

Please sign in to comment.