Skip to content

Commit

Permalink
only call createQdiscAndAttach once for each interface
Browse files Browse the repository at this point in the history
  • Loading branch information
nddq committed Jan 17, 2025
1 parent 9fc3202 commit cfe881e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
17 changes: 10 additions & 7 deletions pkg/managers/pluginmanager/pluginmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,20 @@ func (p *PluginManager) Start(ctx context.Context) error {
return ErrZeroInterval
}

g, ctx := errgroup.WithContext(ctx)

if p.cfg.EnablePodLevel {
p.l.Info("starting watchers")
g.Go(func() error {
p.l.Info("starting watchers")

// Start watcher manager
if err := p.watcherManager.Start(ctx); err != nil {
return errors.Wrap(err, "failed to start watcher manager")
}
// Start watcher manager
if err := p.watcherManager.Start(ctx); err != nil {

Check failure on line 136 in pkg/managers/pluginmanager/pluginmanager.go

View workflow job for this annotation

GitHub Actions / Lint (linux, amd64)

shadow: declaration of "err" shadows declaration at line 119 (govet)

Check failure on line 136 in pkg/managers/pluginmanager/pluginmanager.go

View workflow job for this annotation

GitHub Actions / Lint (linux, arm64)

shadow: declaration of "err" shadows declaration at line 119 (govet)

Check failure on line 136 in pkg/managers/pluginmanager/pluginmanager.go

View workflow job for this annotation

GitHub Actions / Lint (windows, amd64)

shadow: declaration of "err" shadows declaration at line 119 (govet)

Check failure on line 136 in pkg/managers/pluginmanager/pluginmanager.go

View workflow job for this annotation

GitHub Actions / Lint (windows, arm64)

shadow: declaration of "err" shadows declaration at line 119 (govet)
return errors.Wrap(err, "failed to start watcher manager")
}
return nil
})
}

g, ctx := errgroup.WithContext(ctx)

// run conntrack GC
ct, err := conntrack.New()
if err != nil {
Expand Down
29 changes: 16 additions & 13 deletions pkg/plugin/packetparser/packetparser_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,23 +382,26 @@ func (p *packetParser) endpointWatcherCallbackFn(obj interface{}) {
iface := event.Obj.(netlink.LinkAttrs)

ifaceKey := ifaceToKey(iface)
lockMapVal, _ := p.interfaceLockMap.LoadOrStore(ifaceKey, &sync.Mutex{})
mu := lockMapVal.(*sync.Mutex)
mu.Lock()
defer mu.Unlock()
_, ifaceExist := p.interfaceLockMap.LoadOrStore(ifaceKey, struct{}{})

switch event.Type {
case endpoint.EndpointCreated:
p.l.Debug("Endpoint created", zap.String("name", iface.Name))
p.createQdiscAndAttach(iface, Veth)
if !ifaceExist {
p.l.Debug("Endpoint created", zap.String("name", iface.Name))
p.createQdiscAndAttach(iface, Veth)
}
case endpoint.EndpointDeleted:
p.l.Debug("Endpoint deleted", zap.String("name", iface.Name))
// Clean.
if value, ok := p.tcMap.Load(ifaceKey); ok {
v := value.(*tcValue)
p.clean(v.tc, v.qdisc)
// Delete from map.
p.tcMap.Delete(ifaceKey)
if ifaceExist {
p.l.Debug("Endpoint deleted", zap.String("name", iface.Name))
// Clean.
if value, ok := p.tcMap.Load(ifaceKey); ok {
v := value.(*tcValue)
p.clean(v.tc, v.qdisc)
// Delete from map.
p.tcMap.Delete(ifaceKey)
}
// Delete from interfaceLockMap.
p.interfaceLockMap.Delete(ifaceKey)
}
default:
// Unknown.
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/packetparser/types_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ type packetParser struct {
tcMap *sync.Map
reader perfReader
enricher enricher.EnricherInterface
// interfaceLockMap is a map of key to *sync.Mutex.
// interfaceLockMap is a map of exisiting interfaces
interfaceLockMap *sync.Map
endpointIngressInfo *ebpf.ProgramInfo
endpointEgressInfo *ebpf.ProgramInfo
Expand Down

0 comments on commit cfe881e

Please sign in to comment.