Skip to content

Commit

Permalink
Retrieve Kubernetes pod IP address if it is set in status.podIP
Browse files Browse the repository at this point in the history
Signed-off-by: Kris Gambirazzi <[email protected]>
  • Loading branch information
kgtw committed Nov 18, 2020
1 parent b7c7081 commit a037738
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions plugins/filter_kubernetes/kube_meta.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ static int merge_meta(struct flb_kube_meta *meta, struct flb_kube *ctx,
int have_labels = -1;
int have_annotations = -1;
int have_nodename = -1;
int have_podip = -1;
size_t off = 0;
msgpack_sbuffer mp_sbuf;
msgpack_packer mp_pck;
Expand Down Expand Up @@ -611,6 +612,19 @@ static int merge_meta(struct flb_kube_meta *meta, struct flb_kube *ctx,
}
}

/* Process status map value for podIP */
if (status_found == FLB_TRUE) {
for (i = 0; i < status_val.via.map.size; i++) {
k = status_val.via.map.ptr[i].key;
if (k.via.str.size == 5 &&
strncmp(k.via.str.ptr, "podIP", 5) == 0) {
have_podip = i;
map_size++;
break;
}
}
}

if ((!meta->container_hash || !meta->docker_id || !meta->container_image) && status_found) {
extract_container_hash(meta, status_val);
}
Expand Down Expand Up @@ -668,6 +682,14 @@ static int merge_meta(struct flb_kube_meta *meta, struct flb_kube *ctx,
msgpack_pack_object(&mp_pck, v);
}

if (have_podip >= 0) {
v = status_val.via.map.ptr[have_podip].val;

msgpack_pack_str(&mp_pck, 6);
msgpack_pack_str_body(&mp_pck, "pod_ip", 6);
msgpack_pack_object(&mp_pck, v);
}

if (meta->container_name != NULL) {
msgpack_pack_str(&mp_pck, 14);
msgpack_pack_str_body(&mp_pck, "container_name", 14);
Expand Down

0 comments on commit a037738

Please sign in to comment.