Skip to content
This repository was archived by the owner on Apr 8, 2025. It is now read-only.

Commit a832cff

Browse files
committed
api updates
updates flagged by golangci-lint Signed-off-by: John O'Loughlin <[email protected]>
1 parent 4e5d240 commit a832cff

File tree

16 files changed

+127
-155
lines changed

16 files changed

+127
-155
lines changed

Diff for: cniovs/cniovs.go

+17-19
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,17 @@ import (
4848
"github.com/intel/userspace-cni-network-plugin/pkg/types"
4949
)
5050

51-
//
5251
// Constants
53-
//
5452
const (
5553
defaultBridge = "br0"
5654
DefaultHostVhostuserBaseDir = "/var/lib/vhost_sockets/"
5755
)
5856

59-
//
6057
// Types
61-
//
6258
type CniOvs struct {
6359
}
6460

65-
//
6661
// API Functions
67-
//
6862
func (cniOvs CniOvs) AddOnHost(conf *types.NetConf,
6963
args *skel.CmdArgs,
7064
kubeClient kubernetes.Interface,
@@ -196,7 +190,11 @@ func (cniOvs CniOvs) DelFromHost(conf *types.NetConf, args *skel.CmdArgs, shared
196190
func (cniOvs CniOvs) DelFromContainer(conf *types.NetConf, args *skel.CmdArgs, sharedDir string, pod *v1.Pod) error {
197191
logging.Infof("OVS DelFromContainer: ENTER - Container %s Iface %s", args.ContainerID[:12], args.IfName)
198192

199-
configdata.FileCleanup(sharedDir, "")
193+
var err = configdata.FileCleanup(sharedDir, "")
194+
195+
if err != nil {
196+
logging.Debugf("DelFromContainer(ovs): %v", err)
197+
}
200198

201199
return nil
202200
}
@@ -243,15 +241,15 @@ func createSharedDir(sharedDir, oldSharedDir string) error {
243241
if os.IsNotExist(err) {
244242
err = os.MkdirAll(sharedDir, 0750)
245243
if err != nil {
246-
logging.Errorf("createSharedDir: Failed to create dir (%s): %v", sharedDir, err)
244+
_ = logging.Errorf("createSharedDir: Failed to create dir (%s): %v", sharedDir, err)
247245
return err
248246
}
249247

250248
if strings.Contains(sharedDir, DefaultHostVhostuserBaseDir) {
251249
logging.Debugf("createSharedDir: Mount from %s to %s", oldSharedDir, sharedDir)
252250
err = unix.Mount(oldSharedDir, sharedDir, "", unix.MS_BIND, "")
253251
if err != nil {
254-
logging.Errorf("createSharedDir: Failed to bind mount: %s", err)
252+
_ = logging.Errorf("createSharedDir: Failed to bind mount: %s", err)
255253
return err
256254
}
257255
}
@@ -296,15 +294,15 @@ func addLocalDeviceVhost(conf *types.NetConf, args *skel.CmdArgs, actualSharedDi
296294
sharedDir := getShortSharedDir(actualSharedDir)
297295
err = createSharedDir(sharedDir, actualSharedDir)
298296
if err != nil {
299-
logging.Errorf("addLocalDeviceVhost: Failed to create shared dir: %v", err)
297+
_ = logging.Errorf("addLocalDeviceVhost: Failed to create shared dir: %v", err)
300298
return err
301299
}
302300

303301
group := conf.HostConf.VhostConf.Group
304302
if group != "" {
305303
err = setSharedDirGroup(sharedDir, group)
306304
if err != nil {
307-
logging.Errorf("addLocalDeviceVhost: Failed to set shared dir group: %v", err)
305+
_ = logging.Errorf("addLocalDeviceVhost: Failed to set shared dir group: %v", err)
308306
return err
309307
}
310308
}
@@ -341,7 +339,7 @@ func delLocalDeviceVhost(conf *types.NetConf, args *skel.CmdArgs, actualSharedDi
341339
// ovs-vsctl --if-exists del-port
342340
err := deleteVhostPort(data.Vhostname, conf.HostConf.BridgeConf.BridgeName)
343341
if err != nil {
344-
logging.Errorf("delLocalDeviceVhost: Failed to delete port: %v", err)
342+
_ = logging.Errorf("delLocalDeviceVhost: Failed to delete port: %v", err)
345343
return err
346344
}
347345

@@ -350,17 +348,17 @@ func delLocalDeviceVhost(conf *types.NetConf, args *skel.CmdArgs, actualSharedDi
350348
logging.Debugf("delLocalDeviceVhost: Unmount shared directory: %v", sharedDir)
351349
_, err = os.Stat(sharedDir)
352350
if os.IsNotExist(err) {
353-
logging.Errorf("delLocalDeviceVhost: shared directory %s does not exist to unmount", sharedDir)
351+
_ = logging.Errorf("delLocalDeviceVhost: shared directory %s does not exist to unmount", sharedDir)
354352
return nil
355353
}
356354
err = unix.Unmount(sharedDir, 0)
357355
if err != nil {
358-
logging.Errorf("Failed to unmount dir: %v", err)
356+
_ = logging.Errorf("Failed to unmount dir: %v", err)
359357
return err
360358
}
361359
err = os.Remove(sharedDir)
362360
if err != nil {
363-
logging.Errorf("Failed to remove dir: %v", err)
361+
_ = logging.Errorf("Failed to remove dir: %v", err)
364362
return err
365363
}
366364
} else {
@@ -379,7 +377,7 @@ func delLocalDeviceVhost(conf *types.NetConf, args *skel.CmdArgs, actualSharedDi
379377

380378
// Remove files with matching container ID and IfName
381379
for _, fileName := range filesForContainerID {
382-
if match, _ := regexp.MatchString(fileBaseName+"*", fileName); match == true {
380+
if match, _ := regexp.MatchString(fileBaseName+"*", fileName); match {
383381
logging.Debugf("OVS DelFromContainer: %s matches file %s", fileBaseName, fileName)
384382
file := filepath.Join(sharedDir, fileName)
385383
if err = os.Remove(file); err != nil {
@@ -392,7 +390,7 @@ func delLocalDeviceVhost(conf *types.NetConf, args *skel.CmdArgs, actualSharedDi
392390

393391
// In case the Socketfile name was passed in:
394392
if conf.HostConf.VhostConf.Socketfile != fileBaseName {
395-
if match, _ := regexp.MatchString(conf.HostConf.VhostConf.Socketfile+"*", fileName); match == true {
393+
if match, _ := regexp.MatchString(conf.HostConf.VhostConf.Socketfile+"*", fileName); match {
396394
file := filepath.Join(sharedDir, fileName)
397395
if err = os.Remove(file); err != nil {
398396
return err
@@ -415,7 +413,7 @@ func delLocalDeviceVhost(conf *types.NetConf, args *skel.CmdArgs, actualSharedDi
415413
func addLocalNetworkBridge(conf *types.NetConf, args *skel.CmdArgs, data *OvsSavedData) error {
416414
var err error
417415

418-
if found := findBridge(conf.HostConf.BridgeConf.BridgeName); found == false {
416+
if found := findBridge(conf.HostConf.BridgeConf.BridgeName); !found {
419417
logging.Debugf("addLocalNetworkBridge(): Bridge %s not found, creating", conf.HostConf.BridgeConf.BridgeName)
420418
err = createBridge(conf.HostConf.BridgeConf.BridgeName)
421419

@@ -438,7 +436,7 @@ func addLocalNetworkBridge(conf *types.NetConf, args *skel.CmdArgs, data *OvsSav
438436
func delLocalNetworkBridge(conf *types.NetConf, args *skel.CmdArgs, data *OvsSavedData) error {
439437
var err error
440438

441-
if containInterfaces := doesBridgeContainInterfaces(conf.HostConf.BridgeConf.BridgeName); containInterfaces == false {
439+
if containInterfaces := doesBridgeContainInterfaces(conf.HostConf.BridgeConf.BridgeName); !containInterfaces {
442440
logging.Debugf("delLocalNetworkBridge(): No interfaces found, deleting Bridge %s", conf.HostConf.BridgeConf.BridgeName)
443441
err = deleteBridge(conf.HostConf.BridgeConf.BridgeName)
444442
} else {

Diff for: cniovs/cniovs_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func TestGenerateRandomMacAddress(t *testing.T) {
219219
macs := make(map[string]int)
220220
for i := 0; i < nr; i++ {
221221
mac := generateRandomMacAddress()
222-
ok, err := regexp.Match("^[0-9a-fA-F]{2}(:([0-9a-fA-F]){2}){5}$", []byte(mac))
222+
ok, err := regexp.Compile("^[0-9a-fA-F]{2}(:([0-9a-fA-F]){2}){5}$", []byte(mac))
223223
require.NoError(t, err, fmt.Sprintf("MAC is incorrect. MAC: %q", mac))
224224
require.True(t, ok, fmt.Sprintf("MAC is incorrect. MAC: %q", mac))
225225
macs[mac]++

Diff for: cnivpp/api/bridge/bridge.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func DeleteBridge(ch api.Channel, bridgeDomain uint32) error {
7777

7878
// Determine if bridge domain exists
7979
exists, count := findBridge(ch, bridgeDomain)
80-
if exists == false || count != 0 {
80+
if !exists || count != 0 {
8181
return nil
8282
}
8383

Diff for: cnivpp/api/memif/memif.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ import (
3838

3939
const debugMemif = false
4040

41-
type MemifRole uint8
41+
type MemifRole uint32
4242

4343
const (
4444
RoleMaster MemifRole = 0
4545
RoleSlave MemifRole = 1
4646
)
4747

48-
type MemifMode uint8
48+
type MemifMode uint32
4949

5050
const (
5151
ModeEthernet MemifMode = 0
@@ -56,7 +56,6 @@ const (
5656
// Dump Strings
5757
var modeStr = [...]string{"eth", "ip ", "pnt"}
5858
var roleStr = [...]string{"master", "slave "}
59-
var stateStr = [...]string{"dn", "up"}
6059

6160
//
6261
// API Functions
@@ -108,7 +107,7 @@ func DeleteMemifInterface(ch api.Channel, swIfIndex interface_types.InterfaceInd
108107
// Determine if memif interface exists
109108
socketId, exist := findMemifInterface(ch, swIfIndex)
110109
if debugMemif {
111-
if exist == false {
110+
if !exist {
112111
logging.Verbosef("Error deleting memif interface: memif interface (swIfIndex=%d) Does NOT Exist", swIfIndex)
113112
} else {
114113
logging.Verbosef("Attempting to delete memif interface %d with SocketId %d", swIfIndex, socketId)
@@ -428,10 +427,10 @@ func findMemifSocket(ch api.Channel, socketFilename string) (found bool, socketI
428427
// If input SocketFilename has not been created, then loop
429428
// through the list of existing SocketIds and find an unused Id.
430429
//
431-
if found == false {
430+
if !found {
432431
socketId = 1
433432

434-
for done == false {
433+
for !done {
435434

436435
done = true
437436
for i := 0; i < count; i++ {

Diff for: cnivpp/api/vhostuser/vhostuser.go

+19-19
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ package vppvhostuser
2222
import (
2323
"fmt"
2424

25-
"go.fd.io/govpp/api"
25+
"github.com/intel/userspace-cni-network-plugin/cnivpp/bin_api/interface_types"
2626
"github.com/intel/userspace-cni-network-plugin/cnivpp/bin_api/vhost_user"
27+
"go.fd.io/govpp/api"
2728
)
2829

2930
//
@@ -32,34 +33,32 @@ import (
3233

3334
const debugVhost = false
3435

35-
type VhostUserMode uint8
36+
type VhostUserMode bool
3637

3738
const (
38-
ModeClient VhostUserMode = 0
39-
ModeServer VhostUserMode = 1
39+
ModeClient VhostUserMode = false
40+
ModeServer VhostUserMode = true
4041
)
4142

42-
// Dump Strings
43-
var modeStr = [...]string{"client", "server"}
44-
4543
//
4644
// API Functions
4745
//
4846

4947
// Attempt to create a Vhost-User Interface.
5048
// Input:
51-
// ch api.Channel
52-
// mode VhostUserMode - ModeClient or ModeServer
53-
// socketFile string - Directory and Filename of socket file
54-
func CreateVhostUserInterface(ch api.Channel, mode VhostUserMode, socketFile string) (swIfIndex uint32, err error) {
49+
//
50+
// ch api.Channel
51+
// mode VhostUserMode - ModeClient or ModeServer
52+
// socketFile string - Directory and Filename of socket file
53+
func CreateVhostUserInterface(ch api.Channel, mode bool, socketFile string) (swIfIndex interface_types.InterfaceIndex, err error) {
5554

5655
// Populate the Add Structure
5756
req := &vhost_user.CreateVhostUserIf{
58-
IsServer: uint8(mode),
59-
SockFilename: []byte(socketFile),
60-
Renumber: 0,
57+
IsServer: mode,
58+
SockFilename: socketFile,
59+
Renumber: false,
6160
CustomDevInstance: 0,
62-
UseCustomMac: 0,
61+
UseCustomMac: false,
6362
//MacAddress: "",
6463
//Tag: "",
6564
}
@@ -81,7 +80,7 @@ func CreateVhostUserInterface(ch api.Channel, mode VhostUserMode, socketFile str
8180
}
8281

8382
// Attempt to delete a Vhost-User interface.
84-
func DeleteVhostUserInterface(ch api.Channel, swIfIndex uint32) (err error) {
83+
func DeleteVhostUserInterface(ch api.Channel, swIfIndex interface_types.InterfaceIndex) (err error) {
8584

8685
// Populate the Delete Structure
8786
req := &vhost_user.DeleteVhostUserIf{
@@ -122,13 +121,14 @@ func DumpVhostUser(ch api.Channel) {
122121
}
123122
//fmt.Printf("%+v\n", reply)
124123

125-
fmt.Printf(" SwIfId=%d Mode=%s IfName=%s NumReg=%d SockErrno=%d Feature=0x16%x HdrSz=%d SockFile=%s\n",
124+
fmt.Printf(" SwIfId=%d Mode=%t IfName=%s NumReg=%d SockErrno=%d FeaturesFirst32=%d FeaturesLast32=%d HdrSz=%d SockFile=%s\n",
126125
reply.SwIfIndex,
127-
modeStr[reply.IsServer],
126+
reply.IsServer,
128127
string(reply.InterfaceName),
129128
reply.NumRegions,
130129
reply.SockErrno,
131-
reply.Features,
130+
reply.FeaturesFirst32,
131+
reply.FeaturesLast32,
132132
reply.VirtioNetHdrSz,
133133
string(reply.SockFilename))
134134

Diff for: cnivpp/cnivpp.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ import (
3737
"github.com/containernetworking/cni/pkg/skel"
3838
current "github.com/containernetworking/cni/pkg/types/100"
3939

40-
"github.com/intel/userspace-cni-network-plugin/cnivpp/api/bridge"
41-
"github.com/intel/userspace-cni-network-plugin/cnivpp/api/infra"
42-
"github.com/intel/userspace-cni-network-plugin/cnivpp/api/interface"
43-
"github.com/intel/userspace-cni-network-plugin/cnivpp/api/memif"
44-
"github.com/intel/userspace-cni-network-plugin/cnivpp/bin_api/memif"
40+
vppbridge "github.com/intel/userspace-cni-network-plugin/cnivpp/api/bridge"
41+
vppinfra "github.com/intel/userspace-cni-network-plugin/cnivpp/api/infra"
42+
vppinterface "github.com/intel/userspace-cni-network-plugin/cnivpp/api/interface"
43+
vppmemif "github.com/intel/userspace-cni-network-plugin/cnivpp/api/memif"
4544
"github.com/intel/userspace-cni-network-plugin/cnivpp/bin_api/interface_types"
45+
"github.com/intel/userspace-cni-network-plugin/cnivpp/bin_api/memif"
4646
"github.com/intel/userspace-cni-network-plugin/logging"
4747
"github.com/intel/userspace-cni-network-plugin/pkg/configdata"
4848
"github.com/intel/userspace-cni-network-plugin/pkg/types"
@@ -231,8 +231,6 @@ func (cniVpp CniVpp) DelFromHost(conf *types.NetConf, args *skel.CmdArgs, shared
231231
} else {
232232
return fmt.Errorf("ERROR: Unknown HostConf.Type:" + conf.HostConf.IfType)
233233
}
234-
235-
return err
236234
}
237235

238236
func (cniVpp CniVpp) DelFromContainer(conf *types.NetConf, args *skel.CmdArgs, sharedDir string, pod *v1.Pod) error {

Diff for: cnivpp/localdb.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ import (
4040
"github.com/intel/userspace-cni-network-plugin/pkg/types"
4141
)
4242

43-
//
4443
// Constants
45-
//
4644
const debugVppDb = false
4745

4846
//
@@ -53,15 +51,16 @@ const debugVppDb = false
5351
// interfaces) that need to be preserved for later use.
5452
type VppSavedData struct {
5553
interfaceSwIfIndex interface_types.InterfaceIndex `json:"swIfIndex"` // Software Index, used to access the created interface, needed to delete interface.
56-
MemifSocketId uint32 `json:"memifSocketId"` // Memif SocketId, used to access the created memif Socket File, used for debug only.
54+
MemifSocketId uint32 `json:"memifSocketId"` // Memif SocketId, used to access the created memif Socket File, used for debug only.
5755
}
5856

5957
//
6058
// API Functions
6159
//
6260

6361
// saveVppConfig() - Some data needs to be saved, like the swIfIndex, for cmdDel().
64-
// This function squirrels the data away to be retrieved later.
62+
//
63+
// This function squirrels the data away to be retrieved later.
6564
func SaveVppConfig(conf *types.NetConf, args *skel.CmdArgs, data *VppSavedData) error {
6665

6766
// Current implementation is to write data to a file with the name:

0 commit comments

Comments
 (0)