Skip to content

Commit

Permalink
Fix Remaining lint issues
Browse files Browse the repository at this point in the history
This commit handles remaining lint issues.

Signed-off-by: Adrian Chiris <adrianc@nvidia.com>
  • Loading branch information
adrianchiris authored and martinkennelly committed Aug 10, 2021
1 parent d0b252a commit 441e06f
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 34 deletions.
1 change: 0 additions & 1 deletion cmd/sriovdp/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ type cliParams struct {
type resourceManager struct {
cliParams
pluginWatchMode bool
socketSuffix string
rFactory types.ResourceFactory
configList []*types.ResourceConfig
resourceServers []types.ResourceServer
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.5.1
github.com/vishvananda/netlink v1.1.0
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 // indirect
golang.org/x/sys v0.0.0-20210510120138-977fb7262007 // indirect
google.golang.org/grpc v1.28.1
k8s.io/kubelet v0.18.1
Expand Down
4 changes: 2 additions & 2 deletions pkg/factory/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ var _ = Describe("Factory", func() {
}

var selectors json.RawMessage
err := selectors.UnmarshalJSON([]byte(`
err = selectors.UnmarshalJSON([]byte(`
[
{
"vendors": ["8086"],
Expand Down Expand Up @@ -187,7 +187,7 @@ var _ = Describe("Factory", func() {
}

var selectors json.RawMessage
err := selectors.UnmarshalJSON([]byte(`
err = selectors.UnmarshalJSON([]byte(`
[
{
"vendors": ["8086"],
Expand Down
6 changes: 6 additions & 0 deletions pkg/netdevice/netDeviceProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,14 @@ func hasDefaultRoute(pciAddr string) (bool, error) {
link, err := netlink.LinkByName(ifName)
if err != nil {
glog.Errorf("expected to get valid host interface with name %s: %q", ifName, err)
continue
}

routes, err := netlink.RouteList(link, netlink.FAMILY_V4) // IPv6 routes: all interface has at least one link local route entry
if err != nil {
glog.Errorf("failed to get routes for interface: %s, %q", ifName, err)
continue
}
for _, r := range routes {
if r.Dst == nil {
glog.Infof("excluding interface %s: default route found: %+v", ifName, r)
Expand All @@ -125,6 +130,7 @@ func hasDefaultRoute(pciAddr string) (bool, error) {
return false, nil
}

//nolint:gocyclo
func (np *netDeviceProvider) GetFilteredDevices(devices []types.PciDevice, rc *types.ResourceConfig) ([]types.PciDevice, error) {
filteredDevice := devices
nf, ok := rc.SelectorObj.(*types.NetDeviceSelectors)
Expand Down
2 changes: 0 additions & 2 deletions pkg/resources/pciDevice.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ type pciDevice struct {
basePciDevice *ghw.PCIDevice
pfAddr string
driver string
vendor string
product string
vfID int
numa string
apiDevice *pluginapi.Device
Expand Down
17 changes: 5 additions & 12 deletions pkg/resources/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package resources

import (
"context"
"fmt"
"net"
"os"
Expand All @@ -25,7 +26,6 @@ import (
"github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/types"

"github.com/golang/glog"
"golang.org/x/net/context"
"google.golang.org/grpc"
pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
registerapi "k8s.io/kubelet/pkg/apis/pluginregistration/v1"
Expand Down Expand Up @@ -71,11 +71,8 @@ func NewResourceServer(prefix, suffix string, pluginWatch bool, rp types.Resourc
}

func (rs *resourceServer) register() error {
kubeletEndpoint := filepath.Join(types.DeprecatedSockDir, types.KubeEndPoint)
conn, err := grpc.Dial(kubeletEndpoint, grpc.WithInsecure(),
grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) {
return net.DialTimeout("unix", addr, timeout)
}))
kubeletEndpoint := "unix:" + filepath.Join(types.DeprecatedSockDir, types.KubeEndPoint)
conn, err := grpc.Dial(kubeletEndpoint, grpc.WithInsecure())
if err != nil {
glog.Errorf("%s device plugin unable connect to Kubelet : %v", rs.resourcePool.GetResourceName(), err)
return err
Expand Down Expand Up @@ -219,12 +216,8 @@ func (rs *resourceServer) Start() error {
}
}()
// Wait for server to start by launching a blocking connection
conn, err := grpc.Dial(rs.sockPath, grpc.WithInsecure(), grpc.WithBlock(),
grpc.WithTimeout(serverStartTimeout),
grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) {
return net.DialTimeout("unix", addr, timeout)
}),
)
ctx, _ := context.WithTimeout(context.TODO(), serverStartTimeout)
conn, err := grpc.DialContext(ctx, "unix:"+rs.sockPath, grpc.WithInsecure(), grpc.WithBlock())

if err != nil {
glog.Errorf("error. unable to establish test connection with %s gRPC server: %v", resourceName, err)
Expand Down
6 changes: 1 addition & 5 deletions pkg/resources/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@ func (s *fakeRegistrationServer) dial() (registerapi.RegistrationClient, *grpc.C
ctx, cancel := context.WithTimeout(context.Background(), dialTimeout)
defer cancel()

c, err := grpc.DialContext(ctx, sockPath, grpc.WithInsecure(), grpc.WithBlock(),
grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) {
return net.DialTimeout("unix", addr, timeout)
}),
)
c, err := grpc.DialContext(ctx, "unix:"+sockPath, grpc.WithInsecure(), grpc.WithBlock())

if err != nil {
return nil, nil, fmt.Errorf("failed to dial socket %s, err: %v", sockPath, err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/utils/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (fs *FakeFilesystem) Use() func() {
}
}
for filename, body := range fs.Files {
err := ioutil.WriteFile(path.Join(fs.RootDir, filename), body, 0644)
err := ioutil.WriteFile(path.Join(fs.RootDir, filename), body, 0600)
if err != nil {
panic(fmt.Errorf("error creating fake file: %s", err.Error()))
}
Expand All @@ -48,7 +48,7 @@ func (fs *FakeFilesystem) Use() func() {
if err != nil {
panic(fmt.Errorf("error reading file: %s", err.Error()))
}
err = ioutil.WriteFile(path.Join(fs.RootDir, "usr/share/hwdata/pci.ids"), pciData, 0644)
err = ioutil.WriteFile(path.Join(fs.RootDir, "usr/share/hwdata/pci.ids"), pciData, 0600)
if err != nil {
panic(fmt.Errorf("error creating fake file: %s", err.Error()))
}
Expand Down
19 changes: 10 additions & 9 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

var (
sysBusPci = "/sys/bus/pci/devices"
devDir = "/dev"
)

const (
Expand Down Expand Up @@ -260,32 +261,32 @@ func GetVFIODeviceFile(dev string) (devFileHost, devFileContainer string, err er
_, err = os.Lstat(devPath)
if err != nil {
err = fmt.Errorf("GetVFIODeviceFile(): Could not get directory information for device: %s, Err: %v", dev, err)
return
return devFileHost, devFileContainer, err
}

iommuDir := filepath.Join(devPath, "iommu_group")
if err != nil {
err = fmt.Errorf("GetVFIODeviceFile(): error reading iommuDir %v", err)
return
return devFileHost, devFileContainer, err
}

dirInfo, err := os.Lstat(iommuDir)
if err != nil {
err = fmt.Errorf("GetVFIODeviceFile(): unable to find iommu_group %v", err)
return
return devFileHost, devFileContainer, err
}

if dirInfo.Mode()&os.ModeSymlink == 0 {
err = fmt.Errorf("GetVFIODeviceFile(): invalid symlink to iommu_group %v", err)
return
return devFileHost, devFileContainer, err
}

linkName, err := filepath.EvalSymlinks(iommuDir)
if err != nil {
err = fmt.Errorf("GetVFIODeviceFile(): error reading symlink to iommu_group %v", err)
return
return devFileHost, devFileContainer, err
}
devFileContainer = filepath.Join("/dev", "vfio", filepath.Base(linkName))
devFileContainer = filepath.Join(devDir, "vfio", filepath.Base(linkName))
devFileHost = devFileContainer

// Get a file path to the iommu group name
Expand All @@ -299,11 +300,11 @@ func GetVFIODeviceFile(dev string) (devFileHost, devFileContainer string, err er
// if the iommu group name == vfio-noiommu then we are in a VM, adjust path to vfio device
if vName == "vfio-noiommu" {
linkName = filepath.Join(filepath.Dir(linkName), "noiommu-"+filepath.Base(linkName))
devFileHost = filepath.Join("/dev/vfio", filepath.Base(linkName))
devFileHost = filepath.Join(devDir, "vfio", filepath.Base(linkName))
}
}

return
return devFileHost, devFileContainer, err
}

// GetUIODeviceFile returns a vfio device files for vfio-pci bound PCI device's PCI address
Expand All @@ -323,7 +324,7 @@ func GetUIODeviceFile(dev string) (devFile string, err error) {

// uio directory should only contain one directory e.g uio1
// assuption is there's a corresponding device file in /dev e.g. /dev/uio1
devFile = filepath.Join("/dev", files[0].Name())
devFile = filepath.Join(devDir, files[0].Name())

return
}
Expand Down

0 comments on commit 441e06f

Please sign in to comment.