From f2d6b035834e784cf28cbd9e45f9334c3197f136 Mon Sep 17 00:00:00 2001 From: Dan Mick Date: Tue, 30 Oct 2018 20:50:53 -0700 Subject: [PATCH] common/util.cc: add CONTAINER_NAME processing for metadata Kubernetes clusters use POD_NAME; simple containers should be distinguishable and don't have 'pods'. Signed-off-by: Dan Mick --- src/common/util.cc | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/common/util.cc b/src/common/util.cc index d0fbee5e3fc06..68545840e7d79 100644 --- a/src/common/util.cc +++ b/src/common/util.cc @@ -154,15 +154,24 @@ void collect_sys_info(map *m, CephContext *cct) } // but wait, am i in a container? + bool in_container = false; + if (const char *pod_name = getenv("POD_NAME")) { (*m)["pod_name"] = pod_name; + in_container = true; + } + if (const char *container_name = getenv("CONTAINER_NAME")) { + (*m)["container_name"] = container_name; + in_container = true; + } + if (in_container) { 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; + if (const char *ns = getenv("POD_NAMESPACE")) { + (*m)["pod_namespace"] = ns; + } } #ifdef __APPLE__ -- 2.39.5