From 44db75462495e8b0b7c4a368e55cffc91b8679d6 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 29 Aug 2018 08:04:59 -0500 Subject: [PATCH] common/util: pass real hostname when running in kubernetes/rook container 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 --- src/common/util.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/common/util.cc b/src/common/util.cc index faddeae8625..d0fbee5e3fc 100644 --- a/src/common/util.cc +++ b/src/common/util.cc @@ -152,6 +152,19 @@ void collect_sys_info(map *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 { -- 2.39.5