Skip to content

Commit

Permalink
Fix memory leak when there is a pod churn
Browse files Browse the repository at this point in the history
  • Loading branch information
sridhartigera authored and tomastigera committed Oct 4, 2024
1 parent 671bf3a commit 50b93c0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
6 changes: 6 additions & 0 deletions felix/dataplane/linux/bpf_ep_mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,8 @@ func (m *bpfEndpointManager) onInterfaceUpdate(update *ifaceStateUpdate) {
iface.info.isUP = false
m.updateIfaceStateMap(update.Name, iface)
iface.info.ifIndex = 0
iface.info.masterIfIndex = 0
iface.info.ifaceType = 0
}
return true // Force interface to be marked dirty in case we missed a transition during a resync.
})
Expand Down Expand Up @@ -4152,6 +4154,10 @@ func (m *bpfEndpointManager) getIfaceLink(name string) (netlink.Link, error) {
return link, nil
}

func (m *bpfEndpointManager) getNumEPs() int {
return len(m.nameToIface)
}

func (m *bpfEndpointManager) getIfaceTypeFromLink(link netlink.Link) IfaceType {
attrs := link.Attrs()
if attrs.Slave != nil && attrs.Slave.SlaveType() == "bond" {
Expand Down
39 changes: 39 additions & 0 deletions felix/dataplane/linux/bpf_ep_mgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,21 @@ var _ = Describe("BPF Endpoint Manager", func() {
}
}

genWLUpdateEpRemove := func(name string, policies ...string) func() {
return func() {
update := &proto.WorkloadEndpointRemove{
Id: &proto.WorkloadEndpointID{
OrchestratorId: "k8s",
WorkloadId: name,
EndpointId: name,
},
}
bpfEpMgr.OnUpdate(update)
err := bpfEpMgr.CompleteDeferredWork()
Expect(err).NotTo(HaveOccurred())
}
}

genHostMetadataUpdate := func(ip string) func() {
return func() {
bpfEpMgr.OnUpdate(&proto.HostMetadataUpdate{
Expand Down Expand Up @@ -1669,6 +1684,30 @@ var _ = Describe("BPF Endpoint Manager", func() {
checkIfState(15, "cali12345", flags)
})

It("check bpf endpoint count after pod churn", func() {
start := bpfEpMgr.getNumEPs()
for i := 0; i < 3; i++ {
name := fmt.Sprintf("cali%d", i)
genIfaceUpdate(name, ifacemonitor.StateUp, 1000+i)()
genWLUpdate(name)()

err := bpfEpMgr.CompleteDeferredWork()
Expect(err).NotTo(HaveOccurred())

genIfaceUpdate(name, ifacemonitor.StateDown, 1000+i)()

err = bpfEpMgr.CompleteDeferredWork()
Expect(err).NotTo(HaveOccurred())

genWLUpdateEpRemove(name)()

err = bpfEpMgr.CompleteDeferredWork()
Expect(err).NotTo(HaveOccurred())
}
end := bpfEpMgr.getNumEPs()
Expect(end).To(Equal(start))
})

It("iface up -> wl", func() {
genIfaceUpdate("cali12345", ifacemonitor.StateUp, 15)()
genWLUpdate("cali12345")()
Expand Down

0 comments on commit 50b93c0

Please sign in to comment.