]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/util: pass real hostname when running in kubernetes/rook container
authorSage Weil <sage@redhat.com>
Tue, 4 Sep 2018 16:25:54 +0000 (11:25 -0500)
committerSage Weil <sage@redhat.com>
Tue, 4 Sep 2018 16:26:06 +0000 (11:26 -0500)
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>
(cherry picked from commit 44db75462495e8b0b7c4a368e55cffc91b8679d6)

# Conflicts:
# src/common/util.cc
- conflict with APPLE special case in newer code

src/common/util.cc

index fb67d7ca109ef486631ffdebf8ac6e5d1c0b099d..cf345954c11305fad1663e588b8a4c9125965896 100644 (file)
@@ -137,6 +137,18 @@ void collect_sys_info(map<string, string> *m, CephContext *cct)
     (*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;
+  }
+
   // memory
   FILE *f = fopen(PROCPREFIX "/proc/meminfo", "r");
   if (f) {