Skip to content

Commit 8b1de71

Browse files
authored
Merge pull request #94 from eranra/add_hostip
add hostip for k8s
2 parents 757c754 + ecfe88c commit 8b1de71

File tree

4 files changed

+8
-2
lines changed

4 files changed

+8
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ The fifth rule `add_kubernetes` generates new fields with kubernetes information
307307
matching the `input` value (`srcIP` in the example above) with kubernetes `nodes`, `pods` and `services` IPs.
308308
All the kubernetes fields will be named by appending `output` value
309309
(`srcK8S` in the example above) to the kubernetes metadata field names
310-
(e.g., `Namespace`, `Name`, `Type`, `OwnerName`, `OwnerType` )
310+
(e.g., `Namespace`, `Name`, `Type`, `HostIP`, `OwnerName`, `OwnerType` )
311311

312312
In addition, if the `parameters` value is not empty, fields with kubernetes labels
313313
will be generated, and named by appending `parameters` value to the label keys.

pkg/pipeline/transform/kubernetes/kubernetes.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type Info struct {
6262
Labels map[string]string
6363
OwnerReferences []metav1.OwnerReference
6464
Owner Owner
65+
HostIP string
6566
}
6667

6768
func (k *KubeData) GetInfo(ip string) (*Info, error) {
@@ -78,6 +79,7 @@ func (k *KubeData) GetInfo(ip string) (*Info, error) {
7879
Namespace: pod.Namespace,
7980
Labels: pod.Labels,
8081
OwnerReferences: pod.OwnerReferences,
82+
HostIP: pod.Status.HostIP,
8183
}
8284
case typeNode:
8385
node := objs[0].(*v1.Node)

pkg/pipeline/transform/kubernetes/kubernetes_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type InformerInterface interface {
4343
}
4444

4545
func (indexMock *IndexerMock) ByIndex(indexName, indexedValue string) ([]interface{}, error) {
46-
pod := fakePod("podName", "podNamespace", "podHost")
46+
pod := fakePod("podName", "podNamespace", "podHostIP")
4747
podInterface := interface{}(pod)
4848
return []interface{}{podInterface}, nil
4949
}
@@ -77,6 +77,7 @@ func TestKubeData_getInfo(t *testing.T) {
7777
Type: "Pod",
7878
Name: "podName",
7979
Namespace: "podNamespace",
80+
HostIP: "podHostIP",
8081
Owner: Owner{Name: "podName", Type: "Pod"},
8182
}
8283
kubeData = KubeData{ipInformers: map[string]cache.SharedIndexInformer{}}

pkg/pipeline/transform/transform_network.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ func (n *Network) Transform(inputEntry config.GenericMap) config.GenericMap {
140140
outputEntries[rule.Parameters+"_"+labelKey] = labelValue
141141
}
142142
}
143+
if kubeInfo.HostIP != "" {
144+
outputEntries[rule.Output+"_HostIP"] = kubeInfo.HostIP
145+
}
143146
default:
144147
log.Panicf("unknown type %s for transform.Network rule: %v", rule.Type, rule)
145148
}

0 commit comments

Comments
 (0)