Skip to content

Commit

Permalink
common/util.cc: add CONTAINER_NAME processing for metadata
Browse files Browse the repository at this point in the history
Kubernetes clusters use POD_NAME; simple containers should be
distinguishable and don't have 'pods'.

Signed-off-by: Dan Mick <[email protected]>
  • Loading branch information
dmick committed Dec 3, 2018
1 parent 70242bf commit f2d6b03
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/common/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,24 @@ void collect_sys_info(map<string, string> *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__
Expand Down

0 comments on commit f2d6b03

Please sign in to comment.