Skip to content

Commit

Permalink
Merge pull request #196 from jpinsonneau/253
Browse files Browse the repository at this point in the history
NETOBSERV-253 Enrich Host informations
  • Loading branch information
jpinsonneau authored May 9, 2022
2 parents fdd8ca2 + 2a0ee75 commit 19cfeb1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/pipeline/transform/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type Info struct {
Labels map[string]string
OwnerReferences []metav1.OwnerReference
Owner Owner
HostName string
HostIP string
}

Expand All @@ -82,6 +83,7 @@ func (k *KubeData) GetInfo(ip string) (*Info, error) {
Labels: pod.Labels,
OwnerReferences: pod.OwnerReferences,
HostIP: pod.Status.HostIP,
HostName: k.getHostName(pod.Status.HostIP),
}
case typeNode:
node := objs[0].(*v1.Node)
Expand Down Expand Up @@ -140,6 +142,16 @@ func (k *KubeData) getOwner(info *Info) Owner {
}
}

func (k *KubeData) getHostName(hostIP string) string {
if k.ipInformers[typeNode] != nil && len(hostIP) > 0 {
objs, err := k.ipInformers[typeNode].GetIndexer().ByIndex(IndexIP, hostIP)
if err == nil && len(objs) > 0 {
return objs[0].(*v1.Node).Name
}
}
return ""
}

func (k *KubeData) NewNodeInformer(informerFactory informers.SharedInformerFactory) error {
nodes := informerFactory.Core().V1().Nodes().Informer()
err := nodes.AddIndexers(map[string]cache.IndexFunc{
Expand Down
3 changes: 3 additions & 0 deletions pkg/pipeline/transform/transform_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ func (n *Network) TransformEntry(inputEntry config.GenericMap) config.GenericMap
}
if kubeInfo.HostIP != "" {
outputEntries[rule.Output+"_HostIP"] = kubeInfo.HostIP
if kubeInfo.HostName != "" {
outputEntries[rule.Output+"_HostName"] = kubeInfo.HostName
}
}
default:
log.Panicf("unknown type %s for transform.Network rule: %v", rule.Type, rule)
Expand Down

0 comments on commit 19cfeb1

Please sign in to comment.