From 06f4a915bc69a394071605ba71508b3feb9fe905 Mon Sep 17 00:00:00 2001 From: Miguel Duarte Barroso Date: Tue, 18 May 2021 18:27:53 +0200 Subject: [PATCH 1/4] readme, examples: rename the master attr to lowerdevice Signed-off-by: Miguel Duarte Barroso --- README.md | 4 ++-- examples/macvtap-deviceplugin-config-explicit.yaml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1dea3619..d34f63be 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ The value is a json array and each element of the array is a separate resource to be made available: * `name` (string, required) the name of the resource -* `master` (string, required) the name of the macvtap lower link +* `lowerDevice` (string, required) the name of the macvtap lower link * `mode` (string, optional, default=bridge) the macvtap operating mode * `capacity` (uint, optional, default=100) the capacity of the resource @@ -36,7 +36,7 @@ data: DP_MACVTAP_CONF: | [ { "name" : "dataplane", - "master" : "eth0", + "lowerDevice" : "eth0", "mode": "bridge", "capacity" : 50 } ] diff --git a/examples/macvtap-deviceplugin-config-explicit.yaml b/examples/macvtap-deviceplugin-config-explicit.yaml index 2d58f5e1..80304c47 100644 --- a/examples/macvtap-deviceplugin-config-explicit.yaml +++ b/examples/macvtap-deviceplugin-config-explicit.yaml @@ -6,7 +6,7 @@ data: DP_MACVTAP_CONF: >- [ { "name" : "eth0", - "master" : "eth0", + "lowerDevice" : "eth0", "mode": "bridge", "capacity" : 50 } ] From 127ae67138622608fa5949fb7d3c2e8f1d251053 Mon Sep 17 00:00:00 2001 From: Miguel Duarte Barroso Date: Tue, 18 May 2021 18:34:39 +0200 Subject: [PATCH 2/4] dp: use inclusive language Rename the `master` DP attribute to `lowerDevice`. Signed-off-by: Miguel Duarte Barroso --- pkg/deviceplugin/lister.go | 18 +++++++------- pkg/deviceplugin/plugin.go | 50 +++++++++++++++++++------------------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/pkg/deviceplugin/lister.go b/pkg/deviceplugin/lister.go index 23289e10..8bf605b3 100644 --- a/pkg/deviceplugin/lister.go +++ b/pkg/deviceplugin/lister.go @@ -16,10 +16,10 @@ const ( ) type macvtapConfig struct { - Name string `json:"name"` - Master string `json:"master"` - Mode string `json:"mode"` - Capacity int `json:"capacity"` + Name string `json:"name"` + LowerDevice string `json:"lowerDevice"` + Mode string `json:"mode"` + Capacity int `json:"capacity"` } type macvtapLister struct { @@ -157,13 +157,13 @@ func (ml *macvtapLister) NewPlugin(name string) dpm.PluginInterface { c, ok := ml.Config[name] if !ok { c = macvtapConfig{ - Name: name, - Master: name, - Mode: DefaultMode, - Capacity: DefaultCapacity, + Name: name, + LowerDevice: name, + Mode: DefaultMode, + Capacity: DefaultCapacity, } } glog.V(3).Infof("Creating device plugin with config %+v", c) - return NewMacvtapDevicePlugin(c.Name, c.Master, c.Mode, c.Capacity, ml.NetNsPath) + return NewMacvtapDevicePlugin(c.Name, c.LowerDevice, c.Mode, c.Capacity, ml.NetNsPath) } diff --git a/pkg/deviceplugin/plugin.go b/pkg/deviceplugin/plugin.go index 2ebce09a..5b28a69a 100644 --- a/pkg/deviceplugin/plugin.go +++ b/pkg/deviceplugin/plugin.go @@ -22,19 +22,19 @@ const ( ) type macvtapDevicePlugin struct { - Name string - Master string - Mode string - Capacity int + Name string + LowerDevice string + Mode string + Capacity int // NetNsPath is the path to the network namespace the plugin operates in. NetNsPath string stopWatcher chan struct{} } -func NewMacvtapDevicePlugin(name string, master string, mode string, capacity int, netNsPath string) *macvtapDevicePlugin { +func NewMacvtapDevicePlugin(name string, lowerDevice string, mode string, capacity int, netNsPath string) *macvtapDevicePlugin { return &macvtapDevicePlugin{ Name: name, - Master: master, + LowerDevice: lowerDevice, Mode: mode, Capacity: capacity, NetNsPath: netNsPath, @@ -62,47 +62,47 @@ func (mdp *macvtapDevicePlugin) generateMacvtapDevices() []*pluginapi.Device { } func (mdp *macvtapDevicePlugin) ListAndWatch(e *pluginapi.Empty, s pluginapi.DevicePlugin_ListAndWatchServer) error { - // Initialize two arrays, one for devices offered when master exists, - // and no devices if master does not exist. + // Initialize two arrays, one for devices offered when lower device exists, + // and no devices if lower device does not exist. allocatableDevs := mdp.generateMacvtapDevices() emptyDevs := make([]*pluginapi.Device, 0) - emitResponse := func(masterExists bool) { - if masterExists { - glog.V(3).Info("Master exists, sending ListAndWatch response with available devices") + emitResponse := func(lowerDeviceExists bool) { + if lowerDeviceExists { + glog.V(3).Info("LowerDevice exists, sending ListAndWatch response with available devices") s.Send(&pluginapi.ListAndWatchResponse{Devices: allocatableDevs}) } else { - glog.V(3).Info("Master does not exist, sending ListAndWatch response with no devices") + glog.V(3).Info("LowerDevice does not exist, sending ListAndWatch response with no devices") s.Send(&pluginapi.ListAndWatchResponse{Devices: emptyDevs}) } } - didMasterExist := false - onMasterEvent := func() { - var doesMasterExist bool + didLowerDeviceExist := false + onLowerDeviceEvent := func() { + var doesLowerDeviceExist bool err := ns.WithNetNSPath(mdp.NetNsPath, func(_ ns.NetNS) error { var err error - doesMasterExist, err = util.LinkExists(mdp.Master) + doesLowerDeviceExist, err = util.LinkExists(mdp.LowerDevice) return err }) if err != nil { - glog.Warningf("Error while checking on master %s: %v", mdp.Master, err) + glog.Warningf("Error while checking on lower device %s: %v", mdp.LowerDevice, err) return } - if didMasterExist != doesMasterExist { - emitResponse(doesMasterExist) - didMasterExist = doesMasterExist + if didLowerDeviceExist != doesLowerDeviceExist { + emitResponse(doesLowerDeviceExist) + didLowerDeviceExist = doesLowerDeviceExist } } - // Listen for events of master interface. On any, check if master a - // interface exists. If it does, offer up to capacity macvtap devices. Do + // Listen for events of lower device interface. On any, check if lower + // device exists. If it does, offer up to capacity macvtap devices. Do // not offer any otherwise. util.OnLinkEvent( - mdp.Master, + mdp.LowerDevice, mdp.NetNsPath, - onMasterEvent, + onLowerDeviceEvent, mdp.stopWatcher, func(err error) { glog.Error(err) @@ -130,7 +130,7 @@ func (mdp *macvtapDevicePlugin) Allocate(ctx context.Context, r *pluginapi.Alloc var index int err := ns.WithNetNSPath(mdp.NetNsPath, func(_ ns.NetNS) error { var err error - index, err = util.RecreateMacvtap(name, mdp.Master, mdp.Mode) + index, err = util.RecreateMacvtap(name, mdp.LowerDevice, mdp.Mode) return err }) if err != nil { From f0cd8d6ed005e63918d3ced31c18e907f1015c0e Mon Sep 17 00:00:00 2001 From: Miguel Duarte Barroso Date: Tue, 18 May 2021 18:36:25 +0200 Subject: [PATCH 3/4] dp, tests: rename the test variables Signed-off-by: Miguel Duarte Barroso --- pkg/deviceplugin/plugin_test.go | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/pkg/deviceplugin/plugin_test.go b/pkg/deviceplugin/plugin_test.go index 02ce73a6..ca248471 100644 --- a/pkg/deviceplugin/plugin_test.go +++ b/pkg/deviceplugin/plugin_test.go @@ -57,8 +57,8 @@ func (s *ListAndWatchServerSendSpy) SetTrailer(m metadata.MD) { } var _ = Describe("Macvtap", func() { - var masterIfaceName string - var masterIface netlink.Link + var lowerDeviceIfaceName string + var lowerDeviceIface netlink.Link var testNs ns.NetNS BeforeEach(func() { @@ -66,21 +66,21 @@ var _ = Describe("Macvtap", func() { testNs, err = testutils.NewNS() Expect(err).NotTo(HaveOccurred()) - masterIfaceName = fmt.Sprintf("master%d", rand.Intn(100)) - masterIface = &netlink.Dummy{ + lowerDeviceIfaceName = fmt.Sprintf("lowerdev%d", rand.Intn(100)) + lowerDeviceIface = &netlink.Dummy{ LinkAttrs: netlink.LinkAttrs{ - Name: masterIfaceName, + Name: lowerDeviceIfaceName, Namespace: netlink.NsFd(int(testNs.Fd())), }, } - err = netlink.LinkAdd(masterIface) + err = netlink.LinkAdd(lowerDeviceIface) Expect(err).NotTo(HaveOccurred()) }) AfterEach(func() { testNs.Do(func(ns ns.NetNS) error { - netlink.LinkDel(masterIface) + netlink.LinkDel(lowerDeviceIface) return nil }) }) @@ -90,7 +90,7 @@ var _ = Describe("Macvtap", func() { var sendSpy *ListAndWatchServerSendSpy BeforeEach(func() { - mvdp = NewMacvtapDevicePlugin(masterIfaceName, masterIfaceName, "bridge", 0, testNs.Path()) + mvdp = NewMacvtapDevicePlugin(lowerDeviceIfaceName, lowerDeviceIfaceName, "bridge", 0, testNs.Path()) sendSpy = &ListAndWatchServerSendSpy{} go func() { err := mvdp.ListAndWatch(nil, sendSpy) @@ -103,7 +103,7 @@ var _ = Describe("Macvtap", func() { }) It("should allocate a new device upon request", func() { - ifaceName := masterIfaceName + "Mvp99" + ifaceName := lowerDeviceIfaceName + "Mvp99" req := &pluginapi.AllocateRequest{ ContainerRequests: []*pluginapi.ContainerAllocateRequest{ { @@ -132,7 +132,7 @@ var _ = Describe("Macvtap", func() { Expect(dev.HostPath).To(Equal(dev.ContainerPath)) }) - Context("when master device does not exist", func() { + Context("when lower device does not exist", func() { It("should not advertise devices", func() { By("first advertising healthy devices", func() { Eventually(func() int { @@ -142,9 +142,9 @@ var _ = Describe("Macvtap", func() { Expect(sendSpy.last.Devices).To(HaveLen(100)) }) - By("then deleting the master device", func() { + By("then deleting the lower device", func() { err := testNs.Do(func(ns ns.NetNS) error { - return util.LinkDelete(masterIfaceName) + return util.LinkDelete(lowerDeviceIfaceName) }) Expect(err).NotTo(HaveOccurred()) }) @@ -183,10 +183,10 @@ var _ = Describe("Macvtap", func() { resourceName := "dataplane" mode := "vepa" capacity := 30 - config := `[{"name":"%s","master":"%s","mode":"%s","capacity":%d}]` + config := `[{"name":"%s","lowerDevice":"%s","mode":"%s","capacity":%d}]` BeforeEach(func() { - config = fmt.Sprintf(config, resourceName, masterIfaceName, mode, capacity) + config = fmt.Sprintf(config, resourceName, lowerDeviceIfaceName, mode, capacity) os.Setenv(ConfigEnvironmentVariable, config) }) @@ -200,7 +200,7 @@ var _ = Describe("Macvtap", func() { plugin := lister.NewPlugin(resourceName) Expect(plugin.(*macvtapDevicePlugin).Name).To(Equal(resourceName)) - Expect(plugin.(*macvtapDevicePlugin).Master).To(Equal(masterIfaceName)) + Expect(plugin.(*macvtapDevicePlugin).LowerDevice).To(Equal(lowerDeviceIfaceName)) Expect(plugin.(*macvtapDevicePlugin).Mode).To(Equal(mode)) Expect(plugin.(*macvtapDevicePlugin).Capacity).To(Equal(capacity)) }) @@ -238,7 +238,7 @@ var _ = Describe("Macvtap", func() { plugin := lister.NewPlugin(parentName) Expect(plugin.(*macvtapDevicePlugin).Name).To(Equal(parentName)) - Expect(plugin.(*macvtapDevicePlugin).Master).To(Equal(parentName)) + Expect(plugin.(*macvtapDevicePlugin).LowerDevice).To(Equal(parentName)) Expect(plugin.(*macvtapDevicePlugin).Mode).To(Equal(DefaultMode)) Expect(plugin.(*macvtapDevicePlugin).Capacity).To(Equal(DefaultCapacity)) }) From acb56465b345ea88495180f5db78f6067c69385d Mon Sep 17 00:00:00 2001 From: Miguel Duarte Barroso Date: Tue, 18 May 2021 18:41:20 +0200 Subject: [PATCH 4/4] netlink utils: use inclusive language Signed-off-by: Miguel Duarte Barroso --- pkg/util/netlink.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/util/netlink.go b/pkg/util/netlink.go index d3fc8ead..6017ca6e 100644 --- a/pkg/util/netlink.go +++ b/pkg/util/netlink.go @@ -35,12 +35,12 @@ func ModeFromString(s string) (netlink.MacvlanMode, error) { } } -func CreateMacvtap(name string, master string, mode string) (int, error) { +func CreateMacvtap(name string, lowerDevice string, mode string) (int, error) { ifindex := 0 - m, err := netlink.LinkByName(master) + m, err := netlink.LinkByName(lowerDevice) if err != nil { - return ifindex, fmt.Errorf("failed to lookup master %q: %v", master, err) + return ifindex, fmt.Errorf("failed to lookup lowerDevice %q: %v", lowerDevice, err) } nlmode, err := ModeFromString(mode) @@ -72,12 +72,12 @@ func CreateMacvtap(name string, master string, mode string) (int, error) { return ifindex, nil } -func RecreateMacvtap(name string, master string, mode string) (int, error) { +func RecreateMacvtap(name string, lowerDevice string, mode string) (int, error) { err := LinkDelete(name) if err != nil { return 0, err } - return CreateMacvtap(name, master, mode) + return CreateMacvtap(name, lowerDevice, mode) } func LinkExists(link string) (bool, error) {