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

Fix compile issues #85

Merged
merged 17 commits into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions .github/workflows/static-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,21 @@ jobs:
egress-policy: audit

- uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2.7.0
- name: remove deployer container from dockerfile
run: sed -ie '/End of builder/,+5d' ./docker/userspacecni/Dockerfile
- name: Build the Docker image
run: docker build . -f ./docker/userspacecni/Dockerfile -t userspacecni:latest
- name: run container
run: docker run --name userspacecni -itd userspacecni:latest bash
- name: docker copy generated bin api files
run: docker cp userspacecni:/root/userspace-cni-network-plugin/cnivpp ./

- name: golangci-lint
uses: golangci/golangci-lint-action@5c56cd6c9dc07901af25baab6f2b0d9f3b7c3018 # v2.5.2
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.52.2
args: --timeout=20m

shellcheck:
name: Shellcheck
Expand All @@ -30,6 +40,7 @@ jobs:
- uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2.7.0
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@00cae500b08a931fb5698e11e79bfbd38e612a38 # master

hadolint:
runs-on: ubuntu-latest
name: Hadolint
Expand All @@ -39,11 +50,12 @@ jobs:
with:
egress-policy: audit

- uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2.7.0
- uses: brpaz/hadolint-action@7e374b112fd3e7e6ea346131c40e17c7254f64bf # v1.2.1
- uses: actions/checkout@v3
- uses: hadolint/hadolint-action@v3.1.0
name: Run Hadolint
with:
dockerfile: Dockerfile
dockerfile: ./docker/userspacecni/Dockerfile
ignore: DL3008,DL3059

go-check:
runs-on: ubuntu-latest
Expand All @@ -55,15 +67,26 @@ jobs:

- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2

- name: remove deployer container from dockerfile
run: sed -ie '/End of builder/,+5d' ./docker/userspacecni/Dockerfile
- name: Build the Docker image
run: docker build . -f ./docker/userspacecni/Dockerfile -t userspacecni:latest
- name: run container
run: docker run --name userspacecni -itd userspacecni:latest bash
- name: docker copy generated bin api files
run: docker cp userspacecni:/root/userspace-cni-network-plugin/cnivpp ./

- name: Set up Go
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3.5.0
with:
go-version: 1.18.x
go-version: 1.20.1

- name: checkout dockerfile to avoid false diff
run: git checkout ./docker/userspacecni/Dockerfile
# if this fails, run go mod tidy
- name: Check if module files are consistent with code
run: go mod tidy && git diff --exit-code
run: go mod tidy && go get go.fd.io/govpp/binapigen/[email protected] && git diff --exit-code #need package for bin api but not working with tidy

# if this fails, run go mod vendor
- name: Check if vendor directory is consistent with go modules
run: go mod vendor && git diff --exit-code
run: go mod vendor && git diff --exit-code
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ endif
endif

install:
go get git.fd.io/govpp.git/cmd/[email protected]
go get go.fd.io/govpp/cmd/[email protected]
ifeq ($(VPPINSTALLED),0)
@echo VPP not installed, installing required files. Run *sudo make clean* to remove installed files.
@mkdir -p tmpvpp/
Expand Down
38 changes: 18 additions & 20 deletions cniovs/cniovs.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,24 @@ import (
"k8s.io/client-go/kubernetes"

"github.com/containernetworking/cni/pkg/skel"
"github.com/containernetworking/cni/pkg/types/current"
current "github.com/containernetworking/cni/pkg/types/100"

"github.com/intel/userspace-cni-network-plugin/logging"
"github.com/intel/userspace-cni-network-plugin/pkg/configdata"
"github.com/intel/userspace-cni-network-plugin/pkg/types"
)

//
// Constants
//
const (
defaultBridge = "br0"
DefaultHostVhostuserBaseDir = "/var/lib/vhost_sockets/"
)

//
// Types
//
type CniOvs struct {
}

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

configdata.FileCleanup(sharedDir, "")
var err = configdata.FileCleanup(sharedDir, "")

if err != nil {
logging.Debugf("DelFromContainer(ovs): %v", err)
}

return nil
}
Expand Down Expand Up @@ -243,15 +241,15 @@ func createSharedDir(sharedDir, oldSharedDir string) error {
if os.IsNotExist(err) {
err = os.MkdirAll(sharedDir, 0750)
if err != nil {
logging.Errorf("createSharedDir: Failed to create dir (%s): %v", sharedDir, err)
_ = logging.Errorf("createSharedDir: Failed to create dir (%s): %v", sharedDir, err)
return err
}

if strings.Contains(sharedDir, DefaultHostVhostuserBaseDir) {
logging.Debugf("createSharedDir: Mount from %s to %s", oldSharedDir, sharedDir)
err = unix.Mount(oldSharedDir, sharedDir, "", unix.MS_BIND, "")
if err != nil {
logging.Errorf("createSharedDir: Failed to bind mount: %s", err)
_ = logging.Errorf("createSharedDir: Failed to bind mount: %s", err)
return err
}
}
Expand Down Expand Up @@ -296,15 +294,15 @@ func addLocalDeviceVhost(conf *types.NetConf, args *skel.CmdArgs, actualSharedDi
sharedDir := getShortSharedDir(actualSharedDir)
err = createSharedDir(sharedDir, actualSharedDir)
if err != nil {
logging.Errorf("addLocalDeviceVhost: Failed to create shared dir: %v", err)
_ = logging.Errorf("addLocalDeviceVhost: Failed to create shared dir: %v", err)
return err
}

group := conf.HostConf.VhostConf.Group
if group != "" {
err = setSharedDirGroup(sharedDir, group)
if err != nil {
logging.Errorf("addLocalDeviceVhost: Failed to set shared dir group: %v", err)
_ = logging.Errorf("addLocalDeviceVhost: Failed to set shared dir group: %v", err)
return err
}
}
Expand Down Expand Up @@ -341,7 +339,7 @@ func delLocalDeviceVhost(conf *types.NetConf, args *skel.CmdArgs, actualSharedDi
// ovs-vsctl --if-exists del-port
err := deleteVhostPort(data.Vhostname, conf.HostConf.BridgeConf.BridgeName)
if err != nil {
logging.Errorf("delLocalDeviceVhost: Failed to delete port: %v", err)
_ = logging.Errorf("delLocalDeviceVhost: Failed to delete port: %v", err)
return err
}

Expand All @@ -350,17 +348,17 @@ func delLocalDeviceVhost(conf *types.NetConf, args *skel.CmdArgs, actualSharedDi
logging.Debugf("delLocalDeviceVhost: Unmount shared directory: %v", sharedDir)
_, err = os.Stat(sharedDir)
if os.IsNotExist(err) {
logging.Errorf("delLocalDeviceVhost: shared directory %s does not exist to unmount", sharedDir)
_ = logging.Errorf("delLocalDeviceVhost: shared directory %s does not exist to unmount", sharedDir)
return nil
}
err = unix.Unmount(sharedDir, 0)
if err != nil {
logging.Errorf("Failed to unmount dir: %v", err)
_ = logging.Errorf("Failed to unmount dir: %v", err)
return err
}
err = os.Remove(sharedDir)
if err != nil {
logging.Errorf("Failed to remove dir: %v", err)
_ = logging.Errorf("Failed to remove dir: %v", err)
return err
}
} else {
Expand All @@ -379,7 +377,7 @@ func delLocalDeviceVhost(conf *types.NetConf, args *skel.CmdArgs, actualSharedDi

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

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

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

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

if containInterfaces := doesBridgeContainInterfaces(conf.HostConf.BridgeConf.BridgeName); containInterfaces == false {
if containInterfaces := doesBridgeContainInterfaces(conf.HostConf.BridgeConf.BridgeName); !containInterfaces {
logging.Debugf("delLocalNetworkBridge(): No interfaces found, deleting Bridge %s", conf.HostConf.BridgeConf.BridgeName)
err = deleteBridge(conf.HostConf.BridgeConf.BridgeName)
} else {
Expand Down
Loading