diff --git a/common/ip_resolver.go b/common/ip_resolver.go index 5d780903..75f2ad39 100644 --- a/common/ip_resolver.go +++ b/common/ip_resolver.go @@ -636,7 +636,8 @@ func (resolver *K8sIPResolver) getControllerOfOwner(originalOwner *metav1.OwnerR if !ok { return nil, errors.New("type confusion in replicasets map") } - return metav1.GetControllerOf(&replicaSet), nil + owner := metav1.GetControllerOf(&replicaSet) + return owner, nil case "DaemonSet": daemonSetVal, ok := resolver.snapshot.DaemonSets.Load(originalOwner.UID) if !ok { @@ -750,3 +751,18 @@ func (resolver *K8sIPResolver) resolvePodDescriptor(pod *v1.Pod) Workload { } return result } + +func (resolver *K8sIPResolver) ResolvePodOwner(podName string, podNamespace string) Workload { + pods, err := resolver.clientset.CoreV1().Pods(podNamespace).Get(context.Background(), podName, metav1.GetOptions{}) + if err != nil { + return Workload{ + Name: podName, + Namespace: podNamespace, + Kind: "Pod", + Region: "", + Zone: "", + Instance: "", + } + } + return resolver.resolvePodDescriptor(pods) +} diff --git a/containers/container.go b/containers/container.go index b0dadf06..ca1f9579 100644 --- a/containers/container.go +++ b/containers/container.go @@ -174,9 +174,10 @@ func NewContainer(id ContainerID, cg *cgroup.Cgroup, md *ContainerMetadata, pid // %s -> pod name split := strings.Split(string(id), "/") - namespace := split[1] - podName := split[2] - + namespace := split[2] + podName := split[3] + src_workload := registry.ip_resolver.ResolvePodOwner(podName, namespace) + klog.Infof("Pod %s/%s is owned by %s/%s/%s", namespace, podName, src_workload.Name, src_workload.Namespace, src_workload.Kind) c := &Container{ id: id, cgroup: cg, @@ -206,7 +207,7 @@ func NewContainer(id ContainerID, cg *cgroup.Cgroup, md *ContainerMetadata, pid done: make(chan struct{}), ip_resolver: registry.ip_resolver, registry: registry, - srcWorkload: common.Workload{Name: podName, Namespace: namespace, Kind: "Pod"}, + srcWorkload: src_workload, } c.runLogParser("") diff --git a/containers/l7.go b/containers/l7.go index 9ab3d93b..56e02807 100644 --- a/containers/l7.go +++ b/containers/l7.go @@ -56,7 +56,7 @@ func (s L7Stats) get(protocol l7.Protocol, key common.DestinationKey, r *l7.Requ "destination_workload_kind": dstWorkload.Kind, "destination_workload_name": dstWorkload.Name, "destination_workload_namespace": dstWorkload.Namespace, - "src_kind": srcWorkload.Kind, + "src_workload_kind": srcWorkload.Kind, "src_workload_name": srcWorkload.Name, "src_workload_namespace": srcWorkload.Namespace, "actual_destination_workload_kind": actualDstWorkload.Kind, diff --git a/containers/registry.go b/containers/registry.go index 9f5194d3..00a5a2e6 100644 --- a/containers/registry.go +++ b/containers/registry.go @@ -44,6 +44,7 @@ type IPResolver interface { CacheDNS(string, string) common.Workload StartWatching() error StopWatching() + ResolvePodOwner(string, string) common.Workload } type Registry struct {