From b8de47763abb99449829071dc88a9e8955d451a8 Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Thu, 21 Oct 2021 18:05:28 -0600 Subject: [PATCH] filter_kubernetes: register metadata Signed-off-by: Eduardo Silva --- plugins/filter_kubernetes/kube_meta.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/plugins/filter_kubernetes/kube_meta.c b/plugins/filter_kubernetes/kube_meta.c index ff275062b84..ac4f6f47a6f 100644 --- a/plugins/filter_kubernetes/kube_meta.c +++ b/plugins/filter_kubernetes/kube_meta.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -229,6 +230,23 @@ static int refresh_token_if_needed(struct flb_kube *ctx) return 0; } +static void expose_k8s_meta(struct flb_kube *ctx) +{ + char *tmp; + struct flb_env *env; + + env = ctx->config->env; + + flb_env_set(env, "k8s", "enabled"); + flb_env_set(env, "k8s.namespace", ctx->namespace); + flb_env_set(env, "k8s.pod_name", ctx->podname); + + tmp = (char *) flb_env_get(env, "NODE_NAME"); + if (tmp) { + flb_env_set(env, "k8s.node_name", tmp); + } +} + /* Load local information from a POD context */ static int get_local_pod_info(struct flb_kube *ctx) { @@ -273,6 +291,7 @@ static int get_local_pod_info(struct flb_kube *ctx) return FLB_FALSE; } + expose_k8s_meta(ctx); return FLB_TRUE; }