Skip to content

Commit

Permalink
Merge pull request #70 from e0ne/go1.19
Browse files Browse the repository at this point in the history
Housekeeping: Bump golang to 1.19 and some cleanup
  • Loading branch information
moshe010 authored Feb 13, 2023
2 parents 848e3b4 + 2716501 commit b1794e7
Show file tree
Hide file tree
Showing 31 changed files with 82 additions and 313 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/buildtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ jobs:
build:
strategy:
matrix:
go-version: [1.13.x, 1.14.x, 1.15.x, 1.16.x]
os: [ubuntu-20.04]
go-version: [1.19.x]
os: [ubuntu-22.04]
runs-on: ${{ matrix.os }}
env:
GO111MODULE: on
Expand Down
35 changes: 0 additions & 35 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:alpine as builder
FROM golang:1.19-alpine as builder

COPY . /usr/src/ib-sriov-cni

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.ppc64le
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ppc64le/golang:alpine as builder
FROM ppc64le/golang:1.19-alpine as builder

COPY . /usr/src/ib-sriov-cni

Expand Down
17 changes: 0 additions & 17 deletions Dockerfile.rhel7

This file was deleted.

21 changes: 9 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Package related
BINARY_NAME=ib-sriov
PACKAGE=ib-sriov-cni
ORG_PATH=github.com/Mellanox
ORG_PATH=github.com/k8snetworkplumbingwg
REPO_PATH=$(ORG_PATH)/$(PACKAGE)
GOPATH=$(CURDIR)/.gopath
GOBIN =$(CURDIR)/bin
Expand All @@ -24,7 +24,7 @@ LDFLAGS="-X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(DATE
IMAGE_BUILDER?=@docker
IMAGEDIR=$(BASE)/images
DOCKERFILE?=$(CURDIR)/Dockerfile
TAG?=mellanox/ib-sriov-cni
TAG?=k8snetworkplumbingwg/ib-sriov-cni
IMAGE_BUILD_OPTS?=
# Accept proxy settings for docker
# To pass proxy for Docker invoke it as 'make image HTTP_POXY=http://192.168.0.1:8080'
Expand All @@ -43,7 +43,7 @@ GOLANGCI_LINT = $(GOBIN)/golangci-lint
# golangci-lint version should be updated periodically
# we keep it fixed to avoid it from unexpectedly failing on the project
# in case of a version bump
GOLANGCI_LINT_VER = v1.23.8
GOLANGCI_LINT_VER = v1.46.2
TIMEOUT = 15
Q = $(if $(filter 1,$V),,@)

Expand All @@ -67,22 +67,19 @@ $(BUILDDIR)/$(BINARY_NAME): $(GOFILES) | $(BUILDDIR)
@cd $(BASE)/cmd/$(PACKAGE) && CGO_ENABLED=0 $(GO) build -o $(BUILDDIR)/$(BINARY_NAME) -tags no_openssl -ldflags $(LDFLAGS) -v

# Tools
$(GOLANGCI_LINT): | $(BASE) ; $(info building golangci-lint...)
$Q curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) $(GOLANGCI_LINT_VER)
$(GOLANGCI_LINT): ; $(info installing golangci-lint...)
$Q go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VER)


GOVERALLS = $(GOBIN)/goveralls
$(GOBIN)/goveralls: | $(BASE) ; $(info building goveralls...)
$Q go get github.com/mattn/goveralls
$Q go install github.com/mattn/goveralls

# Tests

.PHONY: lint
lint: | $(BASE) $(GOLANGCI_LINT) ; $(info running golangci-lint...) @ ## Run golangci-lint
$Q mkdir -p $(BASE)/test
$Q cd $(BASE) && ret=0 && \
test -z "$$($(GOLANGCI_LINT) run | tee $(BASE)/test/lint.out)" || ret=1 ; \
cat $(BASE)/test/lint.out ; rm -rf $(BASE)/test ; \
exit $$ret
lint: | $(GOLANGCI_LINT) ; $(info running golangci-lint...) @ ## Run golangci-lint
$Q $(GOLANGCI_LINT) run --timeout=5m

TEST_TARGETS := test-default test-bench test-short test-verbose test-race
.PHONY: $(TEST_TARGETS) test-xml check test tests
Expand Down
5 changes: 3 additions & 2 deletions cmd/ib-sriov-cni/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func lockCNIExecution() (*flock.Flock, error) {
// As the mapping of RDMA resources is done in Device plugin prior to CNI invocation, it must not change here.
// We serialize the CNI's operation causing kernel to allocate the VF's RDMA resources under the same name.
// In the future, Systems should use udev PCI based RDMA device names, ensuring consistent RDMA resources names.
err := os.MkdirAll(config.CniFileLockDir, 0700)
err := os.MkdirAll(config.CniFileLockDir, utils.OwnerReadWriteExecuteAttrs)
if err != nil {
return nil, fmt.Errorf("failed to create ib-sriov-cni lock file directory(%q): %v", config.CniFileLockDir, err)
}
Expand Down Expand Up @@ -300,7 +300,8 @@ func cmdDel(args *skel.CmdArgs) error {
if err != nil {
// According to the CNI spec, a DEL action should complete without errors
// even if there are some resources missing. For more details, see
// https://github.com/containernetworking/cni/blob/main/SPEC.md#del-remove-container-from-network-or-un-apply-modifications
//nolint
// https://github.com/containernetworking/cni/blob/main/SPEC.md#del-remove-container-from-network-or-un-apply-modifications
return nil
}

Expand Down
23 changes: 19 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
module github.com/Mellanox/ib-sriov-cni

go 1.13
go 1.19

require (
github.com/Mellanox/rdma-cni v1.0.1
github.com/Mellanox/sriovnet v1.0.2
github.com/containernetworking/cni v0.8.1
github.com/containernetworking/plugins v0.8.5
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/gofrs/flock v0.7.1
github.com/onsi/ginkgo v1.12.0
github.com/onsi/gomega v1.9.0
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/stretchr/objx v0.2.1-0.20190415111823-35313a95ee26 // indirect
github.com/stretchr/testify v1.5.1
github.com/vishvananda/netlink v1.1.0
)

require (
github.com/Mellanox/rdmamap v1.0.0 // indirect
github.com/coreos/go-iptables v0.4.5 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/google/uuid v1.1.1 // indirect
github.com/hpcloud/tail v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/safchain/ethtool v0.0.0-20190326074333-42ed695e3de8 // indirect
github.com/spf13/afero v1.4.1 // indirect
github.com/stretchr/objx v0.2.1-0.20190415111823-35313a95ee26 // indirect
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df // indirect
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 // indirect
golang.org/x/sys v0.0.0-20200327173247-9dae0f8f5775 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 // indirect
gopkg.in/fsnotify.v1 v1.4.7 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
)
14 changes: 9 additions & 5 deletions pkg/utils/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
package utils

import (
"io/ioutil"
"os"
"path/filepath"
)

const (
OwnerReadWriteExecuteOthersReadExecuteAttrs = 0755
OwnerReadWriteOthersReadAttrs = 0644
)

func check(e error) {
if e != nil {
panic(e)
Expand Down Expand Up @@ -75,20 +79,20 @@ func CreateTmpSysFs() error {
originalRoot, _ := os.Open("/")
ts.originalRoot = originalRoot

tmpdir, ioErr := ioutil.TempDir("/tmp", "ib-sriov-cni-plugin-testfiles-")
tmpdir, ioErr := os.MkdirTemp("/tmp", "ib-sriov-cni-plugin-testfiles-")
if ioErr != nil {
return ioErr
}

ts.dirRoot = tmpdir

for _, dir := range ts.dirList {
if err := os.MkdirAll(filepath.Join(ts.dirRoot, dir), 0755); err != nil {
if err := os.MkdirAll(filepath.Join(ts.dirRoot, dir), OwnerReadWriteExecuteOthersReadExecuteAttrs); err != nil {
return err
}
}
for filename, body := range ts.fileList {
if err := ioutil.WriteFile(filepath.Join(ts.dirRoot, filename), body, 0644); err != nil {
if err := os.WriteFile(filepath.Join(ts.dirRoot, filename), body, OwnerReadWriteOthersReadAttrs); err != nil {
return err
}
}
Expand Down Expand Up @@ -117,7 +121,7 @@ func CreateTmpSysFs() error {
}

func createSymlinks(link, target string) error {
if err := os.MkdirAll(target, 0755); err != nil {
if err := os.MkdirAll(target, OwnerReadWriteExecuteOthersReadExecuteAttrs); err != nil {
return err
}
if err := os.Symlink(target, link); err != nil {
Expand Down
21 changes: 12 additions & 9 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package utils
import (
"encoding/json"
"fmt"
"io/ioutil"
"net"
"os"
"path/filepath"
Expand All @@ -20,7 +19,11 @@ var (
SysBusPci = "/sys/bus/pci/devices"
)

const IPoIBAddrLengthBytes = 20
const (
IPoIBAddrLengthBytes = 20
OwnerReadWriteExecuteAttrs = 0700
OwnerReadWriteAttrs = 0600
)

// GetSriovNumVfs takes in a PF name(ifName) as string and returns number of VF configured as int
func GetSriovNumVfs(ifName string) (int, error) {
Expand All @@ -31,7 +34,7 @@ func GetSriovNumVfs(ifName string) (int, error) {
return vfTotal, fmt.Errorf("failed to open the sriov_numfs of device %q: %v", ifName, err)
}

data, err := ioutil.ReadFile(sriovFile)
data, err := os.ReadFile(sriovFile)
if err != nil {
return vfTotal, fmt.Errorf("failed to read the sriov_numfs of device %q: %v", ifName, err)
}
Expand Down Expand Up @@ -82,7 +85,7 @@ func GetPfName(vf string) (string, error) {
return "", err
}

files, err := ioutil.ReadDir(pfSymLink)
files, err := os.ReadDir(pfSymLink)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -123,7 +126,7 @@ func GetVFLinkNames(pciAddr string) (string, error) {
return "", err
}

fInfos, err := ioutil.ReadDir(vfDir)
fInfos, err := os.ReadDir(vfDir)
if err != nil {
return "", fmt.Errorf("failed to read net dir of the device %s: %v", pciAddr, err)
}
Expand All @@ -147,7 +150,7 @@ func GetVFLinkNamesFromVFID(pfName string, vfID int) ([]string, error) {
return nil, err
}

fInfos, err := ioutil.ReadDir(vfDir)
fInfos, err := os.ReadDir(vfDir)
if err != nil {
return nil, fmt.Errorf("failed to read the virtfn%d dir of the device %q: %v", vfID, pfName, err)
}
Expand Down Expand Up @@ -181,13 +184,13 @@ func SaveNetConf(cid, dataDir, podIfName string, conf interface{}) error {
}

func saveScratchNetConf(containerID, dataDir string, netconf []byte) error {
if err := os.MkdirAll(dataDir, 0700); err != nil {
if err := os.MkdirAll(dataDir, OwnerReadWriteExecuteAttrs); err != nil {
return fmt.Errorf("failed to create the sriov data directory(%q): %v", dataDir, err)
}

path := filepath.Join(dataDir, containerID)

err := ioutil.WriteFile(path, netconf, 0600)
err := os.WriteFile(path, netconf, OwnerReadWriteAttrs)
if err != nil {
return fmt.Errorf("failed to write container data in the path(%q): %v", path, err)
}
Expand All @@ -197,7 +200,7 @@ func saveScratchNetConf(containerID, dataDir string, netconf []byte) error {

// ReadScratchNetConf takes in container ID, Pod interface name and data dir as string and returns a pointer to Conf
func ReadScratchNetConf(cRefPath string) ([]byte, error) {
data, err := ioutil.ReadFile(cRefPath)
data, err := os.ReadFile(cRefPath)
if err != nil {
return nil, fmt.Errorf("failed to read container data in the path(%q): %v", cRefPath, err)
}
Expand Down
10 changes: 0 additions & 10 deletions scripts/deploy.sh

This file was deleted.

8 changes: 0 additions & 8 deletions vendor/github.com/Mellanox/rdmamap/go.mod

This file was deleted.

6 changes: 0 additions & 6 deletions vendor/github.com/Mellanox/rdmamap/go.sum

This file was deleted.

10 changes: 0 additions & 10 deletions vendor/github.com/Mellanox/sriovnet/go.mod

This file was deleted.

35 changes: 0 additions & 35 deletions vendor/github.com/Mellanox/sriovnet/go.sum

This file was deleted.

1 change: 0 additions & 1 deletion vendor/github.com/google/uuid/go.mod

This file was deleted.

Loading

0 comments on commit b1794e7

Please sign in to comment.