Navigation Menu

Skip to content

Commit

Permalink
common/util: pass real hostname when running in kubernetes/rook conta…
Browse files Browse the repository at this point in the history
…iner

Rook will set up some environment variables to tell us what pod, pod
namespace, and physical host we are running on.  If we see them, set
'hostname' according to the hardware host, and include the pod info
in our metadata.

This allows the usual host-based logic on Ceph to work correctly, like
placing OSDs automatically in the CRUSH map.

Signed-off-by: Sage Weil <sage@redhat.com>
  • Loading branch information
liewegas committed Aug 30, 2018
1 parent 9f9b525 commit 44db754
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/common/util.cc
Expand Up @@ -152,6 +152,19 @@ void collect_sys_info(map<string, string> *m, CephContext *cct)
(*m)["hostname"] = u.nodename;
(*m)["arch"] = u.machine;
}

// but wait, am i in a container?
if (const char *pod_name = getenv("POD_NAME")) {
(*m)["pod_name"] = pod_name;
if (const char *node_name = getenv("NODE_NAME")) {
(*m)["container_hostname"] = u.nodename;
(*m)["hostname"] = node_name;
}
}
if (const char *ns = getenv("POD_NAMESPACE")) {
(*m)["pod_namespace"] = ns;
}

#ifdef __APPLE__
// memory
{
Expand Down

0 comments on commit 44db754

Please sign in to comment.