Skip to content

Commit 7bfdc5a

Browse files
committed
remove resource limit on ds
add lock for macvtapLister.deviceListLock
1 parent 9a3dfa1 commit 7bfdc5a

4 files changed

Lines changed: 19 additions & 14 deletions

File tree

config/daemonset/daemonset.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ spec:
4646
runAsGroup: 0
4747
privileged: true
4848
resources:
49-
limits:
50-
cpu: 500m
51-
memory: 128Mi
5249
requests:
5350
cpu: 10m
5451
memory: 64Mi

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ require (
1111
github.com/onsi/gomega v1.38.3
1212
github.com/safchain/ethtool v0.6.2
1313
github.com/vishvananda/netlink v1.3.1
14-
golang.org/x/net v0.48.0
1514
golang.org/x/sys v0.39.0
1615
k8s.io/apimachinery v0.35.0
1716
k8s.io/client-go v0.35.0
@@ -85,6 +84,7 @@ require (
8584
go.yaml.in/yaml/v3 v3.0.4 // indirect
8685
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
8786
golang.org/x/mod v0.31.0 // indirect
87+
golang.org/x/net v0.48.0 // indirect
8888
golang.org/x/oauth2 v0.30.0 // indirect
8989
golang.org/x/sync v0.19.0 // indirect
9090
golang.org/x/term v0.38.0 // indirect

pkg/deviceplugin/lister.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@ import (
1111
)
1212

1313
type macvtapLister struct {
14-
DeviceList map[string]*v1beta1.LAN //key is the res name in the LAN
15-
// lock *sync.RWMutex
16-
// NetNsPath is the path to the network namespace the lister operates in.
14+
DeviceList map[string]*v1beta1.LAN //key is the res name in the LAN
15+
deviceListLock *sync.RWMutex
1716
AddChan chan v1beta1.AddRequest
1817
RemovChan chan *v1beta1.LAN
1918
ExistingNSList []string
20-
ExistingNSListLock *sync.RWMutex
19+
existingNSListLock *sync.RWMutex
2120
}
2221

2322
func (ml *macvtapLister) getCurrentPlugins() dpm.PluginNameList {
2423
r := make(dpm.PluginNameList, 0)
24+
ml.deviceListLock.RLock()
25+
defer ml.deviceListLock.RUnlock()
2526
for name := range ml.DeviceList {
2627
r = append(r, name)
2728
}
@@ -33,7 +34,8 @@ func NewMacvtapLister(netNsPath string, add chan v1beta1.AddRequest, remove chan
3334
AddChan: add,
3435
RemovChan: remove,
3536
DeviceList: make(map[string]*v1beta1.LAN),
36-
ExistingNSListLock: new(sync.RWMutex),
37+
deviceListLock: new(sync.RWMutex),
38+
existingNSListLock: new(sync.RWMutex),
3739
}
3840
}
3941

@@ -55,22 +57,26 @@ func (ml *macvtapLister) Discover(pluginListCh chan dpm.PluginNameList) {
5557

5658
lan := req.NewLan
5759
log.Info("got a new lan", "name", lan.Name)
58-
ml.ExistingNSListLock.Lock()
60+
ml.existingNSListLock.Lock()
5961
ml.ExistingNSList = req.ExistingNSNames
60-
ml.ExistingNSListLock.Unlock()
62+
ml.existingNSListLock.Unlock()
63+
ml.deviceListLock.Lock()
6164
for _, spokeName := range lan.Spec.SpokeList {
6265
ml.DeviceList[v1beta1.GetDPResouceName(lan.Name, spokeName, true)] = lan
6366
ml.DeviceList[v1beta1.GetDPResouceName(lan.Name, spokeName, false)] = lan
6467
}
68+
ml.deviceListLock.Unlock()
6569
ml.report(pluginListCh)
6670
log.Info("report the new lan", "name", lan.Name)
6771

6872
case lan := <-ml.RemovChan:
6973
log.Info("got a lan to remove", "name", lan.Name)
74+
ml.deviceListLock.Lock()
7075
for _, spokeName := range lan.Spec.SpokeList {
7176
delete(ml.DeviceList, v1beta1.GetDPResouceName(lan.Name, spokeName, true))
7277
delete(ml.DeviceList, v1beta1.GetDPResouceName(lan.Name, spokeName, false))
7378
}
79+
ml.deviceListLock.Unlock()
7480
ml.report(pluginListCh)
7581
log.Info("report new dev list after removal", "name", lan.Name)
7682

@@ -82,7 +88,9 @@ func (ml *macvtapLister) Discover(pluginListCh chan dpm.PluginNameList) {
8288
// also vlanName in k8slan case
8389
func (ml *macvtapLister) NewPlugin(name string) dpm.PluginInterface {
8490
log := ctrl.Log.WithName("deviceplugin")
91+
ml.deviceListLock.RLock()
8592
lan, ok := ml.DeviceList[name]
93+
ml.deviceListLock.RUnlock()
8694
if !ok {
8795
return nil
8896
}

pkg/deviceplugin/plugin.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package deviceplugin
22

33
import (
4+
"context"
45
"fmt"
56
"os"
67
"slices"
@@ -9,7 +10,6 @@ import (
910

1011
"github.com/hujun-open/k8slan/api/v1beta1"
1112
"github.com/hujun-open/k8slan/pkg/interfaces"
12-
"golang.org/x/net/context"
1313
pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
1414
ctrl "sigs.k8s.io/controller-runtime"
1515
)
@@ -84,9 +84,9 @@ func (mdp *macvtapDevicePlugin) ListAndWatch(e *pluginapi.Empty, s pluginapi.Dev
8484
}
8585

8686
func (mdp *macvtapDevicePlugin) clearUnused() error {
87-
mdp.lister.ExistingNSListLock.RLock()
87+
mdp.lister.existingNSListLock.RLock()
8888
crNSList := slices.Clone(mdp.lister.ExistingNSList)
89-
mdp.lister.ExistingNSListLock.RUnlock()
89+
mdp.lister.existingNSListLock.RUnlock()
9090
existList, err := interfaces.GetExistingNSPaths()
9191
if err != nil {
9292
return fmt.Errorf("failed to list existing NS path, %w", err)

0 commit comments

Comments
 (0)