diff --git a/felix/dataplane/linux/bpf_ep_mgr.go b/felix/dataplane/linux/bpf_ep_mgr.go index 61709acfcf4..75f4ef750a7 100644 --- a/felix/dataplane/linux/bpf_ep_mgr.go +++ b/felix/dataplane/linux/bpf_ep_mgr.go @@ -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. }) @@ -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" { diff --git a/felix/dataplane/linux/bpf_ep_mgr_test.go b/felix/dataplane/linux/bpf_ep_mgr_test.go index 00dd2e26154..f39164030f6 100644 --- a/felix/dataplane/linux/bpf_ep_mgr_test.go +++ b/felix/dataplane/linux/bpf_ep_mgr_test.go @@ -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{ @@ -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")()