Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion common/ip_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
9 changes: 5 additions & 4 deletions containers/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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("")

Expand Down
2 changes: 1 addition & 1 deletion containers/l7.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions containers/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type IPResolver interface {
CacheDNS(string, string) common.Workload
StartWatching() error
StopWatching()
ResolvePodOwner(string, string) common.Workload
}

type Registry struct {
Expand Down