From 4d2a91cb7b1d6cc247c2ab8929dcf684b9d36c98 Mon Sep 17 00:00:00 2001 From: Arnob Kumar Saha Date: Thu, 23 May 2024 00:50:32 +0600 Subject: [PATCH] Fix hostname in falcoevent (#7) Signed-off-by: Arnob kumar saha --- pkg/falcosidekick/handler.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/pkg/falcosidekick/handler.go b/pkg/falcosidekick/handler.go index 01057993..be27485c 100644 --- a/pkg/falcosidekick/handler.go +++ b/pkg/falcosidekick/handler.go @@ -38,7 +38,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/klog/v2" cu "kmodules.xyz/client-go/client" - "kmodules.xyz/client-go/meta" "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -164,13 +163,19 @@ func newFalcoPayload(payload io.Reader) (types.FalcoPayload, error) { func forwardEvent(kc client.Client, payload types.FalcoPayload, evHash uint64) error { var nodeName string if payload.Hostname != "" { - var pod core.Pod - key := client.ObjectKey{ - Namespace: meta.PodNamespace(), - Name: payload.Hostname, - } - if err := kc.Get(context.TODO(), key, &pod); err == nil { - nodeName = pod.Spec.NodeName + nodeName = payload.Hostname + } else { + podName := payload.OutputFields["k8s.pod.name"].(string) + nsName := payload.OutputFields["k8s.ns.name"].(string) + if podName != "" && nsName != "" { + var pod core.Pod + key := client.ObjectKey{ + Namespace: nsName, + Name: podName, + } + if err := kc.Get(context.TODO(), key, &pod); err == nil { + nodeName = pod.Spec.NodeName + } } }