ci(lint): setup golangci-lint
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
parent
86e39cfe3c
commit
d12b81dec5
3
.github/workflows/test.yaml
vendored
3
.github/workflows/test.yaml
vendored
@ -20,6 +20,9 @@ jobs:
|
|||||||
- uses: ibiqlik/action-yamllint@v3
|
- uses: ibiqlik/action-yamllint@v3
|
||||||
with:
|
with:
|
||||||
format: auto
|
format: auto
|
||||||
|
- uses: golangci/golangci-lint-action@v3
|
||||||
|
with:
|
||||||
|
args: -v
|
||||||
build:
|
build:
|
||||||
name: Build all linux architectures
|
name: Build all linux architectures
|
||||||
needs: lint
|
needs: lint
|
||||||
|
21
.golangci.yml
Normal file
21
.golangci.yml
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
linters:
|
||||||
|
enable:
|
||||||
|
- gci
|
||||||
|
- gofumpt
|
||||||
|
- misspell
|
||||||
|
disable:
|
||||||
|
- errcheck
|
||||||
|
- gosimple
|
||||||
|
- ineffassign
|
||||||
|
- staticcheck
|
||||||
|
|
||||||
|
linters-settings:
|
||||||
|
gci:
|
||||||
|
sections:
|
||||||
|
- standard
|
||||||
|
- default
|
||||||
|
- prefix(github.com/containernetworking)
|
||||||
|
|
||||||
|
run:
|
||||||
|
skip-dirs:
|
||||||
|
- vendor
|
@ -4,7 +4,7 @@
|
|||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
// You may obtain a copy of the License at
|
// You may obtain a copy of the License at
|
||||||
//
|
//
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
//
|
//
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
@ -14,15 +14,14 @@
|
|||||||
package integration_test
|
package integration_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"bytes"
|
|
||||||
"io"
|
|
||||||
"net"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -148,8 +147,8 @@ var _ = Describe("Basic PTP using cnitool", func() {
|
|||||||
basicBridgeEnv.runInNS(hostNS, cnitoolBin, "del", "network-chain-test", contNS2.LongName())
|
basicBridgeEnv.runInNS(hostNS, cnitoolBin, "del", "network-chain-test", contNS2.LongName())
|
||||||
})
|
})
|
||||||
|
|
||||||
Measure("limits traffic only on the restricted bandwith veth device", func(b Benchmarker) {
|
Measure("limits traffic only on the restricted bandwidth veth device", func(b Benchmarker) {
|
||||||
ipRegexp := regexp.MustCompile("10\\.1[12]\\.2\\.\\d{1,3}")
|
ipRegexp := regexp.MustCompile(`10\.1[12]\.2\.\d{1,3}`)
|
||||||
|
|
||||||
By(fmt.Sprintf("adding %s to %s\n\n", "chained-bridge-bandwidth", contNS1.ShortName()))
|
By(fmt.Sprintf("adding %s to %s\n\n", "chained-bridge-bandwidth", contNS1.ShortName()))
|
||||||
chainedBridgeBandwidthEnv.runInNS(hostNS, cnitoolBin, "add", "network-chain-test", contNS1.LongName())
|
chainedBridgeBandwidthEnv.runInNS(hostNS, cnitoolBin, "add", "network-chain-test", contNS1.LongName())
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
// You may obtain a copy of the License at
|
// You may obtain a copy of the License at
|
||||||
//
|
//
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
//
|
//
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
@ -15,10 +15,10 @@
|
|||||||
package ip_test
|
package ip_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIp(t *testing.T) {
|
func TestIp(t *testing.T) {
|
||||||
|
@ -205,7 +205,6 @@ var _ = Describe("IP Operations", func() {
|
|||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(ip).To(Equal(test.expected))
|
Expect(ip).To(Equal(test.expected))
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
It("empty text", func() {
|
It("empty text", func() {
|
||||||
|
@ -58,5 +58,5 @@ func echo1(f string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return os.WriteFile(f, []byte("1"), 0644)
|
return os.WriteFile(f, []byte("1"), 0o644)
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,6 @@ func TeardownIPMasq(ipn *net.IPNet, chain string, comment string) error {
|
|||||||
err = ipt.ClearChain("nat", chain)
|
err = ipt.ClearChain("nat", chain)
|
||||||
if err != nil && !isNotExist(err) {
|
if err != nil && !isNotExist(err) {
|
||||||
return err
|
return err
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ipt.DeleteChain("nat", chain)
|
err = ipt.DeleteChain("nat", chain)
|
||||||
|
@ -28,9 +28,7 @@ import (
|
|||||||
"github.com/containernetworking/plugins/pkg/utils/sysctl"
|
"github.com/containernetworking/plugins/pkg/utils/sysctl"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var ErrLinkNotFound = errors.New("link not found")
|
||||||
ErrLinkNotFound = errors.New("link not found")
|
|
||||||
)
|
|
||||||
|
|
||||||
// makeVethPair is called from within the container's network namespace
|
// makeVethPair is called from within the container's network namespace
|
||||||
func makeVethPair(name, peer string, mtu int, mac string, hostNS ns.NetNS) (netlink.Link, error) {
|
func makeVethPair(name, peer string, mtu int, mac string, hostNS ns.NetNS) (netlink.Link, error) {
|
||||||
|
@ -22,20 +22,13 @@ import (
|
|||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
"github.com/vishvananda/netlink"
|
||||||
|
|
||||||
"github.com/containernetworking/plugins/pkg/ip"
|
"github.com/containernetworking/plugins/pkg/ip"
|
||||||
"github.com/containernetworking/plugins/pkg/ns"
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
"github.com/containernetworking/plugins/pkg/testutils"
|
"github.com/containernetworking/plugins/pkg/testutils"
|
||||||
|
|
||||||
"github.com/vishvananda/netlink"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func getHwAddr(linkname string) string {
|
|
||||||
veth, err := netlink.LinkByName(linkname)
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
|
||||||
return fmt.Sprintf("%s", veth.Attrs().HardwareAddr)
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = Describe("Link", func() {
|
var _ = Describe("Link", func() {
|
||||||
const (
|
const (
|
||||||
ifaceFormatString string = "i%d"
|
ifaceFormatString string = "i%d"
|
||||||
@ -64,7 +57,7 @@ var _ = Describe("Link", func() {
|
|||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
fakeBytes := make([]byte, 20)
|
fakeBytes := make([]byte, 20)
|
||||||
//to be reset in AfterEach block
|
// to be reset in AfterEach block
|
||||||
rand.Reader = bytes.NewReader(fakeBytes)
|
rand.Reader = bytes.NewReader(fakeBytes)
|
||||||
|
|
||||||
_ = containerNetNS.Do(func(ns.NetNS) error {
|
_ = containerNetNS.Do(func(ns.NetNS) error {
|
||||||
@ -181,7 +174,7 @@ var _ = Describe("Link", func() {
|
|||||||
|
|
||||||
Context("when there is no name available for the host-side", func() {
|
Context("when there is no name available for the host-side", func() {
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
//adding different interface to container ns
|
// adding different interface to container ns
|
||||||
containerVethName += "0"
|
containerVethName += "0"
|
||||||
})
|
})
|
||||||
It("returns useful error", func() {
|
It("returns useful error", func() {
|
||||||
@ -197,7 +190,7 @@ var _ = Describe("Link", func() {
|
|||||||
|
|
||||||
Context("when there is no name conflict for the host or container interfaces", func() {
|
Context("when there is no name conflict for the host or container interfaces", func() {
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
//adding different interface to container and host ns
|
// adding different interface to container and host ns
|
||||||
containerVethName += "0"
|
containerVethName += "0"
|
||||||
rand.Reader = originalRandReader
|
rand.Reader = originalRandReader
|
||||||
})
|
})
|
||||||
@ -211,7 +204,7 @@ var _ = Describe("Link", func() {
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
//verify veths are in different namespaces
|
// verify veths are in different namespaces
|
||||||
_ = containerNetNS.Do(func(ns.NetNS) error {
|
_ = containerNetNS.Do(func(ns.NetNS) error {
|
||||||
defer GinkgoRecover()
|
defer GinkgoRecover()
|
||||||
|
|
||||||
|
@ -21,13 +21,13 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
|
"github.com/vishvananda/netlink"
|
||||||
|
|
||||||
"github.com/containernetworking/cni/pkg/types"
|
"github.com/containernetworking/cni/pkg/types"
|
||||||
current "github.com/containernetworking/cni/pkg/types/100"
|
current "github.com/containernetworking/cni/pkg/types/100"
|
||||||
"github.com/vishvananda/netlink"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func ValidateExpectedInterfaceIPs(ifName string, resultIPs []*current.IPConfig) error {
|
func ValidateExpectedInterfaceIPs(ifName string, resultIPs []*current.IPConfig) error {
|
||||||
|
|
||||||
// Ensure ips
|
// Ensure ips
|
||||||
for _, ips := range resultIPs {
|
for _, ips := range resultIPs {
|
||||||
ourAddr := netlink.Addr{IPNet: &ips.Address}
|
ourAddr := netlink.Addr{IPNet: &ips.Address}
|
||||||
@ -49,12 +49,15 @@ func ValidateExpectedInterfaceIPs(ifName string, resultIPs []*current.IPConfig)
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if match == false {
|
if !match {
|
||||||
return fmt.Errorf("Failed to match addr %v on interface %v", ourAddr, ifName)
|
return fmt.Errorf("Failed to match addr %v on interface %v", ourAddr, ifName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert the host/prefixlen to just prefix for route lookup.
|
// Convert the host/prefixlen to just prefix for route lookup.
|
||||||
_, ourPrefix, err := net.ParseCIDR(ourAddr.String())
|
_, ourPrefix, err := net.ParseCIDR(ourAddr.String())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
findGwy := &netlink.Route{Dst: ourPrefix}
|
findGwy := &netlink.Route{Dst: ourPrefix}
|
||||||
routeFilter := netlink.RT_FILTER_DST
|
routeFilter := netlink.RT_FILTER_DST
|
||||||
@ -77,7 +80,6 @@ func ValidateExpectedInterfaceIPs(ifName string, resultIPs []*current.IPConfig)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ValidateExpectedRoute(resultRoutes []*types.Route) error {
|
func ValidateExpectedRoute(resultRoutes []*types.Route) error {
|
||||||
|
|
||||||
// Ensure that each static route in prevResults is found in the routing table
|
// Ensure that each static route in prevResults is found in the routing table
|
||||||
for _, route := range resultRoutes {
|
for _, route := range resultRoutes {
|
||||||
find := &netlink.Route{Dst: &route.Dst, Gw: route.GW}
|
find := &netlink.Route{Dst: &route.Dst, Gw: route.GW}
|
||||||
|
@ -16,6 +16,7 @@ package ipam
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/containernetworking/cni/pkg/invoke"
|
"github.com/containernetworking/cni/pkg/invoke"
|
||||||
"github.com/containernetworking/cni/pkg/types"
|
"github.com/containernetworking/cni/pkg/types"
|
||||||
)
|
)
|
||||||
|
@ -19,11 +19,11 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/vishvananda/netlink"
|
||||||
|
|
||||||
current "github.com/containernetworking/cni/pkg/types/100"
|
current "github.com/containernetworking/cni/pkg/types/100"
|
||||||
"github.com/containernetworking/plugins/pkg/ip"
|
"github.com/containernetworking/plugins/pkg/ip"
|
||||||
"github.com/containernetworking/plugins/pkg/utils/sysctl"
|
"github.com/containernetworking/plugins/pkg/utils/sysctl"
|
||||||
|
|
||||||
"github.com/vishvananda/netlink"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -18,15 +18,14 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
. "github.com/onsi/ginkgo/v2"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
"github.com/vishvananda/netlink"
|
||||||
|
|
||||||
"github.com/containernetworking/cni/pkg/types"
|
"github.com/containernetworking/cni/pkg/types"
|
||||||
current "github.com/containernetworking/cni/pkg/types/100"
|
current "github.com/containernetworking/cni/pkg/types/100"
|
||||||
"github.com/containernetworking/plugins/pkg/ns"
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
"github.com/containernetworking/plugins/pkg/testutils"
|
"github.com/containernetworking/plugins/pkg/testutils"
|
||||||
|
|
||||||
"github.com/vishvananda/netlink"
|
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
|
||||||
. "github.com/onsi/gomega"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const LINK_NAME = "eth0"
|
const LINK_NAME = "eth0"
|
||||||
|
@ -15,10 +15,10 @@
|
|||||||
package ipam_test
|
package ipam_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIpam(t *testing.T) {
|
func TestIpam(t *testing.T) {
|
||||||
|
@ -16,8 +16,8 @@ package link_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/networkplumbing/go-nft/nft"
|
|
||||||
|
|
||||||
|
"github.com/networkplumbing/go-nft/nft"
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
|
@ -21,11 +21,12 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/containernetworking/plugins/pkg/ns"
|
|
||||||
"github.com/containernetworking/plugins/pkg/testutils"
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
|
|
||||||
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
|
"github.com/containernetworking/plugins/pkg/testutils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getInodeCurNetNS() (uint64, error) {
|
func getInodeCurNetNS() (uint64, error) {
|
||||||
|
@ -17,11 +17,10 @@ package ns_test
|
|||||||
import (
|
import (
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"testing"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNs(t *testing.T) {
|
func TestNs(t *testing.T) {
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package main_test
|
package main_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestEchosvr(t *testing.T) {
|
func TestEchosvr(t *testing.T) {
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
// Echosvr is a simple TCP echo server
|
// Echosvr is a simple TCP echo server
|
||||||
//
|
//
|
||||||
// It prints its listen address on stdout
|
// It prints its listen address on stdout
|
||||||
// 127.0.0.1:xxxxx
|
//
|
||||||
// A test should wait for this line, parse it
|
// 127.0.0.1:xxxxx
|
||||||
// and may then attempt to connect.
|
// A test should wait for this line, parse it
|
||||||
|
// and may then attempt to connect.
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -58,7 +59,7 @@ func main() {
|
|||||||
log.Fatalf("Error from ReadFrom(): %s", err)
|
log.Fatalf("Error from ReadFrom(): %s", err)
|
||||||
}
|
}
|
||||||
sock.SetWriteDeadline(time.Now().Add(1 * time.Minute))
|
sock.SetWriteDeadline(time.Now().Add(1 * time.Minute))
|
||||||
n, err = sock.WriteTo(buffer[0:n], addr)
|
_, err = sock.WriteTo(buffer[0:n], addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,9 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/containernetworking/plugins/pkg/ns"
|
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
|
|
||||||
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getNsRunDir() string {
|
func getNsRunDir() string {
|
||||||
@ -49,7 +50,6 @@ func getNsRunDir() string {
|
|||||||
// Creates a new persistent (bind-mounted) network namespace and returns an object
|
// Creates a new persistent (bind-mounted) network namespace and returns an object
|
||||||
// representing that namespace, without switching to it.
|
// representing that namespace, without switching to it.
|
||||||
func NewNS() (ns.NetNS, error) {
|
func NewNS() (ns.NetNS, error) {
|
||||||
|
|
||||||
nsRunDir := getNsRunDir()
|
nsRunDir := getNsRunDir()
|
||||||
|
|
||||||
b := make([]byte, 16)
|
b := make([]byte, 16)
|
||||||
@ -61,7 +61,7 @@ func NewNS() (ns.NetNS, error) {
|
|||||||
// Create the directory for mounting network namespaces
|
// Create the directory for mounting network namespaces
|
||||||
// This needs to be a shared mountpoint in case it is mounted in to
|
// This needs to be a shared mountpoint in case it is mounted in to
|
||||||
// other namespaces (containers)
|
// other namespaces (containers)
|
||||||
err = os.MkdirAll(nsRunDir, 0755)
|
err = os.MkdirAll(nsRunDir, 0o755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,12 @@ import (
|
|||||||
"math/rand"
|
"math/rand"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"github.com/containernetworking/plugins/pkg/ns"
|
|
||||||
"github.com/containernetworking/plugins/pkg/testutils"
|
|
||||||
"github.com/coreos/go-iptables/iptables"
|
"github.com/coreos/go-iptables/iptables"
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
|
"github.com/containernetworking/plugins/pkg/testutils"
|
||||||
)
|
)
|
||||||
|
|
||||||
const TABLE = "filter" // We'll monkey around here
|
const TABLE = "filter" // We'll monkey around here
|
||||||
@ -34,7 +35,6 @@ var _ = Describe("chain tests", func() {
|
|||||||
var cleanup func()
|
var cleanup func()
|
||||||
|
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
|
|
||||||
// Save a reference to the original namespace,
|
// Save a reference to the original namespace,
|
||||||
// Add a new NS
|
// Add a new NS
|
||||||
currNs, err := ns.GetCurrentNS()
|
currNs, err := ns.GetCurrentNS()
|
||||||
@ -60,7 +60,6 @@ var _ = Describe("chain tests", func() {
|
|||||||
ipt.DeleteChain(TABLE, testChain)
|
ipt.DeleteChain(TABLE, testChain)
|
||||||
currNs.Set()
|
currNs.Set()
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
AfterEach(func() {
|
AfterEach(func() {
|
||||||
@ -93,5 +92,4 @@ var _ = Describe("chain tests", func() {
|
|||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
@ -46,7 +46,7 @@ func getSysctl(name string) (string, error) {
|
|||||||
|
|
||||||
func setSysctl(name, value string) (string, error) {
|
func setSysctl(name, value string) (string, error) {
|
||||||
fullName := filepath.Join("/proc/sys", toNormalName(name))
|
fullName := filepath.Join("/proc/sys", toNormalName(name))
|
||||||
if err := os.WriteFile(fullName, []byte(value), 0644); err != nil {
|
if err := os.WriteFile(fullName, []byte(value), 0o644); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,12 +20,13 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/containernetworking/plugins/pkg/ns"
|
|
||||||
"github.com/containernetworking/plugins/pkg/testutils"
|
|
||||||
"github.com/containernetworking/plugins/pkg/utils/sysctl"
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
"github.com/vishvananda/netlink"
|
"github.com/vishvananda/netlink"
|
||||||
|
|
||||||
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
|
"github.com/containernetworking/plugins/pkg/testutils"
|
||||||
|
"github.com/containernetworking/plugins/pkg/utils/sysctl"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -38,7 +39,6 @@ var _ = Describe("Sysctl tests", func() {
|
|||||||
var cleanup func()
|
var cleanup func()
|
||||||
|
|
||||||
beforeEach := func() {
|
beforeEach := func() {
|
||||||
|
|
||||||
// Save a reference to the original namespace,
|
// Save a reference to the original namespace,
|
||||||
// Add a new NS
|
// Add a new NS
|
||||||
currNs, err := ns.GetCurrentNS()
|
currNs, err := ns.GetCurrentNS()
|
||||||
@ -66,7 +66,6 @@ var _ = Describe("Sysctl tests", func() {
|
|||||||
netlink.LinkDel(testIface)
|
netlink.LinkDel(testIface)
|
||||||
currNs.Set()
|
currNs.Set()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AfterEach(func() {
|
AfterEach(func() {
|
||||||
@ -114,5 +113,4 @@ var _ = Describe("Sysctl tests", func() {
|
|||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
@ -15,10 +15,10 @@
|
|||||||
package utils_test
|
package utils_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestUtils(t *testing.T) {
|
func TestUtils(t *testing.T) {
|
||||||
|
@ -161,5 +161,4 @@ var _ = Describe("Utils", func() {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
@ -23,7 +23,7 @@ const (
|
|||||||
MaxDHCPLen = 576
|
MaxDHCPLen = 576
|
||||||
)
|
)
|
||||||
|
|
||||||
//Send the Discovery Packet to the Broadcast Channel
|
// Send the Discovery Packet to the Broadcast Channel
|
||||||
func DhcpSendDiscoverPacket(c *dhcp4client.Client, options dhcp4.Options) (dhcp4.Packet, error) {
|
func DhcpSendDiscoverPacket(c *dhcp4client.Client, options dhcp4.Options) (dhcp4.Packet, error) {
|
||||||
discoveryPacket := c.DiscoverPacket()
|
discoveryPacket := c.DiscoverPacket()
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ func DhcpSendDiscoverPacket(c *dhcp4client.Client, options dhcp4.Options) (dhcp4
|
|||||||
return discoveryPacket, c.SendPacket(discoveryPacket)
|
return discoveryPacket, c.SendPacket(discoveryPacket)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Send Request Based On the offer Received.
|
// Send Request Based On the offer Received.
|
||||||
func DhcpSendRequest(c *dhcp4client.Client, options dhcp4.Options, offerPacket *dhcp4.Packet) (dhcp4.Packet, error) {
|
func DhcpSendRequest(c *dhcp4client.Client, options dhcp4.Options, offerPacket *dhcp4.Packet) (dhcp4.Packet, error) {
|
||||||
requestPacket := c.RequestPacket(offerPacket)
|
requestPacket := c.RequestPacket(offerPacket)
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ func DhcpSendRequest(c *dhcp4client.Client, options dhcp4.Options, offerPacket *
|
|||||||
return requestPacket, c.SendPacket(requestPacket)
|
return requestPacket, c.SendPacket(requestPacket)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Send Decline to the received acknowledgement.
|
// Send Decline to the received acknowledgement.
|
||||||
func DhcpSendDecline(c *dhcp4client.Client, acknowledgementPacket *dhcp4.Packet, options dhcp4.Options) (dhcp4.Packet, error) {
|
func DhcpSendDecline(c *dhcp4client.Client, acknowledgementPacket *dhcp4.Packet, options dhcp4.Options) (dhcp4.Packet, error) {
|
||||||
declinePacket := c.DeclinePacket(acknowledgementPacket)
|
declinePacket := c.DeclinePacket(acknowledgementPacket)
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ func DhcpSendDecline(c *dhcp4client.Client, acknowledgementPacket *dhcp4.Packet,
|
|||||||
return declinePacket, c.SendPacket(declinePacket)
|
return declinePacket, c.SendPacket(declinePacket)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Lets do a Full DHCP Request.
|
// Lets do a Full DHCP Request.
|
||||||
func DhcpRequest(c *dhcp4client.Client, options dhcp4.Options) (bool, dhcp4.Packet, error) {
|
func DhcpRequest(c *dhcp4client.Client, options dhcp4.Options) (bool, dhcp4.Packet, error) {
|
||||||
discoveryPacket, err := DhcpSendDiscoverPacket(c, options)
|
discoveryPacket, err := DhcpSendDiscoverPacket(c, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -91,8 +91,8 @@ func DhcpRequest(c *dhcp4client.Client, options dhcp4.Options) (bool, dhcp4.Pack
|
|||||||
return true, acknowledgement, nil
|
return true, acknowledgement, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//Renew a lease backed on the Acknowledgement Packet.
|
// Renew a lease backed on the Acknowledgement Packet.
|
||||||
//Returns Successful, The AcknoledgementPacket, Any Errors
|
// Returns Successful, The AcknoledgementPacket, Any Errors
|
||||||
func DhcpRenew(c *dhcp4client.Client, acknowledgement dhcp4.Packet, options dhcp4.Options) (bool, dhcp4.Packet, error) {
|
func DhcpRenew(c *dhcp4client.Client, acknowledgement dhcp4.Packet, options dhcp4.Options) (bool, dhcp4.Packet, error) {
|
||||||
renewRequest := c.RenewalRequestPacket(&acknowledgement)
|
renewRequest := c.RenewalRequestPacket(&acknowledgement)
|
||||||
|
|
||||||
@ -120,8 +120,8 @@ func DhcpRenew(c *dhcp4client.Client, acknowledgement dhcp4.Packet, options dhcp
|
|||||||
return true, newAcknowledgement, nil
|
return true, newAcknowledgement, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//Release a lease backed on the Acknowledgement Packet.
|
// Release a lease backed on the Acknowledgement Packet.
|
||||||
//Returns Any Errors
|
// Returns Any Errors
|
||||||
func DhcpRelease(c *dhcp4client.Client, acknowledgement dhcp4.Packet, options dhcp4.Options) error {
|
func DhcpRelease(c *dhcp4client.Client, acknowledgement dhcp4.Packet, options dhcp4.Options) error {
|
||||||
release := c.ReleasePacket(&acknowledgement)
|
release := c.ReleasePacket(&acknowledgement)
|
||||||
|
|
||||||
|
@ -30,9 +30,10 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/coreos/go-systemd/v22/activation"
|
||||||
|
|
||||||
"github.com/containernetworking/cni/pkg/skel"
|
"github.com/containernetworking/cni/pkg/skel"
|
||||||
current "github.com/containernetworking/cni/pkg/types/100"
|
current "github.com/containernetworking/cni/pkg/types/100"
|
||||||
"github.com/coreos/go-systemd/v22/activation"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var errNoMoreTries = errors.New("no more tries")
|
var errNoMoreTries = errors.New("no more tries")
|
||||||
@ -55,7 +56,7 @@ func newDHCP(clientTimeout, clientResendMax time.Duration) *DHCP {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: current client ID is too long. At least the container ID should not be used directly.
|
// TODO: current client ID is too long. At least the container ID should not be used directly.
|
||||||
// A seperate issue is necessary to ensure no breaking change is affecting other users.
|
// A separate issue is necessary to ensure no breaking change is affecting other users.
|
||||||
func generateClientID(containerID string, netName string, ifName string) string {
|
func generateClientID(containerID string, netName string, ifName string) string {
|
||||||
clientID := containerID + "/" + netName + "/" + ifName
|
clientID := containerID + "/" + netName + "/" + ifName
|
||||||
// defined in RFC 2132, length size can not be larger than 1 octet. So we truncate 254 to make everyone happy.
|
// defined in RFC 2132, length size can not be larger than 1 octet. So we truncate 254 to make everyone happy.
|
||||||
@ -166,7 +167,7 @@ func getListener(socketPath string) (net.Listener, error) {
|
|||||||
|
|
||||||
switch {
|
switch {
|
||||||
case len(l) == 0:
|
case len(l) == 0:
|
||||||
if err := os.MkdirAll(filepath.Dir(socketPath), 0700); err != nil {
|
if err := os.MkdirAll(filepath.Dir(socketPath), 0o700); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return net.Listen("unix", socketPath)
|
return net.Listen("unix", socketPath)
|
||||||
@ -195,7 +196,7 @@ func runDaemon(
|
|||||||
if !filepath.IsAbs(pidfilePath) {
|
if !filepath.IsAbs(pidfilePath) {
|
||||||
return fmt.Errorf("Error writing pidfile %q: path not absolute", pidfilePath)
|
return fmt.Errorf("Error writing pidfile %q: path not absolute", pidfilePath)
|
||||||
}
|
}
|
||||||
if err := os.WriteFile(pidfilePath, []byte(fmt.Sprintf("%d", os.Getpid())), 0644); err != nil {
|
if err := os.WriteFile(pidfilePath, []byte(fmt.Sprintf("%d", os.Getpid())), 0o644); err != nil {
|
||||||
return fmt.Errorf("Error writing pidfile %q: %v", pidfilePath, err)
|
return fmt.Errorf("Error writing pidfile %q: %v", pidfilePath, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,15 +22,14 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
. "github.com/onsi/ginkgo/v2"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
"github.com/vishvananda/netlink"
|
||||||
|
|
||||||
"github.com/containernetworking/cni/pkg/skel"
|
"github.com/containernetworking/cni/pkg/skel"
|
||||||
current "github.com/containernetworking/cni/pkg/types/100"
|
current "github.com/containernetworking/cni/pkg/types/100"
|
||||||
"github.com/containernetworking/plugins/pkg/ns"
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
"github.com/containernetworking/plugins/pkg/testutils"
|
"github.com/containernetworking/plugins/pkg/testutils"
|
||||||
|
|
||||||
"github.com/vishvananda/netlink"
|
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
|
||||||
. "github.com/onsi/gomega"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = Describe("DHCP Multiple Lease Operations", func() {
|
var _ = Describe("DHCP Multiple Lease Operations", func() {
|
||||||
|
@ -15,10 +15,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDHCP(t *testing.T) {
|
func TestDHCP(t *testing.T) {
|
||||||
|
@ -25,20 +25,18 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containernetworking/cni/pkg/skel"
|
|
||||||
types100 "github.com/containernetworking/cni/pkg/types/100"
|
|
||||||
"github.com/containernetworking/plugins/pkg/ns"
|
|
||||||
"github.com/containernetworking/plugins/pkg/testutils"
|
|
||||||
|
|
||||||
"github.com/vishvananda/netlink"
|
|
||||||
|
|
||||||
"github.com/d2g/dhcp4"
|
"github.com/d2g/dhcp4"
|
||||||
"github.com/d2g/dhcp4server"
|
"github.com/d2g/dhcp4server"
|
||||||
"github.com/d2g/dhcp4server/leasepool"
|
"github.com/d2g/dhcp4server/leasepool"
|
||||||
"github.com/d2g/dhcp4server/leasepool/memorypool"
|
"github.com/d2g/dhcp4server/leasepool/memorypool"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
"github.com/vishvananda/netlink"
|
||||||
|
|
||||||
|
"github.com/containernetworking/cni/pkg/skel"
|
||||||
|
types100 "github.com/containernetworking/cni/pkg/types/100"
|
||||||
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
|
"github.com/containernetworking/plugins/pkg/testutils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getTmpDir() (string, error) {
|
func getTmpDir() (string, error) {
|
||||||
@ -120,7 +118,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var _ = BeforeSuite(func() {
|
var _ = BeforeSuite(func() {
|
||||||
err := os.MkdirAll(cniDirPrefix, 0700)
|
err := os.MkdirAll(cniDirPrefix, 0o700)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -34,13 +34,17 @@ import (
|
|||||||
|
|
||||||
// RFC 2131 suggests using exponential backoff, starting with 4sec
|
// RFC 2131 suggests using exponential backoff, starting with 4sec
|
||||||
// and randomized to +/- 1sec
|
// and randomized to +/- 1sec
|
||||||
const resendDelay0 = 4 * time.Second
|
const (
|
||||||
const resendDelayMax = 62 * time.Second
|
resendDelay0 = 4 * time.Second
|
||||||
|
resendDelayMax = 62 * time.Second
|
||||||
|
)
|
||||||
|
|
||||||
// To speed up the retry for first few failures, we retry without
|
// To speed up the retry for first few failures, we retry without
|
||||||
// backoff for a few times
|
// backoff for a few times
|
||||||
const resendFastDelay = 2 * time.Second
|
const (
|
||||||
const resendFastMax = 4
|
resendFastDelay = 2 * time.Second
|
||||||
|
resendFastMax = 4
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
leaseStateBound = iota
|
leaseStateBound = iota
|
||||||
@ -80,8 +84,8 @@ var requestOptionsDefault = map[dhcp4.OptionCode]bool{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func prepareOptions(cniArgs string, ProvideOptions []ProvideOption, RequestOptions []RequestOption) (
|
func prepareOptions(cniArgs string, ProvideOptions []ProvideOption, RequestOptions []RequestOption) (
|
||||||
optsRequesting map[dhcp4.OptionCode]bool, optsProviding map[dhcp4.OptionCode][]byte, err error) {
|
optsRequesting map[dhcp4.OptionCode]bool, optsProviding map[dhcp4.OptionCode][]byte, err error,
|
||||||
|
) {
|
||||||
// parse CNI args
|
// parse CNI args
|
||||||
cniArgsParsed := map[string]string{}
|
cniArgsParsed := map[string]string{}
|
||||||
for _, argPair := range strings.Split(cniArgs, ";") {
|
for _, argPair := range strings.Split(cniArgs, ";") {
|
||||||
@ -450,7 +454,7 @@ func jitter(span time.Duration) time.Duration {
|
|||||||
func backoffRetry(resendMax time.Duration, f func() (*dhcp4.Packet, error)) (*dhcp4.Packet, error) {
|
func backoffRetry(resendMax time.Duration, f func() (*dhcp4.Packet, error)) (*dhcp4.Packet, error) {
|
||||||
var baseDelay time.Duration = resendDelay0
|
var baseDelay time.Duration = resendDelay0
|
||||||
var sleepTime time.Duration
|
var sleepTime time.Duration
|
||||||
var fastRetryLimit = resendFastMax
|
fastRetryLimit := resendFastMax
|
||||||
for {
|
for {
|
||||||
pkt, err := f()
|
pkt, err := f()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -127,7 +127,7 @@ func cmdDel(args *skel.CmdArgs) error {
|
|||||||
func cmdCheck(args *skel.CmdArgs) error {
|
func cmdCheck(args *skel.CmdArgs) error {
|
||||||
// Plugin must return result in same version as specified in netconf
|
// Plugin must return result in same version as specified in netconf
|
||||||
versionDecoder := &version.ConfigDecoder{}
|
versionDecoder := &version.ConfigDecoder{}
|
||||||
//confVersion, err := versionDecoder.Decode(args.StdinData)
|
// confVersion, err := versionDecoder.Decode(args.StdinData)
|
||||||
_, err := versionDecoder.Decode(args.StdinData)
|
_, err := versionDecoder.Decode(args.StdinData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -21,8 +21,9 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containernetworking/cni/pkg/types"
|
|
||||||
"github.com/d2g/dhcp4"
|
"github.com/d2g/dhcp4"
|
||||||
|
|
||||||
|
"github.com/containernetworking/cni/pkg/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
var optionNameToID = map[string]dhcp4.OptionCode{
|
var optionNameToID = map[string]dhcp4.OptionCode{
|
||||||
|
@ -19,8 +19,9 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/containernetworking/cni/pkg/types"
|
|
||||||
"github.com/d2g/dhcp4"
|
"github.com/d2g/dhcp4"
|
||||||
|
|
||||||
|
"github.com/containernetworking/cni/pkg/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func validateRoutes(t *testing.T, routes []*types.Route) {
|
func validateRoutes(t *testing.T, routes []*types.Route) {
|
||||||
|
@ -22,7 +22,6 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
current "github.com/containernetworking/cni/pkg/types/100"
|
current "github.com/containernetworking/cni/pkg/types/100"
|
||||||
|
|
||||||
"github.com/containernetworking/plugins/pkg/ip"
|
"github.com/containernetworking/plugins/pkg/ip"
|
||||||
"github.com/containernetworking/plugins/plugins/ipam/host-local/backend"
|
"github.com/containernetworking/plugins/plugins/ipam/host-local/backend"
|
||||||
)
|
)
|
||||||
|
@ -15,10 +15,10 @@
|
|||||||
package allocator_test
|
package allocator_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAllocator(t *testing.T) {
|
func TestAllocator(t *testing.T) {
|
||||||
|
@ -18,12 +18,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
|
. "github.com/onsi/ginkgo/v2"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
"github.com/containernetworking/cni/pkg/types"
|
"github.com/containernetworking/cni/pkg/types"
|
||||||
current "github.com/containernetworking/cni/pkg/types/100"
|
current "github.com/containernetworking/cni/pkg/types/100"
|
||||||
fakestore "github.com/containernetworking/plugins/plugins/ipam/host-local/backend/testing"
|
fakestore "github.com/containernetworking/plugins/plugins/ipam/host-local/backend/testing"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
|
||||||
. "github.com/onsi/gomega"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type AllocatorTestCase struct {
|
type AllocatorTestCase struct {
|
||||||
@ -262,7 +262,6 @@ var _ = Describe("host-local ip allocator", func() {
|
|||||||
res, err = alloc.Get("ID", "eth0", nil)
|
res, err = alloc.Get("ID", "eth0", nil)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(res.Address.String()).To(Equal("192.168.1.3/29"))
|
Expect(res.Address.String()).To(Equal("192.168.1.3/29"))
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
Context("when requesting a specific IP", func() {
|
Context("when requesting a specific IP", func() {
|
||||||
@ -301,7 +300,6 @@ var _ = Describe("host-local ip allocator", func() {
|
|||||||
Expect(err).To(HaveOccurred())
|
Expect(err).To(HaveOccurred())
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
Context("when out of ips", func() {
|
Context("when out of ips", func() {
|
||||||
It("returns a meaningful error", func() {
|
It("returns a meaningful error", func() {
|
||||||
|
@ -21,7 +21,6 @@ import (
|
|||||||
|
|
||||||
"github.com/containernetworking/cni/pkg/types"
|
"github.com/containernetworking/cni/pkg/types"
|
||||||
"github.com/containernetworking/cni/pkg/version"
|
"github.com/containernetworking/cni/pkg/version"
|
||||||
|
|
||||||
"github.com/containernetworking/plugins/pkg/ip"
|
"github.com/containernetworking/plugins/pkg/ip"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -43,7 +42,7 @@ type Net struct {
|
|||||||
|
|
||||||
// IPAMConfig represents the IP related network configuration.
|
// IPAMConfig represents the IP related network configuration.
|
||||||
// This nests Range because we initially only supported a single
|
// This nests Range because we initially only supported a single
|
||||||
// range directly, and wish to preserve backwards compatability
|
// range directly, and wish to preserve backwards compatibility
|
||||||
type IPAMConfig struct {
|
type IPAMConfig struct {
|
||||||
*Range
|
*Range
|
||||||
Name string
|
Name string
|
||||||
|
@ -17,9 +17,10 @@ package allocator
|
|||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
"github.com/containernetworking/cni/pkg/types"
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
|
"github.com/containernetworking/cni/pkg/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = Describe("IPAM config", func() {
|
var _ = Describe("IPAM config", func() {
|
||||||
@ -415,7 +416,6 @@ var _ = Describe("IPAM config", func() {
|
|||||||
}`
|
}`
|
||||||
_, _, err := LoadIPAMConfig([]byte(input), "")
|
_, _, err := LoadIPAMConfig([]byte(input), "")
|
||||||
Expect(err).To(MatchError("invalid range set 0: mixed address families"))
|
Expect(err).To(MatchError("invalid range set 0: mixed address families"))
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
It("Should should error on too many ranges", func() {
|
It("Should should error on too many ranges", func() {
|
||||||
|
@ -125,7 +125,7 @@ func (r *Range) Contains(addr net.IP) bool {
|
|||||||
|
|
||||||
// Overlaps returns true if there is any overlap between ranges
|
// Overlaps returns true if there is any overlap between ranges
|
||||||
func (r *Range) Overlaps(r1 *Range) bool {
|
func (r *Range) Overlaps(r1 *Range) bool {
|
||||||
// different familes
|
// different families
|
||||||
if len(r.RangeStart) != len(r1.RangeStart) {
|
if len(r.RangeStart) != len(r1.RangeStart) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,6 @@ var _ = Describe("range sets", func() {
|
|||||||
r, err = p.RangeFor(net.IP{192, 168, 99, 99})
|
r, err = p.RangeFor(net.IP{192, 168, 99, 99})
|
||||||
Expect(r).To(BeNil())
|
Expect(r).To(BeNil())
|
||||||
Expect(err).To(MatchError("192.168.99.99 not in range set 192.168.0.1-192.168.0.254,172.16.1.1-172.16.1.254"))
|
Expect(err).To(MatchError("192.168.99.99 not in range set 192.168.0.1-192.168.0.254,172.16.1.1-172.16.1.254"))
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
It("should discover overlaps within a set", func() {
|
It("should discover overlaps within a set", func() {
|
||||||
|
@ -17,10 +17,10 @@ package allocator
|
|||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
"github.com/containernetworking/cni/pkg/types"
|
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
|
"github.com/containernetworking/cni/pkg/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = Describe("IP ranges", func() {
|
var _ = Describe("IP ranges", func() {
|
||||||
|
@ -24,8 +24,10 @@ import (
|
|||||||
"github.com/containernetworking/plugins/plugins/ipam/host-local/backend"
|
"github.com/containernetworking/plugins/plugins/ipam/host-local/backend"
|
||||||
)
|
)
|
||||||
|
|
||||||
const lastIPFilePrefix = "last_reserved_ip."
|
const (
|
||||||
const LineBreak = "\r\n"
|
lastIPFilePrefix = "last_reserved_ip."
|
||||||
|
LineBreak = "\r\n"
|
||||||
|
)
|
||||||
|
|
||||||
var defaultDataDir = "/var/lib/cni/networks"
|
var defaultDataDir = "/var/lib/cni/networks"
|
||||||
|
|
||||||
@ -44,7 +46,7 @@ func New(network, dataDir string) (*Store, error) {
|
|||||||
dataDir = defaultDataDir
|
dataDir = defaultDataDir
|
||||||
}
|
}
|
||||||
dir := filepath.Join(dataDir, network)
|
dir := filepath.Join(dataDir, network)
|
||||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
if err := os.MkdirAll(dir, 0o755); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +60,7 @@ func New(network, dataDir string) (*Store, error) {
|
|||||||
func (s *Store) Reserve(id string, ifname string, ip net.IP, rangeID string) (bool, error) {
|
func (s *Store) Reserve(id string, ifname string, ip net.IP, rangeID string) (bool, error) {
|
||||||
fname := GetEscapedPath(s.dataDir, ip.String())
|
fname := GetEscapedPath(s.dataDir, ip.String())
|
||||||
|
|
||||||
f, err := os.OpenFile(fname, os.O_RDWR|os.O_EXCL|os.O_CREATE, 0644)
|
f, err := os.OpenFile(fname, os.O_RDWR|os.O_EXCL|os.O_CREATE, 0o644)
|
||||||
if os.IsExist(err) {
|
if os.IsExist(err) {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
@ -76,7 +78,7 @@ func (s *Store) Reserve(id string, ifname string, ip net.IP, rangeID string) (bo
|
|||||||
}
|
}
|
||||||
// store the reserved ip in lastIPFile
|
// store the reserved ip in lastIPFile
|
||||||
ipfile := GetEscapedPath(s.dataDir, lastIPFilePrefix+rangeID)
|
ipfile := GetEscapedPath(s.dataDir, lastIPFilePrefix+rangeID)
|
||||||
err = os.WriteFile(ipfile, []byte(ip.String()), 0644)
|
err = os.WriteFile(ipfile, []byte(ip.String()), 0o644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
@ -110,7 +112,6 @@ func (s *Store) FindByKey(id string, ifname string, match string) (bool, error)
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
return found, err
|
return found, err
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Store) FindByID(id string, ifname string) bool {
|
func (s *Store) FindByID(id string, ifname string) bool {
|
||||||
@ -149,7 +150,6 @@ func (s *Store) ReleaseByKey(id string, ifname string, match string) (bool, erro
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
return found, err
|
return found, err
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// N.B. This function eats errors to be tolerant and
|
// N.B. This function eats errors to be tolerant and
|
||||||
|
@ -15,10 +15,10 @@
|
|||||||
package disk
|
package disk
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLock(t *testing.T) {
|
func TestLock(t *testing.T) {
|
||||||
|
@ -15,9 +15,10 @@
|
|||||||
package disk
|
package disk
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/alexflint/go-filemutex"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
|
"github.com/alexflint/go-filemutex"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FileLock wraps os.File to be used as a lock using flock
|
// FileLock wraps os.File to be used as a lock using flock
|
||||||
|
@ -30,7 +30,7 @@ var _ = Describe("Lock Operations", func() {
|
|||||||
|
|
||||||
// create a dummy file to lock
|
// create a dummy file to lock
|
||||||
path := filepath.Join(dir, "x")
|
path := filepath.Join(dir, "x")
|
||||||
f, err := os.OpenFile(path, os.O_RDONLY|os.O_CREATE, 0666)
|
f, err := os.OpenFile(path, os.O_RDONLY|os.O_CREATE, 0o666)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
err = f.Close()
|
err = f.Close()
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
@ -17,9 +17,10 @@ package main
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/containernetworking/cni/pkg/types"
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
|
"github.com/containernetworking/cni/pkg/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = Describe("parsing resolv.conf", func() {
|
var _ = Describe("parsing resolv.conf", func() {
|
||||||
|
@ -15,10 +15,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestHostLocal(t *testing.T) {
|
func TestHostLocal(t *testing.T) {
|
||||||
|
@ -21,14 +21,14 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
. "github.com/onsi/ginkgo/v2"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
"github.com/containernetworking/cni/pkg/skel"
|
"github.com/containernetworking/cni/pkg/skel"
|
||||||
"github.com/containernetworking/cni/pkg/types"
|
"github.com/containernetworking/cni/pkg/types"
|
||||||
types100 "github.com/containernetworking/cni/pkg/types/100"
|
types100 "github.com/containernetworking/cni/pkg/types/100"
|
||||||
"github.com/containernetworking/plugins/pkg/testutils"
|
"github.com/containernetworking/plugins/pkg/testutils"
|
||||||
|
|
||||||
"github.com/containernetworking/plugins/plugins/ipam/host-local/backend/disk"
|
"github.com/containernetworking/plugins/plugins/ipam/host-local/backend/disk"
|
||||||
. "github.com/onsi/ginkgo/v2"
|
|
||||||
. "github.com/onsi/gomega"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const LineBreak = "\r\n"
|
const LineBreak = "\r\n"
|
||||||
@ -57,7 +57,7 @@ var _ = Describe("host-local Operations", func() {
|
|||||||
ver := ver
|
ver := ver
|
||||||
|
|
||||||
It(fmt.Sprintf("[%s] allocates and releases addresses with ADD/DEL", ver), func() {
|
It(fmt.Sprintf("[%s] allocates and releases addresses with ADD/DEL", ver), func() {
|
||||||
err := os.WriteFile(filepath.Join(tmpDir, "resolv.conf"), []byte("nameserver 192.0.2.3"), 0644)
|
err := os.WriteFile(filepath.Join(tmpDir, "resolv.conf"), []byte("nameserver 192.0.2.3"), 0o644)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
conf := fmt.Sprintf(`{
|
conf := fmt.Sprintf(`{
|
||||||
@ -166,7 +166,7 @@ var _ = Describe("host-local Operations", func() {
|
|||||||
It(fmt.Sprintf("[%s] allocates and releases addresses on specific interface with ADD/DEL", ver), func() {
|
It(fmt.Sprintf("[%s] allocates and releases addresses on specific interface with ADD/DEL", ver), func() {
|
||||||
const ifname1 string = "eth1"
|
const ifname1 string = "eth1"
|
||||||
|
|
||||||
err := os.WriteFile(filepath.Join(tmpDir, "resolv.conf"), []byte("nameserver 192.0.2.3"), 0644)
|
err := os.WriteFile(filepath.Join(tmpDir, "resolv.conf"), []byte("nameserver 192.0.2.3"), 0o644)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
conf0 := fmt.Sprintf(`{
|
conf0 := fmt.Sprintf(`{
|
||||||
@ -356,7 +356,7 @@ var _ = Describe("host-local Operations", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It(fmt.Sprintf("[%s] verify DEL works on backwards compatible allocate", ver), func() {
|
It(fmt.Sprintf("[%s] verify DEL works on backwards compatible allocate", ver), func() {
|
||||||
err := os.WriteFile(filepath.Join(tmpDir, "resolv.conf"), []byte("nameserver 192.0.2.3"), 0644)
|
err := os.WriteFile(filepath.Join(tmpDir, "resolv.conf"), []byte("nameserver 192.0.2.3"), 0o644)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
conf := fmt.Sprintf(`{
|
conf := fmt.Sprintf(`{
|
||||||
@ -397,7 +397,7 @@ var _ = Describe("host-local Operations", func() {
|
|||||||
contents, err := os.ReadFile(ipFilePath)
|
contents, err := os.ReadFile(ipFilePath)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(string(contents)).To(Equal(args.ContainerID + LineBreak + ifname))
|
Expect(string(contents)).To(Equal(args.ContainerID + LineBreak + ifname))
|
||||||
err = os.WriteFile(ipFilePath, []byte(strings.TrimSpace(args.ContainerID)), 0644)
|
err = os.WriteFile(ipFilePath, []byte(strings.TrimSpace(args.ContainerID)), 0o644)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
err = testutils.CmdDelWithArgs(args, func() error {
|
err = testutils.CmdDelWithArgs(args, func() error {
|
||||||
@ -504,7 +504,7 @@ var _ = Describe("host-local Operations", func() {
|
|||||||
return cmdAdd(args)
|
return cmdAdd(args)
|
||||||
})
|
})
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(strings.Index(string(out), "Error retriving last reserved ip")).To(Equal(-1))
|
Expect(strings.Index(string(out), "Error retrieving last reserved ip")).To(Equal(-1))
|
||||||
})
|
})
|
||||||
|
|
||||||
It(fmt.Sprintf("[%s] allocates a custom IP when requested by config args", ver), func() {
|
It(fmt.Sprintf("[%s] allocates a custom IP when requested by config args", ver), func() {
|
||||||
@ -546,7 +546,7 @@ var _ = Describe("host-local Operations", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It(fmt.Sprintf("[%s] allocates custom IPs from multiple ranges", ver), func() {
|
It(fmt.Sprintf("[%s] allocates custom IPs from multiple ranges", ver), func() {
|
||||||
err := os.WriteFile(filepath.Join(tmpDir, "resolv.conf"), []byte("nameserver 192.0.2.3"), 0644)
|
err := os.WriteFile(filepath.Join(tmpDir, "resolv.conf"), []byte("nameserver 192.0.2.3"), 0o644)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
conf := fmt.Sprintf(`{
|
conf := fmt.Sprintf(`{
|
||||||
@ -594,7 +594,7 @@ var _ = Describe("host-local Operations", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It(fmt.Sprintf("[%s] allocates custom IPs from multiple protocols", ver), func() {
|
It(fmt.Sprintf("[%s] allocates custom IPs from multiple protocols", ver), func() {
|
||||||
err := os.WriteFile(filepath.Join(tmpDir, "resolv.conf"), []byte("nameserver 192.0.2.3"), 0644)
|
err := os.WriteFile(filepath.Join(tmpDir, "resolv.conf"), []byte("nameserver 192.0.2.3"), 0o644)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
conf := fmt.Sprintf(`{
|
conf := fmt.Sprintf(`{
|
||||||
|
@ -19,14 +19,13 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
bv "github.com/containernetworking/plugins/pkg/utils/buildversion"
|
|
||||||
"github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator"
|
|
||||||
"github.com/containernetworking/plugins/plugins/ipam/host-local/backend/disk"
|
|
||||||
|
|
||||||
"github.com/containernetworking/cni/pkg/skel"
|
"github.com/containernetworking/cni/pkg/skel"
|
||||||
"github.com/containernetworking/cni/pkg/types"
|
"github.com/containernetworking/cni/pkg/types"
|
||||||
current "github.com/containernetworking/cni/pkg/types/100"
|
current "github.com/containernetworking/cni/pkg/types/100"
|
||||||
"github.com/containernetworking/cni/pkg/version"
|
"github.com/containernetworking/cni/pkg/version"
|
||||||
|
bv "github.com/containernetworking/plugins/pkg/utils/buildversion"
|
||||||
|
"github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator"
|
||||||
|
"github.com/containernetworking/plugins/plugins/ipam/host-local/backend/disk"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -34,7 +33,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func cmdCheck(args *skel.CmdArgs) error {
|
func cmdCheck(args *skel.CmdArgs) error {
|
||||||
|
|
||||||
ipamConf, _, err := allocator.LoadIPAMConfig(args.StdinData, args.Args)
|
ipamConf, _, err := allocator.LoadIPAMConfig(args.StdinData, args.Args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -84,7 +82,7 @@ func cmdAdd(args *skel.CmdArgs) error {
|
|||||||
|
|
||||||
// Store all requested IPs in a map, so we can easily remove ones we use
|
// Store all requested IPs in a map, so we can easily remove ones we use
|
||||||
// and error if some remain
|
// and error if some remain
|
||||||
requestedIPs := map[string]net.IP{} //net.IP cannot be a key
|
requestedIPs := map[string]net.IP{} // net.IP cannot be a key
|
||||||
|
|
||||||
for _, ip := range ipamConf.IPArgs {
|
for _, ip := range ipamConf.IPArgs {
|
||||||
requestedIPs[ip.String()] = ip
|
requestedIPs[ip.String()] = ip
|
||||||
|
@ -19,13 +19,13 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
. "github.com/onsi/ginkgo/v2"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
"github.com/containernetworking/cni/pkg/skel"
|
"github.com/containernetworking/cni/pkg/skel"
|
||||||
"github.com/containernetworking/cni/pkg/types"
|
"github.com/containernetworking/cni/pkg/types"
|
||||||
types100 "github.com/containernetworking/cni/pkg/types/100"
|
types100 "github.com/containernetworking/cni/pkg/types/100"
|
||||||
"github.com/containernetworking/plugins/pkg/testutils"
|
"github.com/containernetworking/plugins/pkg/testutils"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
|
||||||
. "github.com/onsi/gomega"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = Describe("static Operations", func() {
|
var _ = Describe("static Operations", func() {
|
||||||
|
@ -129,7 +129,6 @@ func loadNetConf(bytes []byte, envArgs string) (*NetConf, string, error) {
|
|||||||
// - Calculates and compiles a list of gateway addresses
|
// - Calculates and compiles a list of gateway addresses
|
||||||
// - Adds a default route if needed
|
// - Adds a default route if needed
|
||||||
func calcGateways(result *current.Result, n *NetConf) (*gwInfo, *gwInfo, error) {
|
func calcGateways(result *current.Result, n *NetConf) (*gwInfo, *gwInfo, error) {
|
||||||
|
|
||||||
gwsV4 := &gwInfo{}
|
gwsV4 := &gwInfo{}
|
||||||
gwsV6 := &gwInfo{}
|
gwsV6 := &gwInfo{}
|
||||||
|
|
||||||
@ -533,8 +532,10 @@ func cmdAdd(args *skel.CmdArgs) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if vlanInterface == nil {
|
if vlanInterface == nil {
|
||||||
vlanInterface = ¤t.Interface{Name: vlanIface.Attrs().Name,
|
vlanInterface = ¤t.Interface{
|
||||||
Mac: vlanIface.Attrs().HardwareAddr.String()}
|
Name: vlanIface.Attrs().Name,
|
||||||
|
Mac: vlanIface.Attrs().HardwareAddr.String(),
|
||||||
|
}
|
||||||
result.Interfaces = append(result.Interfaces, vlanInterface)
|
result.Interfaces = append(result.Interfaces, vlanInterface)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -720,7 +721,6 @@ type cniBridgeIf struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func validateInterface(intf current.Interface, expectInSb bool) (cniBridgeIf, netlink.Link, error) {
|
func validateInterface(intf current.Interface, expectInSb bool) (cniBridgeIf, netlink.Link, error) {
|
||||||
|
|
||||||
ifFound := cniBridgeIf{found: false}
|
ifFound := cniBridgeIf{found: false}
|
||||||
if intf.Name == "" {
|
if intf.Name == "" {
|
||||||
return ifFound, nil, fmt.Errorf("Interface name missing ")
|
return ifFound, nil, fmt.Errorf("Interface name missing ")
|
||||||
@ -745,7 +745,6 @@ func validateInterface(intf current.Interface, expectInSb bool) (cniBridgeIf, ne
|
|||||||
}
|
}
|
||||||
|
|
||||||
func validateCniBrInterface(intf current.Interface, n *NetConf) (cniBridgeIf, error) {
|
func validateCniBrInterface(intf current.Interface, n *NetConf) (cniBridgeIf, error) {
|
||||||
|
|
||||||
brFound, link, err := validateInterface(intf, false)
|
brFound, link, err := validateInterface(intf, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return brFound, err
|
return brFound, err
|
||||||
@ -777,7 +776,6 @@ func validateCniBrInterface(intf current.Interface, n *NetConf) (cniBridgeIf, er
|
|||||||
}
|
}
|
||||||
|
|
||||||
func validateCniVethInterface(intf *current.Interface, brIf cniBridgeIf, contIf cniBridgeIf) (cniBridgeIf, error) {
|
func validateCniVethInterface(intf *current.Interface, brIf cniBridgeIf, contIf cniBridgeIf) (cniBridgeIf, error) {
|
||||||
|
|
||||||
vethFound, link, err := validateInterface(*intf, false)
|
vethFound, link, err := validateInterface(*intf, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return vethFound, err
|
return vethFound, err
|
||||||
@ -821,7 +819,6 @@ func validateCniVethInterface(intf *current.Interface, brIf cniBridgeIf, contIf
|
|||||||
}
|
}
|
||||||
|
|
||||||
func validateCniContainerInterface(intf current.Interface) (cniBridgeIf, error) {
|
func validateCniContainerInterface(intf current.Interface) (cniBridgeIf, error) {
|
||||||
|
|
||||||
vethFound, link, err := validateInterface(intf, true)
|
vethFound, link, err := validateInterface(intf, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return vethFound, err
|
return vethFound, err
|
||||||
@ -850,7 +847,6 @@ func validateCniContainerInterface(intf current.Interface) (cniBridgeIf, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func cmdCheck(args *skel.CmdArgs) error {
|
func cmdCheck(args *skel.CmdArgs) error {
|
||||||
|
|
||||||
n, _, err := loadNetConf(args.StdinData, args.Args)
|
n, _, err := loadNetConf(args.StdinData, args.Args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -15,10 +15,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -23,6 +23,9 @@ import (
|
|||||||
|
|
||||||
"github.com/coreos/go-iptables/iptables"
|
"github.com/coreos/go-iptables/iptables"
|
||||||
"github.com/networkplumbing/go-nft/nft"
|
"github.com/networkplumbing/go-nft/nft"
|
||||||
|
. "github.com/onsi/ginkgo/v2"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
"github.com/vishvananda/netlink"
|
||||||
"github.com/vishvananda/netlink/nl"
|
"github.com/vishvananda/netlink/nl"
|
||||||
|
|
||||||
"github.com/containernetworking/cni/pkg/skel"
|
"github.com/containernetworking/cni/pkg/skel"
|
||||||
@ -32,12 +35,7 @@ import (
|
|||||||
"github.com/containernetworking/plugins/pkg/ip"
|
"github.com/containernetworking/plugins/pkg/ip"
|
||||||
"github.com/containernetworking/plugins/pkg/ns"
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
"github.com/containernetworking/plugins/pkg/testutils"
|
"github.com/containernetworking/plugins/pkg/testutils"
|
||||||
|
|
||||||
"github.com/vishvananda/netlink"
|
|
||||||
|
|
||||||
"github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator"
|
"github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator"
|
||||||
. "github.com/onsi/ginkgo/v2"
|
|
||||||
. "github.com/onsi/gomega"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -285,7 +283,7 @@ var counter uint
|
|||||||
// arguments for a test case.
|
// arguments for a test case.
|
||||||
func (tc testCase) createCmdArgs(targetNS ns.NetNS, dataDir string) *skel.CmdArgs {
|
func (tc testCase) createCmdArgs(targetNS ns.NetNS, dataDir string) *skel.CmdArgs {
|
||||||
conf := tc.netConfJSON(dataDir)
|
conf := tc.netConfJSON(dataDir)
|
||||||
//defer func() { counter += 1 }()
|
// defer func() { counter += 1 }()
|
||||||
return &skel.CmdArgs{
|
return &skel.CmdArgs{
|
||||||
ContainerID: fmt.Sprintf("dummy-%d", counter),
|
ContainerID: fmt.Sprintf("dummy-%d", counter),
|
||||||
Netns: targetNS.Path(),
|
Netns: targetNS.Path(),
|
||||||
@ -298,12 +296,11 @@ func (tc testCase) createCmdArgs(targetNS ns.NetNS, dataDir string) *skel.CmdArg
|
|||||||
// createCheckCmdArgs generates network configuration and creates command
|
// createCheckCmdArgs generates network configuration and creates command
|
||||||
// arguments for a Check test case.
|
// arguments for a Check test case.
|
||||||
func (tc testCase) createCheckCmdArgs(targetNS ns.NetNS, config *Net, dataDir string) *skel.CmdArgs {
|
func (tc testCase) createCheckCmdArgs(targetNS ns.NetNS, config *Net, dataDir string) *skel.CmdArgs {
|
||||||
|
|
||||||
conf, err := json.Marshal(config)
|
conf, err := json.Marshal(config)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
// TODO Don't we need to use the same counter as before?
|
// TODO Don't we need to use the same counter as before?
|
||||||
//defer func() { counter += 1 }()
|
// defer func() { counter += 1 }()
|
||||||
return &skel.CmdArgs{
|
return &skel.CmdArgs{
|
||||||
ContainerID: fmt.Sprintf("dummy-%d", counter),
|
ContainerID: fmt.Sprintf("dummy-%d", counter),
|
||||||
Netns: targetNS.Path(),
|
Netns: targetNS.Path(),
|
||||||
@ -435,10 +432,12 @@ type testerBase struct {
|
|||||||
vethName string
|
vethName string
|
||||||
}
|
}
|
||||||
|
|
||||||
type testerV10x testerBase
|
type (
|
||||||
type testerV04x testerBase
|
testerV10x testerBase
|
||||||
type testerV03x testerBase
|
testerV04x testerBase
|
||||||
type testerV01xOr02x testerBase
|
testerV03x testerBase
|
||||||
|
testerV01xOr02x testerBase
|
||||||
|
)
|
||||||
|
|
||||||
func newTesterByVersion(version string, testNS, targetNS ns.NetNS) cmdAddDelTester {
|
func newTesterByVersion(version string, testNS, targetNS ns.NetNS) cmdAddDelTester {
|
||||||
switch {
|
switch {
|
||||||
@ -615,7 +614,7 @@ func (tester *testerV10x) cmdAddTest(tc testCase, dataDir string) (types.Result,
|
|||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(len(addrs)).To(Equal(len(expCIDRsV4)))
|
Expect(len(addrs)).To(Equal(len(expCIDRsV4)))
|
||||||
addrs, err = netlink.AddrList(link, netlink.FAMILY_V6)
|
addrs, err = netlink.AddrList(link, netlink.FAMILY_V6)
|
||||||
Expect(len(addrs)).To(Equal(len(expCIDRsV6) + 1)) //add one for the link-local
|
Expect(len(addrs)).To(Equal(len(expCIDRsV6) + 1)) // add one for the link-local
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
// Ignore link local address which may or may not be
|
// Ignore link local address which may or may not be
|
||||||
// ready when we read addresses.
|
// ready when we read addresses.
|
||||||
@ -691,7 +690,7 @@ func (tester *testerV10x) cmdCheckTest(tc testCase, conf *Net, dataDir string) {
|
|||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(len(addrs)).To(Equal(len(expCIDRsV4)))
|
Expect(len(addrs)).To(Equal(len(expCIDRsV4)))
|
||||||
addrs, err = netlink.AddrList(link, netlink.FAMILY_V6)
|
addrs, err = netlink.AddrList(link, netlink.FAMILY_V6)
|
||||||
Expect(len(addrs)).To(Equal(len(expCIDRsV6) + 1)) //add one for the link-local
|
Expect(len(addrs)).To(Equal(len(expCIDRsV6) + 1)) // add one for the link-local
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
// Ignore link local address which may or may not be
|
// Ignore link local address which may or may not be
|
||||||
// ready when we read addresses.
|
// ready when we read addresses.
|
||||||
@ -915,7 +914,7 @@ func (tester *testerV04x) cmdAddTest(tc testCase, dataDir string) (types.Result,
|
|||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(len(addrs)).To(Equal(len(expCIDRsV4)))
|
Expect(len(addrs)).To(Equal(len(expCIDRsV4)))
|
||||||
addrs, err = netlink.AddrList(link, netlink.FAMILY_V6)
|
addrs, err = netlink.AddrList(link, netlink.FAMILY_V6)
|
||||||
Expect(len(addrs)).To(Equal(len(expCIDRsV6) + 1)) //add one for the link-local
|
Expect(len(addrs)).To(Equal(len(expCIDRsV6) + 1)) // add one for the link-local
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
// Ignore link local address which may or may not be
|
// Ignore link local address which may or may not be
|
||||||
// ready when we read addresses.
|
// ready when we read addresses.
|
||||||
@ -991,7 +990,7 @@ func (tester *testerV04x) cmdCheckTest(tc testCase, conf *Net, dataDir string) {
|
|||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(len(addrs)).To(Equal(len(expCIDRsV4)))
|
Expect(len(addrs)).To(Equal(len(expCIDRsV4)))
|
||||||
addrs, err = netlink.AddrList(link, netlink.FAMILY_V6)
|
addrs, err = netlink.AddrList(link, netlink.FAMILY_V6)
|
||||||
Expect(len(addrs)).To(Equal(len(expCIDRsV6) + 1)) //add one for the link-local
|
Expect(len(addrs)).To(Equal(len(expCIDRsV6) + 1)) // add one for the link-local
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
// Ignore link local address which may or may not be
|
// Ignore link local address which may or may not be
|
||||||
// ready when we read addresses.
|
// ready when we read addresses.
|
||||||
@ -1577,7 +1576,6 @@ func buildOneConfig(name, cniVersion string, orig *Net, prevResult types.Result)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return conf, nil
|
return conf, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func cmdAddDelCheckTest(origNS, targetNS ns.NetNS, tc testCase, dataDir string) {
|
func cmdAddDelCheckTest(origNS, targetNS ns.NetNS, tc testCase, dataDir string) {
|
||||||
@ -1989,8 +1987,6 @@ var _ = Describe("bridge Operations", func() {
|
|||||||
|
|
||||||
It(fmt.Sprintf("[%s] ensure promiscuous mode on bridge", ver), func() {
|
It(fmt.Sprintf("[%s] ensure promiscuous mode on bridge", ver), func() {
|
||||||
const IFNAME = "bridge0"
|
const IFNAME = "bridge0"
|
||||||
const EXPECTED_IP = "10.0.0.0/8"
|
|
||||||
const CHANGED_EXPECTED_IP = "10.1.2.3/16"
|
|
||||||
|
|
||||||
conf := &NetConf{
|
conf := &NetConf{
|
||||||
NetConf: types.NetConf{
|
NetConf: types.NetConf{
|
||||||
@ -2014,7 +2010,7 @@ var _ = Describe("bridge Operations", func() {
|
|||||||
// Check if ForceAddress has default value
|
// Check if ForceAddress has default value
|
||||||
Expect(conf.ForceAddress).To(Equal(false))
|
Expect(conf.ForceAddress).To(Equal(false))
|
||||||
|
|
||||||
//Check if promiscuous mode is set correctly
|
// Check if promiscuous mode is set correctly
|
||||||
link, err := netlink.LinkByName("bridge0")
|
link, err := netlink.LinkByName("bridge0")
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
@ -26,7 +26,6 @@ import (
|
|||||||
"github.com/containernetworking/cni/pkg/types"
|
"github.com/containernetworking/cni/pkg/types"
|
||||||
current "github.com/containernetworking/cni/pkg/types/100"
|
current "github.com/containernetworking/cni/pkg/types/100"
|
||||||
"github.com/containernetworking/cni/pkg/version"
|
"github.com/containernetworking/cni/pkg/version"
|
||||||
|
|
||||||
"github.com/containernetworking/plugins/pkg/ip"
|
"github.com/containernetworking/plugins/pkg/ip"
|
||||||
"github.com/containernetworking/plugins/pkg/ipam"
|
"github.com/containernetworking/plugins/pkg/ipam"
|
||||||
"github.com/containernetworking/plugins/pkg/ns"
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
@ -42,7 +41,6 @@ func parseNetConf(bytes []byte) (*types.NetConf, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createDummy(conf *types.NetConf, ifName string, netns ns.NetNS) (*current.Interface, error) {
|
func createDummy(conf *types.NetConf, ifName string, netns ns.NetNS) (*current.Interface, error) {
|
||||||
|
|
||||||
dummy := ¤t.Interface{}
|
dummy := ¤t.Interface{}
|
||||||
|
|
||||||
dm := &netlink.Dummy{
|
dm := &netlink.Dummy{
|
||||||
@ -245,7 +243,6 @@ func cmdCheck(args *skel.CmdArgs) error {
|
|||||||
//
|
//
|
||||||
// Check prevResults for ips, routes and dns against values found in the container
|
// Check prevResults for ips, routes and dns against values found in the container
|
||||||
if err := netns.Do(func(_ ns.NetNS) error {
|
if err := netns.Do(func(_ ns.NetNS) error {
|
||||||
|
|
||||||
// Check interface against values found in the container
|
// Check interface against values found in the container
|
||||||
err := validateCniContainerInterface(contMap)
|
err := validateCniContainerInterface(contMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -262,11 +259,9 @@ func cmdCheck(args *skel.CmdArgs) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateCniContainerInterface(intf current.Interface) error {
|
func validateCniContainerInterface(intf current.Interface) error {
|
||||||
|
|
||||||
var link netlink.Link
|
var link netlink.Link
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
@ -15,12 +15,11 @@
|
|||||||
package main_test
|
package main_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/onsi/gomega/gexec"
|
"testing"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
"github.com/onsi/gomega/gexec"
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var pathToLoPlugin string
|
var pathToLoPlugin string
|
||||||
|
@ -23,6 +23,10 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
. "github.com/onsi/ginkgo/v2"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
"github.com/vishvananda/netlink"
|
||||||
|
|
||||||
"github.com/containernetworking/cni/pkg/skel"
|
"github.com/containernetworking/cni/pkg/skel"
|
||||||
"github.com/containernetworking/cni/pkg/types"
|
"github.com/containernetworking/cni/pkg/types"
|
||||||
types020 "github.com/containernetworking/cni/pkg/types/020"
|
types020 "github.com/containernetworking/cni/pkg/types/020"
|
||||||
@ -31,11 +35,6 @@ import (
|
|||||||
"github.com/containernetworking/plugins/pkg/ns"
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
"github.com/containernetworking/plugins/pkg/testutils"
|
"github.com/containernetworking/plugins/pkg/testutils"
|
||||||
"github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator"
|
"github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator"
|
||||||
|
|
||||||
"github.com/vishvananda/netlink"
|
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
|
||||||
. "github.com/onsi/gomega"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const MASTER_NAME = "eth0"
|
const MASTER_NAME = "eth0"
|
||||||
@ -89,7 +88,6 @@ func buildOneConfig(netName string, cniVersion string, orig *Net, prevResult typ
|
|||||||
}
|
}
|
||||||
|
|
||||||
return conf, nil
|
return conf, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type tester interface {
|
type tester interface {
|
||||||
@ -99,10 +97,12 @@ type tester interface {
|
|||||||
|
|
||||||
type testerBase struct{}
|
type testerBase struct{}
|
||||||
|
|
||||||
type testerV10x testerBase
|
type (
|
||||||
type testerV04x testerBase
|
testerV10x testerBase
|
||||||
type testerV03x testerBase
|
testerV04x testerBase
|
||||||
type testerV01xOr02x testerBase
|
testerV03x testerBase
|
||||||
|
testerV01xOr02x testerBase
|
||||||
|
)
|
||||||
|
|
||||||
func newTesterByVersion(version string) tester {
|
func newTesterByVersion(version string) tester {
|
||||||
switch {
|
switch {
|
||||||
|
@ -31,16 +31,13 @@ import (
|
|||||||
"github.com/containernetworking/cni/pkg/types"
|
"github.com/containernetworking/cni/pkg/types"
|
||||||
current "github.com/containernetworking/cni/pkg/types/100"
|
current "github.com/containernetworking/cni/pkg/types/100"
|
||||||
"github.com/containernetworking/cni/pkg/version"
|
"github.com/containernetworking/cni/pkg/version"
|
||||||
|
|
||||||
"github.com/containernetworking/plugins/pkg/ip"
|
"github.com/containernetworking/plugins/pkg/ip"
|
||||||
"github.com/containernetworking/plugins/pkg/ipam"
|
"github.com/containernetworking/plugins/pkg/ipam"
|
||||||
"github.com/containernetworking/plugins/pkg/ns"
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
bv "github.com/containernetworking/plugins/pkg/utils/buildversion"
|
bv "github.com/containernetworking/plugins/pkg/utils/buildversion"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var sysBusPCI = "/sys/bus/pci/devices"
|
||||||
sysBusPCI = "/sys/bus/pci/devices"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Array of different linux drivers bound to network device needed for DPDK
|
// Array of different linux drivers bound to network device needed for DPDK
|
||||||
var userspaceDrivers = []string{"vfio-pci", "uio_pci_generic", "igb_uio"}
|
var userspaceDrivers = []string{"vfio-pci", "uio_pci_generic", "igb_uio"}
|
||||||
@ -386,7 +383,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func cmdCheck(args *skel.CmdArgs) error {
|
func cmdCheck(args *skel.CmdArgs) error {
|
||||||
|
|
||||||
cfg, err := loadConf(args.StdinData)
|
cfg, err := loadConf(args.StdinData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -443,7 +439,6 @@ func cmdCheck(args *skel.CmdArgs) error {
|
|||||||
//
|
//
|
||||||
// Check prevResults for ips, routes and dns against values found in the container
|
// Check prevResults for ips, routes and dns against values found in the container
|
||||||
if err := netns.Do(func(_ ns.NetNS) error {
|
if err := netns.Do(func(_ ns.NetNS) error {
|
||||||
|
|
||||||
// Check interface against values found in the container
|
// Check interface against values found in the container
|
||||||
err := validateCniContainerInterface(contMap)
|
err := validateCniContainerInterface(contMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -469,7 +464,6 @@ func cmdCheck(args *skel.CmdArgs) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func validateCniContainerInterface(intf current.Interface) error {
|
func validateCniContainerInterface(intf current.Interface) error {
|
||||||
|
|
||||||
var link netlink.Link
|
var link netlink.Link
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
@ -15,10 +15,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestVlan(t *testing.T) {
|
func TestVlan(t *testing.T) {
|
||||||
|
@ -23,6 +23,10 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
. "github.com/onsi/ginkgo/v2"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
"github.com/vishvananda/netlink"
|
||||||
|
|
||||||
"github.com/containernetworking/cni/pkg/skel"
|
"github.com/containernetworking/cni/pkg/skel"
|
||||||
"github.com/containernetworking/cni/pkg/types"
|
"github.com/containernetworking/cni/pkg/types"
|
||||||
types040 "github.com/containernetworking/cni/pkg/types/040"
|
types040 "github.com/containernetworking/cni/pkg/types/040"
|
||||||
@ -30,10 +34,6 @@ import (
|
|||||||
"github.com/containernetworking/cni/pkg/version"
|
"github.com/containernetworking/cni/pkg/version"
|
||||||
"github.com/containernetworking/plugins/pkg/ns"
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
"github.com/containernetworking/plugins/pkg/testutils"
|
"github.com/containernetworking/plugins/pkg/testutils"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
|
||||||
. "github.com/onsi/gomega"
|
|
||||||
"github.com/vishvananda/netlink"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Net struct {
|
type Net struct {
|
||||||
@ -214,7 +214,6 @@ func buildOneConfig(name, cniVersion string, orig *Net, prevResult types.Result)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return conf, nil
|
return conf, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type tester interface {
|
type tester interface {
|
||||||
@ -224,9 +223,11 @@ type tester interface {
|
|||||||
|
|
||||||
type testerBase struct{}
|
type testerBase struct{}
|
||||||
|
|
||||||
type testerV10x testerBase
|
type (
|
||||||
type testerV04x testerBase
|
testerV10x testerBase
|
||||||
type testerV03x testerBase
|
testerV04x testerBase
|
||||||
|
testerV03x testerBase
|
||||||
|
)
|
||||||
|
|
||||||
func newTesterByVersion(version string) tester {
|
func newTesterByVersion(version string) tester {
|
||||||
switch {
|
switch {
|
||||||
@ -664,11 +665,11 @@ var _ = Describe("base functionality", func() {
|
|||||||
Expect(link.Attrs().HardwareAddr).To(Equal(origLink.Attrs().HardwareAddr))
|
Expect(link.Attrs().HardwareAddr).To(Equal(origLink.Attrs().HardwareAddr))
|
||||||
Expect(link.Attrs().Flags & net.FlagUp).To(Equal(net.FlagUp))
|
Expect(link.Attrs().Flags & net.FlagUp).To(Equal(net.FlagUp))
|
||||||
|
|
||||||
//get the IP address of the interface in the target namespace
|
// get the IP address of the interface in the target namespace
|
||||||
addrs, err := netlink.AddrList(link, netlink.FAMILY_V4)
|
addrs, err := netlink.AddrList(link, netlink.FAMILY_V4)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
addr := addrs[0].IPNet.String()
|
addr := addrs[0].IPNet.String()
|
||||||
//assert that IP address is what we set
|
// assert that IP address is what we set
|
||||||
Expect(addr).To(Equal(targetIP))
|
Expect(addr).To(Equal(targetIP))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -711,7 +712,6 @@ var _ = Describe("base functionality", func() {
|
|||||||
}
|
}
|
||||||
_, _, err := testutils.CmdAddWithArgs(args, func() error { return cmdAdd(args) })
|
_, _, err := testutils.CmdAddWithArgs(args, func() error { return cmdAdd(args) })
|
||||||
Expect(err).To(MatchError(`specify either "device", "hwaddr", "kernelpath" or "pciBusID"`))
|
Expect(err).To(MatchError(`specify either "device", "hwaddr", "kernelpath" or "pciBusID"`))
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
It(fmt.Sprintf("[%s] works with a valid config without IPAM", ver), func() {
|
It(fmt.Sprintf("[%s] works with a valid config without IPAM", ver), func() {
|
||||||
@ -961,11 +961,11 @@ var _ = Describe("base functionality", func() {
|
|||||||
Expect(link.Attrs().HardwareAddr).To(Equal(origLink.Attrs().HardwareAddr))
|
Expect(link.Attrs().HardwareAddr).To(Equal(origLink.Attrs().HardwareAddr))
|
||||||
Expect(link.Attrs().Flags & net.FlagUp).To(Equal(net.FlagUp))
|
Expect(link.Attrs().Flags & net.FlagUp).To(Equal(net.FlagUp))
|
||||||
|
|
||||||
//get the IP address of the interface in the target namespace
|
// get the IP address of the interface in the target namespace
|
||||||
addrs, err := netlink.AddrList(link, netlink.FAMILY_V4)
|
addrs, err := netlink.AddrList(link, netlink.FAMILY_V4)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
addr := addrs[0].IPNet.String()
|
addr := addrs[0].IPNet.String()
|
||||||
//assert that IP address is what we set
|
// assert that IP address is what we set
|
||||||
Expect(addr).To(Equal(targetIP))
|
Expect(addr).To(Equal(targetIP))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -1167,7 +1167,7 @@ func (fs *fakeFilesystem) use() func() {
|
|||||||
fs.rootDir = tmpDir
|
fs.rootDir = tmpDir
|
||||||
|
|
||||||
for _, dir := range fs.dirs {
|
for _, dir := range fs.dirs {
|
||||||
err := os.MkdirAll(path.Join(fs.rootDir, dir), 0755)
|
err := os.MkdirAll(path.Join(fs.rootDir, dir), 0o755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Errorf("error creating fake directory: %s", err.Error()))
|
panic(fmt.Errorf("error creating fake directory: %s", err.Error()))
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,6 @@ import (
|
|||||||
"github.com/containernetworking/cni/pkg/types"
|
"github.com/containernetworking/cni/pkg/types"
|
||||||
current "github.com/containernetworking/cni/pkg/types/100"
|
current "github.com/containernetworking/cni/pkg/types/100"
|
||||||
"github.com/containernetworking/cni/pkg/version"
|
"github.com/containernetworking/cni/pkg/version"
|
||||||
|
|
||||||
"github.com/containernetworking/plugins/pkg/ip"
|
"github.com/containernetworking/plugins/pkg/ip"
|
||||||
"github.com/containernetworking/plugins/pkg/ipam"
|
"github.com/containernetworking/plugins/pkg/ipam"
|
||||||
"github.com/containernetworking/plugins/pkg/ns"
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
@ -357,7 +356,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func cmdCheck(args *skel.CmdArgs) error {
|
func cmdCheck(args *skel.CmdArgs) error {
|
||||||
|
|
||||||
n, _, err := loadConf(args, true)
|
n, _, err := loadConf(args, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -423,7 +421,6 @@ func cmdCheck(args *skel.CmdArgs) error {
|
|||||||
|
|
||||||
// Check prevResults for ips, routes and dns against values found in the container
|
// Check prevResults for ips, routes and dns against values found in the container
|
||||||
if err := netns.Do(func(_ ns.NetNS) error {
|
if err := netns.Do(func(_ ns.NetNS) error {
|
||||||
|
|
||||||
// Check interface against values found in the container
|
// Check interface against values found in the container
|
||||||
err := validateCniContainerInterface(contMap, m.Attrs().Index, n.Mode)
|
err := validateCniContainerInterface(contMap, m.Attrs().Index, n.Mode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -448,7 +445,6 @@ func cmdCheck(args *skel.CmdArgs) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func validateCniContainerInterface(intf current.Interface, masterIndex int, modeExpected string) error {
|
func validateCniContainerInterface(intf current.Interface, masterIndex int, modeExpected string) error {
|
||||||
|
|
||||||
var link netlink.Link
|
var link netlink.Link
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
@ -15,10 +15,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIpvlan(t *testing.T) {
|
func TestIpvlan(t *testing.T) {
|
||||||
|
@ -22,6 +22,10 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
. "github.com/onsi/ginkgo/v2"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
"github.com/vishvananda/netlink"
|
||||||
|
|
||||||
"github.com/containernetworking/cni/pkg/skel"
|
"github.com/containernetworking/cni/pkg/skel"
|
||||||
"github.com/containernetworking/cni/pkg/types"
|
"github.com/containernetworking/cni/pkg/types"
|
||||||
types020 "github.com/containernetworking/cni/pkg/types/020"
|
types020 "github.com/containernetworking/cni/pkg/types/020"
|
||||||
@ -29,16 +33,13 @@ import (
|
|||||||
types100 "github.com/containernetworking/cni/pkg/types/100"
|
types100 "github.com/containernetworking/cni/pkg/types/100"
|
||||||
"github.com/containernetworking/plugins/pkg/ns"
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
"github.com/containernetworking/plugins/pkg/testutils"
|
"github.com/containernetworking/plugins/pkg/testutils"
|
||||||
|
|
||||||
"github.com/vishvananda/netlink"
|
|
||||||
|
|
||||||
"github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator"
|
"github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator"
|
||||||
. "github.com/onsi/ginkgo/v2"
|
|
||||||
. "github.com/onsi/gomega"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const MASTER_NAME = "eth0"
|
const (
|
||||||
const MASTER_NAME_INCONTAINER = "eth1"
|
MASTER_NAME = "eth0"
|
||||||
|
MASTER_NAME_INCONTAINER = "eth1"
|
||||||
|
)
|
||||||
|
|
||||||
type Net struct {
|
type Net struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
@ -92,7 +93,6 @@ func buildOneConfig(cniVersion string, master string, orig *Net, prevResult type
|
|||||||
}
|
}
|
||||||
|
|
||||||
return conf, nil
|
return conf, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ipvlanAddCheckDelTest(conf, masterName string, originalNS, targetNS ns.NetNS) {
|
func ipvlanAddCheckDelTest(conf, masterName string, originalNS, targetNS ns.NetNS) {
|
||||||
@ -206,9 +206,11 @@ type tester interface {
|
|||||||
|
|
||||||
type testerBase struct{}
|
type testerBase struct{}
|
||||||
|
|
||||||
type testerV10x testerBase
|
type (
|
||||||
type testerV04x testerBase
|
testerV10x testerBase
|
||||||
type testerV02x testerBase
|
testerV04x testerBase
|
||||||
|
testerV02x testerBase
|
||||||
|
)
|
||||||
|
|
||||||
func newTesterByVersion(version string) tester {
|
func newTesterByVersion(version string) tester {
|
||||||
switch {
|
switch {
|
||||||
@ -324,7 +326,7 @@ var _ = Describe("ipvlan Operations", func() {
|
|||||||
if inContainer {
|
if inContainer {
|
||||||
masterInterface = MASTER_NAME_INCONTAINER
|
masterInterface = MASTER_NAME_INCONTAINER
|
||||||
}
|
}
|
||||||
//for _, ver := range testutils.AllSpecVersions {
|
// for _, ver := range testutils.AllSpecVersions {
|
||||||
for _, ver := range [...]string{"1.0.0"} {
|
for _, ver := range [...]string{"1.0.0"} {
|
||||||
// Redefine ver inside for scope so real value is picked up by each dynamically defined It()
|
// Redefine ver inside for scope so real value is picked up by each dynamically defined It()
|
||||||
// See Gingkgo's "Patterns for dynamically generating tests" documentation.
|
// See Gingkgo's "Patterns for dynamically generating tests" documentation.
|
||||||
@ -471,8 +473,8 @@ var _ = Describe("ipvlan Operations", func() {
|
|||||||
err = netlink.LinkSetUp(link)
|
err = netlink.LinkSetUp(link)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
var address = &net.IPNet{IP: net.IPv4(192, 0, 0, 1), Mask: net.CIDRMask(24, 32)}
|
address := &net.IPNet{IP: net.IPv4(192, 0, 0, 1), Mask: net.CIDRMask(24, 32)}
|
||||||
var addr = &netlink.Addr{IPNet: address}
|
addr := &netlink.Addr{IPNet: address}
|
||||||
err = netlink.AddrAdd(link, addr)
|
err = netlink.AddrAdd(link, addr)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
@ -26,7 +26,6 @@ import (
|
|||||||
"github.com/containernetworking/cni/pkg/types"
|
"github.com/containernetworking/cni/pkg/types"
|
||||||
current "github.com/containernetworking/cni/pkg/types/100"
|
current "github.com/containernetworking/cni/pkg/types/100"
|
||||||
"github.com/containernetworking/cni/pkg/version"
|
"github.com/containernetworking/cni/pkg/version"
|
||||||
|
|
||||||
"github.com/containernetworking/plugins/pkg/ns"
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
bv "github.com/containernetworking/plugins/pkg/utils/buildversion"
|
bv "github.com/containernetworking/plugins/pkg/utils/buildversion"
|
||||||
)
|
)
|
||||||
@ -112,7 +111,7 @@ func cmdAdd(args *skel.CmdArgs) error {
|
|||||||
r := ¤t.Result{
|
r := ¤t.Result{
|
||||||
CNIVersion: conf.CNIVersion,
|
CNIVersion: conf.CNIVersion,
|
||||||
Interfaces: []*current.Interface{
|
Interfaces: []*current.Interface{
|
||||||
¤t.Interface{
|
{
|
||||||
Name: args.IfName,
|
Name: args.IfName,
|
||||||
Mac: "00:00:00:00:00:00",
|
Mac: "00:00:00:00:00:00",
|
||||||
Sandbox: args.Netns,
|
Sandbox: args.Netns,
|
||||||
|
@ -15,12 +15,11 @@
|
|||||||
package main_test
|
package main_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/onsi/gomega/gexec"
|
"testing"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
"github.com/onsi/gomega/gexec"
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var pathToLoPlugin string
|
var pathToLoPlugin string
|
||||||
|
@ -20,12 +20,13 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/containernetworking/plugins/pkg/ns"
|
|
||||||
"github.com/containernetworking/plugins/pkg/testutils"
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
"github.com/onsi/gomega/gbytes"
|
"github.com/onsi/gomega/gbytes"
|
||||||
"github.com/onsi/gomega/gexec"
|
"github.com/onsi/gomega/gexec"
|
||||||
|
|
||||||
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
|
"github.com/containernetworking/plugins/pkg/testutils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func generateConfig(cniVersion string) *strings.Reader {
|
func generateConfig(cniVersion string) *strings.Reader {
|
||||||
|
@ -27,7 +27,6 @@ import (
|
|||||||
"github.com/containernetworking/cni/pkg/types"
|
"github.com/containernetworking/cni/pkg/types"
|
||||||
current "github.com/containernetworking/cni/pkg/types/100"
|
current "github.com/containernetworking/cni/pkg/types/100"
|
||||||
"github.com/containernetworking/cni/pkg/version"
|
"github.com/containernetworking/cni/pkg/version"
|
||||||
|
|
||||||
"github.com/containernetworking/plugins/pkg/ip"
|
"github.com/containernetworking/plugins/pkg/ip"
|
||||||
"github.com/containernetworking/plugins/pkg/ipam"
|
"github.com/containernetworking/plugins/pkg/ipam"
|
||||||
"github.com/containernetworking/plugins/pkg/ns"
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
@ -434,7 +433,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func cmdCheck(args *skel.CmdArgs) error {
|
func cmdCheck(args *skel.CmdArgs) error {
|
||||||
|
|
||||||
n, _, err := loadConf(args, args.Args)
|
n, _, err := loadConf(args, args.Args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -501,7 +499,6 @@ func cmdCheck(args *skel.CmdArgs) error {
|
|||||||
|
|
||||||
// Check prevResults for ips, routes and dns against values found in the container
|
// Check prevResults for ips, routes and dns against values found in the container
|
||||||
if err := netns.Do(func(_ ns.NetNS) error {
|
if err := netns.Do(func(_ ns.NetNS) error {
|
||||||
|
|
||||||
// Check interface against values found in the container
|
// Check interface against values found in the container
|
||||||
err := validateCniContainerInterface(contMap, m.Attrs().Index, n.Mode)
|
err := validateCniContainerInterface(contMap, m.Attrs().Index, n.Mode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -526,7 +523,6 @@ func cmdCheck(args *skel.CmdArgs) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func validateCniContainerInterface(intf current.Interface, parentIndex int, modeExpected string) error {
|
func validateCniContainerInterface(intf current.Interface, parentIndex int, modeExpected string) error {
|
||||||
|
|
||||||
var link netlink.Link
|
var link netlink.Link
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
@ -15,10 +15,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMacvlan(t *testing.T) {
|
func TestMacvlan(t *testing.T) {
|
||||||
|
@ -22,6 +22,10 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
. "github.com/onsi/ginkgo/v2"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
"github.com/vishvananda/netlink"
|
||||||
|
|
||||||
"github.com/containernetworking/cni/pkg/skel"
|
"github.com/containernetworking/cni/pkg/skel"
|
||||||
"github.com/containernetworking/cni/pkg/types"
|
"github.com/containernetworking/cni/pkg/types"
|
||||||
types020 "github.com/containernetworking/cni/pkg/types/020"
|
types020 "github.com/containernetworking/cni/pkg/types/020"
|
||||||
@ -29,16 +33,13 @@ import (
|
|||||||
types100 "github.com/containernetworking/cni/pkg/types/100"
|
types100 "github.com/containernetworking/cni/pkg/types/100"
|
||||||
"github.com/containernetworking/plugins/pkg/ns"
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
"github.com/containernetworking/plugins/pkg/testutils"
|
"github.com/containernetworking/plugins/pkg/testutils"
|
||||||
|
|
||||||
"github.com/vishvananda/netlink"
|
|
||||||
|
|
||||||
"github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator"
|
"github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator"
|
||||||
. "github.com/onsi/ginkgo/v2"
|
|
||||||
. "github.com/onsi/gomega"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const MASTER_NAME = "eth0"
|
const (
|
||||||
const MASTER_NAME_INCONTAINER = "eth1"
|
MASTER_NAME = "eth0"
|
||||||
|
MASTER_NAME_INCONTAINER = "eth1"
|
||||||
|
)
|
||||||
|
|
||||||
type Net struct {
|
type Net struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
@ -98,7 +99,6 @@ func buildOneConfig(netName string, cniVersion string, orig *Net, prevResult typ
|
|||||||
}
|
}
|
||||||
|
|
||||||
return conf, nil
|
return conf, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type tester interface {
|
type tester interface {
|
||||||
@ -108,10 +108,12 @@ type tester interface {
|
|||||||
|
|
||||||
type testerBase struct{}
|
type testerBase struct{}
|
||||||
|
|
||||||
type testerV10x testerBase
|
type (
|
||||||
type testerV04x testerBase
|
testerV10x testerBase
|
||||||
type testerV03x testerBase
|
testerV04x testerBase
|
||||||
type testerV01xOr02x testerBase
|
testerV03x testerBase
|
||||||
|
testerV01xOr02x testerBase
|
||||||
|
)
|
||||||
|
|
||||||
func newTesterByVersion(version string) tester {
|
func newTesterByVersion(version string) tester {
|
||||||
switch {
|
switch {
|
||||||
@ -407,7 +409,6 @@ var _ = Describe("macvlan Operations", func() {
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
It(fmt.Sprintf("[%s] configures and deconfigures a l2 macvlan link with ADD/DEL", ver), func() {
|
It(fmt.Sprintf("[%s] configures and deconfigures a l2 macvlan link with ADD/DEL", ver), func() {
|
||||||
@ -637,8 +638,8 @@ var _ = Describe("macvlan Operations", func() {
|
|||||||
err = netlink.LinkSetUp(link)
|
err = netlink.LinkSetUp(link)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
var address = &net.IPNet{IP: net.IPv4(192, 0, 0, 1), Mask: net.CIDRMask(24, 32)}
|
address := &net.IPNet{IP: net.IPv4(192, 0, 0, 1), Mask: net.CIDRMask(24, 32)}
|
||||||
var addr = &netlink.Addr{IPNet: address}
|
addr := &netlink.Addr{IPNet: address}
|
||||||
err = netlink.AddrAdd(link, addr)
|
err = netlink.AddrAdd(link, addr)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
@ -28,7 +28,6 @@ import (
|
|||||||
"github.com/containernetworking/cni/pkg/types"
|
"github.com/containernetworking/cni/pkg/types"
|
||||||
current "github.com/containernetworking/cni/pkg/types/100"
|
current "github.com/containernetworking/cni/pkg/types/100"
|
||||||
"github.com/containernetworking/cni/pkg/version"
|
"github.com/containernetworking/cni/pkg/version"
|
||||||
|
|
||||||
"github.com/containernetworking/plugins/pkg/ip"
|
"github.com/containernetworking/plugins/pkg/ip"
|
||||||
"github.com/containernetworking/plugins/pkg/ipam"
|
"github.com/containernetworking/plugins/pkg/ipam"
|
||||||
"github.com/containernetworking/plugins/pkg/ns"
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
@ -282,7 +281,6 @@ func cmdDel(args *skel.CmdArgs) error {
|
|||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// if NetNs is passed down by the Cloud Orchestration Engine, or if it called multiple times
|
// if NetNs is passed down by the Cloud Orchestration Engine, or if it called multiple times
|
||||||
// so don't return an error if the device is already removed.
|
// so don't return an error if the device is already removed.
|
||||||
@ -358,7 +356,6 @@ func cmdCheck(args *skel.CmdArgs) error {
|
|||||||
//
|
//
|
||||||
// Check prevResults for ips, routes and dns against values found in the container
|
// Check prevResults for ips, routes and dns against values found in the container
|
||||||
if err := netns.Do(func(_ ns.NetNS) error {
|
if err := netns.Do(func(_ ns.NetNS) error {
|
||||||
|
|
||||||
// Check interface against values found in the container
|
// Check interface against values found in the container
|
||||||
err := validateCniContainerInterface(contMap)
|
err := validateCniContainerInterface(contMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -383,7 +380,6 @@ func cmdCheck(args *skel.CmdArgs) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func validateCniContainerInterface(intf current.Interface) error {
|
func validateCniContainerInterface(intf current.Interface) error {
|
||||||
|
|
||||||
var link netlink.Link
|
var link netlink.Link
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
@ -15,10 +15,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPtp(t *testing.T) {
|
func TestPtp(t *testing.T) {
|
||||||
|
@ -20,6 +20,10 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
. "github.com/onsi/ginkgo/v2"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
"github.com/vishvananda/netlink"
|
||||||
|
|
||||||
"github.com/containernetworking/cni/pkg/skel"
|
"github.com/containernetworking/cni/pkg/skel"
|
||||||
"github.com/containernetworking/cni/pkg/types"
|
"github.com/containernetworking/cni/pkg/types"
|
||||||
types020 "github.com/containernetworking/cni/pkg/types/020"
|
types020 "github.com/containernetworking/cni/pkg/types/020"
|
||||||
@ -27,12 +31,7 @@ import (
|
|||||||
types100 "github.com/containernetworking/cni/pkg/types/100"
|
types100 "github.com/containernetworking/cni/pkg/types/100"
|
||||||
"github.com/containernetworking/plugins/pkg/ns"
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
"github.com/containernetworking/plugins/pkg/testutils"
|
"github.com/containernetworking/plugins/pkg/testutils"
|
||||||
|
|
||||||
"github.com/vishvananda/netlink"
|
|
||||||
|
|
||||||
"github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator"
|
"github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator"
|
||||||
. "github.com/onsi/ginkgo/v2"
|
|
||||||
. "github.com/onsi/gomega"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Net struct {
|
type Net struct {
|
||||||
@ -87,7 +86,6 @@ func buildOneConfig(netName string, cniVersion string, orig *Net, prevResult typ
|
|||||||
}
|
}
|
||||||
|
|
||||||
return conf, nil
|
return conf, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type tester interface {
|
type tester interface {
|
||||||
@ -97,10 +95,12 @@ type tester interface {
|
|||||||
|
|
||||||
type testerBase struct{}
|
type testerBase struct{}
|
||||||
|
|
||||||
type testerV10x testerBase
|
type (
|
||||||
type testerV04x testerBase
|
testerV10x testerBase
|
||||||
type testerV03x testerBase
|
testerV04x testerBase
|
||||||
type testerV01xOr02x testerBase
|
testerV03x testerBase
|
||||||
|
testerV01xOr02x testerBase
|
||||||
|
)
|
||||||
|
|
||||||
func newTesterByVersion(version string) tester {
|
func newTesterByVersion(version string) tester {
|
||||||
switch {
|
switch {
|
||||||
|
@ -25,15 +25,13 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/opencontainers/selinux/go-selinux"
|
"github.com/opencontainers/selinux/go-selinux"
|
||||||
|
"github.com/vishvananda/netlink"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
|
|
||||||
"github.com/containernetworking/cni/pkg/skel"
|
"github.com/containernetworking/cni/pkg/skel"
|
||||||
"github.com/containernetworking/cni/pkg/types"
|
"github.com/containernetworking/cni/pkg/types"
|
||||||
current "github.com/containernetworking/cni/pkg/types/100"
|
current "github.com/containernetworking/cni/pkg/types/100"
|
||||||
"github.com/containernetworking/cni/pkg/version"
|
"github.com/containernetworking/cni/pkg/version"
|
||||||
"github.com/vishvananda/netlink"
|
|
||||||
|
|
||||||
"github.com/containernetworking/plugins/pkg/ip"
|
"github.com/containernetworking/plugins/pkg/ip"
|
||||||
"github.com/containernetworking/plugins/pkg/ipam"
|
"github.com/containernetworking/plugins/pkg/ipam"
|
||||||
"github.com/containernetworking/plugins/pkg/ns"
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
@ -43,15 +41,14 @@ import (
|
|||||||
|
|
||||||
type NetConf struct {
|
type NetConf struct {
|
||||||
types.NetConf
|
types.NetConf
|
||||||
MultiQueue bool `json:"multiQueue"`
|
MultiQueue bool `json:"multiQueue"`
|
||||||
MTU int `json:"mtu"`
|
MTU int `json:"mtu"`
|
||||||
Mac string `json:"mac,omitempty"`
|
Mac string `json:"mac,omitempty"`
|
||||||
Owner *uint32 `json:"owner,omitempty"`
|
Owner *uint32 `json:"owner,omitempty"`
|
||||||
Group *uint32 `json:"group,omitempty"`
|
Group *uint32 `json:"group,omitempty"`
|
||||||
SelinuxContext string `json:"selinuxContext,omitempty"`
|
SelinuxContext string `json:"selinuxContext,omitempty"`
|
||||||
Args *struct {
|
Args *struct{} `json:"args,omitempty"`
|
||||||
} `json:"args,omitempty"`
|
RuntimeConfig struct {
|
||||||
RuntimeConfig struct {
|
|
||||||
Mac string `json:"mac,omitempty"`
|
Mac string `json:"mac,omitempty"`
|
||||||
} `json:"runtimeConfig,omitempty"`
|
} `json:"runtimeConfig,omitempty"`
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,6 @@ import (
|
|||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
"github.com/vishvananda/netlink"
|
"github.com/vishvananda/netlink"
|
||||||
|
|
||||||
"github.com/containernetworking/cni/pkg/skel"
|
"github.com/containernetworking/cni/pkg/skel"
|
||||||
@ -92,7 +91,6 @@ func buildOneConfig(netName string, cniVersion string, orig *Net, prevResult typ
|
|||||||
}
|
}
|
||||||
|
|
||||||
return conf, nil
|
return conf, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type tester interface {
|
type tester interface {
|
||||||
@ -102,10 +100,12 @@ type tester interface {
|
|||||||
|
|
||||||
type testerBase struct{}
|
type testerBase struct{}
|
||||||
|
|
||||||
type testerV10x testerBase
|
type (
|
||||||
type testerV04x testerBase
|
testerV10x testerBase
|
||||||
type testerV03x testerBase
|
testerV04x testerBase
|
||||||
type testerV01xOr02x testerBase
|
testerV03x testerBase
|
||||||
|
testerV01xOr02x testerBase
|
||||||
|
)
|
||||||
|
|
||||||
func newTesterByVersion(version string) tester {
|
func newTesterByVersion(version string) tester {
|
||||||
switch {
|
switch {
|
||||||
|
@ -20,12 +20,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
|
"github.com/vishvananda/netlink"
|
||||||
|
|
||||||
"github.com/containernetworking/cni/pkg/skel"
|
"github.com/containernetworking/cni/pkg/skel"
|
||||||
"github.com/containernetworking/cni/pkg/types"
|
"github.com/containernetworking/cni/pkg/types"
|
||||||
current "github.com/containernetworking/cni/pkg/types/100"
|
current "github.com/containernetworking/cni/pkg/types/100"
|
||||||
"github.com/containernetworking/cni/pkg/version"
|
"github.com/containernetworking/cni/pkg/version"
|
||||||
"github.com/vishvananda/netlink"
|
|
||||||
|
|
||||||
"github.com/containernetworking/plugins/pkg/ip"
|
"github.com/containernetworking/plugins/pkg/ip"
|
||||||
"github.com/containernetworking/plugins/pkg/ipam"
|
"github.com/containernetworking/plugins/pkg/ipam"
|
||||||
"github.com/containernetworking/plugins/pkg/ns"
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
@ -61,7 +61,6 @@ func loadConf(args *skel.CmdArgs) (*NetConf, string, error) {
|
|||||||
|
|
||||||
// check existing and MTU of master interface
|
// check existing and MTU of master interface
|
||||||
masterMTU, err := getMTUByName(n.Master, args.Netns, n.LinkContNs)
|
masterMTU, err := getMTUByName(n.Master, args.Netns, n.LinkContNs)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", err
|
return nil, "", err
|
||||||
}
|
}
|
||||||
@ -326,7 +325,6 @@ func cmdCheck(args *skel.CmdArgs) error {
|
|||||||
//
|
//
|
||||||
// Check prevResults for ips, routes and dns against values found in the container
|
// Check prevResults for ips, routes and dns against values found in the container
|
||||||
if err := netns.Do(func(_ ns.NetNS) error {
|
if err := netns.Do(func(_ ns.NetNS) error {
|
||||||
|
|
||||||
// Check interface against values found in the container
|
// Check interface against values found in the container
|
||||||
err := validateCniContainerInterface(contMap, m.Attrs().Index, conf.VlanId, conf.MTU)
|
err := validateCniContainerInterface(contMap, m.Attrs().Index, conf.VlanId, conf.MTU)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -351,7 +349,6 @@ func cmdCheck(args *skel.CmdArgs) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func validateCniContainerInterface(intf current.Interface, masterIndex int, vlanId int, mtu int) error {
|
func validateCniContainerInterface(intf current.Interface, masterIndex int, vlanId int, mtu int) error {
|
||||||
|
|
||||||
var link netlink.Link
|
var link netlink.Link
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
@ -15,10 +15,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestVlan(t *testing.T) {
|
func TestVlan(t *testing.T) {
|
||||||
|
@ -22,6 +22,10 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
. "github.com/onsi/ginkgo/v2"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
"github.com/vishvananda/netlink"
|
||||||
|
|
||||||
"github.com/containernetworking/cni/pkg/skel"
|
"github.com/containernetworking/cni/pkg/skel"
|
||||||
"github.com/containernetworking/cni/pkg/types"
|
"github.com/containernetworking/cni/pkg/types"
|
||||||
types020 "github.com/containernetworking/cni/pkg/types/020"
|
types020 "github.com/containernetworking/cni/pkg/types/020"
|
||||||
@ -29,16 +33,13 @@ import (
|
|||||||
types100 "github.com/containernetworking/cni/pkg/types/100"
|
types100 "github.com/containernetworking/cni/pkg/types/100"
|
||||||
"github.com/containernetworking/plugins/pkg/ns"
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
"github.com/containernetworking/plugins/pkg/testutils"
|
"github.com/containernetworking/plugins/pkg/testutils"
|
||||||
|
|
||||||
"github.com/vishvananda/netlink"
|
|
||||||
|
|
||||||
"github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator"
|
"github.com/containernetworking/plugins/plugins/ipam/host-local/backend/allocator"
|
||||||
. "github.com/onsi/ginkgo/v2"
|
|
||||||
. "github.com/onsi/gomega"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const MASTER_NAME = "eth0"
|
const (
|
||||||
const MASTER_NAME_INCONTAINER = "eth1"
|
MASTER_NAME = "eth0"
|
||||||
|
MASTER_NAME_INCONTAINER = "eth1"
|
||||||
|
)
|
||||||
|
|
||||||
type Net struct {
|
type Net struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
@ -94,7 +95,6 @@ func buildOneConfig(netName string, cniVersion string, orig *Net, prevResult typ
|
|||||||
}
|
}
|
||||||
|
|
||||||
return conf, nil
|
return conf, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type tester interface {
|
type tester interface {
|
||||||
@ -104,10 +104,12 @@ type tester interface {
|
|||||||
|
|
||||||
type testerBase struct{}
|
type testerBase struct{}
|
||||||
|
|
||||||
type testerV10x testerBase
|
type (
|
||||||
type testerV04x testerBase
|
testerV10x testerBase
|
||||||
type testerV03x testerBase
|
testerV04x testerBase
|
||||||
type testerV01xOr02x testerBase
|
testerV03x testerBase
|
||||||
|
testerV01xOr02x testerBase
|
||||||
|
)
|
||||||
|
|
||||||
func newTesterByVersion(version string) tester {
|
func newTesterByVersion(version string) tester {
|
||||||
switch {
|
switch {
|
||||||
|
@ -22,6 +22,9 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
. "github.com/onsi/ginkgo/v2"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
"github.com/onsi/gomega/gexec"
|
||||||
"github.com/vishvananda/netlink"
|
"github.com/vishvananda/netlink"
|
||||||
|
|
||||||
"github.com/containernetworking/cni/pkg/invoke"
|
"github.com/containernetworking/cni/pkg/invoke"
|
||||||
@ -30,10 +33,6 @@ import (
|
|||||||
types100 "github.com/containernetworking/cni/pkg/types/100"
|
types100 "github.com/containernetworking/cni/pkg/types/100"
|
||||||
"github.com/containernetworking/plugins/pkg/ns"
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
"github.com/containernetworking/plugins/pkg/testutils"
|
"github.com/containernetworking/plugins/pkg/testutils"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
|
||||||
. "github.com/onsi/gomega"
|
|
||||||
"github.com/onsi/gomega/gexec"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func buildOneConfig(name, cniVersion string, orig *PluginConf, prevResult types.Result) (*PluginConf, []byte, error) {
|
func buildOneConfig(name, cniVersion string, orig *PluginConf, prevResult types.Result) (*PluginConf, []byte, error) {
|
||||||
@ -78,7 +77,6 @@ func buildOneConfig(name, cniVersion string, orig *PluginConf, prevResult types.
|
|||||||
}
|
}
|
||||||
|
|
||||||
return conf, newBytes, nil
|
return conf, newBytes, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ = Describe("bandwidth test", func() {
|
var _ = Describe("bandwidth test", func() {
|
||||||
@ -221,7 +219,6 @@ var _ = Describe("bandwidth test", func() {
|
|||||||
Expect(qdiscs[0].(*netlink.Tbf).Limit).To(Equal(uint32(1)))
|
Expect(qdiscs[0].(*netlink.Tbf).Limit).To(Equal(uint32(1)))
|
||||||
return nil
|
return nil
|
||||||
})).To(Succeed())
|
})).To(Succeed())
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
It(fmt.Sprintf("[%s] does not apply ingress when disabled", ver), func() {
|
It(fmt.Sprintf("[%s] does not apply ingress when disabled", ver), func() {
|
||||||
@ -289,7 +286,6 @@ var _ = Describe("bandwidth test", func() {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
})).To(Succeed())
|
})).To(Succeed())
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
It(fmt.Sprintf("[%s] does not apply egress when disabled", ver), func() {
|
It(fmt.Sprintf("[%s] does not apply egress when disabled", ver), func() {
|
||||||
@ -359,7 +355,6 @@ var _ = Describe("bandwidth test", func() {
|
|||||||
Expect(qdiscs[0].(*netlink.Tbf).Limit).To(Equal(uint32(35)))
|
Expect(qdiscs[0].(*netlink.Tbf).Limit).To(Equal(uint32(35)))
|
||||||
return nil
|
return nil
|
||||||
})).To(Succeed())
|
})).To(Succeed())
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
It(fmt.Sprintf("[%s] fails an invalid ingress config", ver), func() {
|
It(fmt.Sprintf("[%s] fails an invalid ingress config", ver), func() {
|
||||||
@ -507,7 +502,6 @@ var _ = Describe("bandwidth test", func() {
|
|||||||
Expect(qdiscs[0].(*netlink.Tbf).Limit).To(Equal(uint32(1)))
|
Expect(qdiscs[0].(*netlink.Tbf).Limit).To(Equal(uint32(1)))
|
||||||
return nil
|
return nil
|
||||||
})).To(Succeed())
|
})).To(Succeed())
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
It(fmt.Sprintf("[%s] should apply static config when both static config and runtime config exist", ver), func() {
|
It(fmt.Sprintf("[%s] should apply static config when both static config and runtime config exist", ver), func() {
|
||||||
@ -620,7 +614,6 @@ var _ = Describe("bandwidth test", func() {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
})).To(Succeed())
|
})).To(Succeed())
|
||||||
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -730,7 +723,6 @@ var _ = Describe("bandwidth test", func() {
|
|||||||
Expect(qdiscs[0].(*netlink.Tbf).Limit).To(Equal(uint32(1)))
|
Expect(qdiscs[0].(*netlink.Tbf).Limit).To(Equal(uint32(1)))
|
||||||
return nil
|
return nil
|
||||||
})).To(Succeed())
|
})).To(Succeed())
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
It(fmt.Sprintf("[%s] should fail when container interface has no veth peer", ver), func() {
|
It(fmt.Sprintf("[%s] should fail when container interface has no veth peer", ver), func() {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
// You may obtain a copy of the License at
|
// You may obtain a copy of the License at
|
||||||
//
|
//
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
//
|
//
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
@ -24,14 +24,13 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/containernetworking/plugins/pkg/ns"
|
|
||||||
"github.com/onsi/gomega/gbytes"
|
|
||||||
"github.com/onsi/gomega/gexec"
|
|
||||||
|
|
||||||
"github.com/vishvananda/netlink"
|
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
"github.com/onsi/gomega/gbytes"
|
||||||
|
"github.com/onsi/gomega/gexec"
|
||||||
|
"github.com/vishvananda/netlink"
|
||||||
|
|
||||||
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTBF(t *testing.T) {
|
func TestTBF(t *testing.T) {
|
||||||
|
@ -19,9 +19,9 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/containernetworking/plugins/pkg/ip"
|
|
||||||
|
|
||||||
"github.com/vishvananda/netlink"
|
"github.com/vishvananda/netlink"
|
||||||
|
|
||||||
|
"github.com/containernetworking/plugins/pkg/ip"
|
||||||
)
|
)
|
||||||
|
|
||||||
const latencyInMillis = 25
|
const latencyInMillis = 25
|
||||||
@ -34,7 +34,6 @@ func CreateIfb(ifbDeviceName string, mtu int) error {
|
|||||||
MTU: mtu,
|
MTU: mtu,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("adding link: %s", err)
|
return fmt.Errorf("adding link: %s", err)
|
||||||
}
|
}
|
||||||
@ -147,10 +146,6 @@ func createTBF(rateInBits, burstInBits uint64, linkIndex int) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func tick2Time(tick uint32) uint32 {
|
|
||||||
return uint32(float64(tick) / float64(netlink.TickInUsec()))
|
|
||||||
}
|
|
||||||
|
|
||||||
func time2Tick(time uint32) uint32 {
|
func time2Tick(time uint32) uint32 {
|
||||||
return uint32(float64(time) * float64(netlink.TickInUsec()))
|
return uint32(float64(time) * float64(netlink.TickInUsec()))
|
||||||
}
|
}
|
||||||
|
@ -25,24 +25,25 @@ import (
|
|||||||
"github.com/containernetworking/cni/pkg/types"
|
"github.com/containernetworking/cni/pkg/types"
|
||||||
current "github.com/containernetworking/cni/pkg/types/100"
|
current "github.com/containernetworking/cni/pkg/types/100"
|
||||||
"github.com/containernetworking/cni/pkg/version"
|
"github.com/containernetworking/cni/pkg/version"
|
||||||
|
|
||||||
"github.com/containernetworking/plugins/pkg/ip"
|
"github.com/containernetworking/plugins/pkg/ip"
|
||||||
"github.com/containernetworking/plugins/pkg/ns"
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
"github.com/containernetworking/plugins/pkg/utils"
|
"github.com/containernetworking/plugins/pkg/utils"
|
||||||
bv "github.com/containernetworking/plugins/pkg/utils/buildversion"
|
bv "github.com/containernetworking/plugins/pkg/utils/buildversion"
|
||||||
)
|
)
|
||||||
|
|
||||||
const maxIfbDeviceLength = 15
|
const (
|
||||||
const ifbDevicePrefix = "bwp"
|
maxIfbDeviceLength = 15
|
||||||
|
ifbDevicePrefix = "bwp"
|
||||||
|
)
|
||||||
|
|
||||||
// BandwidthEntry corresponds to a single entry in the bandwidth argument,
|
// BandwidthEntry corresponds to a single entry in the bandwidth argument,
|
||||||
// see CONVENTIONS.md
|
// see CONVENTIONS.md
|
||||||
type BandwidthEntry struct {
|
type BandwidthEntry struct {
|
||||||
IngressRate uint64 `json:"ingressRate"` //Bandwidth rate in bps for traffic through container. 0 for no limit. If ingressRate is set, ingressBurst must also be set
|
IngressRate uint64 `json:"ingressRate"` // Bandwidth rate in bps for traffic through container. 0 for no limit. If ingressRate is set, ingressBurst must also be set
|
||||||
IngressBurst uint64 `json:"ingressBurst"` //Bandwidth burst in bits for traffic through container. 0 for no limit. If ingressBurst is set, ingressRate must also be set
|
IngressBurst uint64 `json:"ingressBurst"` // Bandwidth burst in bits for traffic through container. 0 for no limit. If ingressBurst is set, ingressRate must also be set
|
||||||
|
|
||||||
EgressRate uint64 `json:"egressRate"` //Bandwidth rate in bps for traffic through container. 0 for no limit. If egressRate is set, egressBurst must also be set
|
EgressRate uint64 `json:"egressRate"` // Bandwidth rate in bps for traffic through container. 0 for no limit. If egressRate is set, egressBurst must also be set
|
||||||
EgressBurst uint64 `json:"egressBurst"` //Bandwidth burst in bits for traffic through container. 0 for no limit. If egressBurst is set, egressRate must also be set
|
EgressBurst uint64 `json:"egressBurst"` // Bandwidth burst in bits for traffic through container. 0 for no limit. If egressBurst is set, egressRate must also be set
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bw *BandwidthEntry) isZero() bool {
|
func (bw *BandwidthEntry) isZero() bool {
|
||||||
@ -92,7 +93,6 @@ func parseConfig(stdin []byte) (*PluginConf, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &conf, nil
|
return &conf, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getBandwidth(conf *PluginConf) *BandwidthEntry {
|
func getBandwidth(conf *PluginConf) *BandwidthEntry {
|
||||||
|
@ -26,7 +26,6 @@ import (
|
|||||||
"github.com/containernetworking/cni/pkg/types"
|
"github.com/containernetworking/cni/pkg/types"
|
||||||
current "github.com/containernetworking/cni/pkg/types/100"
|
current "github.com/containernetworking/cni/pkg/types/100"
|
||||||
"github.com/containernetworking/cni/pkg/version"
|
"github.com/containernetworking/cni/pkg/version"
|
||||||
|
|
||||||
bv "github.com/containernetworking/plugins/pkg/utils/buildversion"
|
bv "github.com/containernetworking/plugins/pkg/utils/buildversion"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -22,16 +22,15 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/godbus/dbus/v5"
|
||||||
|
. "github.com/onsi/ginkgo/v2"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
"github.com/containernetworking/cni/pkg/invoke"
|
"github.com/containernetworking/cni/pkg/invoke"
|
||||||
"github.com/containernetworking/cni/pkg/skel"
|
"github.com/containernetworking/cni/pkg/skel"
|
||||||
current "github.com/containernetworking/cni/pkg/types/100"
|
current "github.com/containernetworking/cni/pkg/types/100"
|
||||||
"github.com/containernetworking/plugins/pkg/ns"
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
"github.com/containernetworking/plugins/pkg/testutils"
|
"github.com/containernetworking/plugins/pkg/testutils"
|
||||||
|
|
||||||
"github.com/godbus/dbus/v5"
|
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
|
||||||
. "github.com/onsi/gomega"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const ifname = "eth0"
|
const ifname = "eth0"
|
||||||
|
@ -22,12 +22,13 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
. "github.com/onsi/ginkgo/v2"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
"github.com/containernetworking/cni/libcni"
|
"github.com/containernetworking/cni/libcni"
|
||||||
types100 "github.com/containernetworking/cni/pkg/types/100"
|
types100 "github.com/containernetworking/cni/pkg/types/100"
|
||||||
"github.com/containernetworking/plugins/pkg/ns"
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
"github.com/containernetworking/plugins/pkg/testutils"
|
"github.com/containernetworking/plugins/pkg/testutils"
|
||||||
. "github.com/onsi/ginkgo/v2"
|
|
||||||
. "github.com/onsi/gomega"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// The integration tests expect the "firewall" binary to be present in $PATH.
|
// The integration tests expect the "firewall" binary to be present in $PATH.
|
||||||
|
@ -19,6 +19,11 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/coreos/go-iptables/iptables"
|
||||||
|
. "github.com/onsi/ginkgo/v2"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
"github.com/vishvananda/netlink"
|
||||||
|
|
||||||
"github.com/containernetworking/cni/pkg/skel"
|
"github.com/containernetworking/cni/pkg/skel"
|
||||||
"github.com/containernetworking/cni/pkg/types"
|
"github.com/containernetworking/cni/pkg/types"
|
||||||
"github.com/containernetworking/cni/pkg/types/040"
|
"github.com/containernetworking/cni/pkg/types/040"
|
||||||
@ -26,13 +31,6 @@ import (
|
|||||||
"github.com/containernetworking/cni/pkg/version"
|
"github.com/containernetworking/cni/pkg/version"
|
||||||
"github.com/containernetworking/plugins/pkg/ns"
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
"github.com/containernetworking/plugins/pkg/testutils"
|
"github.com/containernetworking/plugins/pkg/testutils"
|
||||||
|
|
||||||
"github.com/vishvananda/netlink"
|
|
||||||
|
|
||||||
"github.com/coreos/go-iptables/iptables"
|
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
|
||||||
. "github.com/onsi/gomega"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func findChains(chains []string) (bool, bool) {
|
func findChains(chains []string) (bool, bool) {
|
||||||
|
@ -15,10 +15,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFirewall(t *testing.T) {
|
func TestFirewall(t *testing.T) {
|
||||||
|
@ -18,8 +18,9 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
current "github.com/containernetworking/cni/pkg/types/100"
|
|
||||||
"github.com/godbus/dbus/v5"
|
"github.com/godbus/dbus/v5"
|
||||||
|
|
||||||
|
current "github.com/containernetworking/cni/pkg/types/100"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -19,9 +19,10 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/coreos/go-iptables/iptables"
|
||||||
|
|
||||||
types100 "github.com/containernetworking/cni/pkg/types/100"
|
types100 "github.com/containernetworking/cni/pkg/types/100"
|
||||||
"github.com/containernetworking/plugins/pkg/utils"
|
"github.com/containernetworking/plugins/pkg/utils"
|
||||||
"github.com/coreos/go-iptables/iptables"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func setupIngressPolicy(conf *FirewallNetConf, prevResult *types100.Result) error {
|
func setupIngressPolicy(conf *FirewallNetConf, prevResult *types100.Result) error {
|
||||||
|
@ -21,9 +21,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
|
"github.com/coreos/go-iptables/iptables"
|
||||||
|
|
||||||
current "github.com/containernetworking/cni/pkg/types/100"
|
current "github.com/containernetworking/cni/pkg/types/100"
|
||||||
"github.com/containernetworking/plugins/pkg/utils"
|
"github.com/containernetworking/plugins/pkg/utils"
|
||||||
"github.com/coreos/go-iptables/iptables"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func getPrivChainRules(ip string) [][]string {
|
func getPrivChainRules(ip string) [][]string {
|
||||||
@ -211,7 +212,6 @@ type iptablesBackend struct {
|
|||||||
protos map[iptables.Protocol]*iptables.IPTables
|
protos map[iptables.Protocol]*iptables.IPTables
|
||||||
privChainName string
|
privChainName string
|
||||||
adminChainName string
|
adminChainName string
|
||||||
ifName string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// iptablesBackend implements the FirewallBackend interface
|
// iptablesBackend implements the FirewallBackend interface
|
||||||
|
@ -18,9 +18,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/containernetworking/plugins/pkg/utils"
|
|
||||||
"github.com/coreos/go-iptables/iptables"
|
"github.com/coreos/go-iptables/iptables"
|
||||||
"github.com/mattn/go-shellwords"
|
"github.com/mattn/go-shellwords"
|
||||||
|
|
||||||
|
"github.com/containernetworking/plugins/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type chain struct {
|
type chain struct {
|
||||||
@ -36,7 +37,6 @@ type chain struct {
|
|||||||
|
|
||||||
// setup idempotently creates the chain. It will not error if the chain exists.
|
// setup idempotently creates the chain. It will not error if the chain exists.
|
||||||
func (c *chain) setup(ipt *iptables.IPTables) error {
|
func (c *chain) setup(ipt *iptables.IPTables) error {
|
||||||
|
|
||||||
err := utils.EnsureChain(ipt, c.table, c.name)
|
err := utils.EnsureChain(ipt, c.table, c.name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -103,7 +103,6 @@ func (c *chain) teardown(ipt *iptables.IPTables) error {
|
|||||||
|
|
||||||
// check the chain.
|
// check the chain.
|
||||||
func (c *chain) check(ipt *iptables.IPTables) error {
|
func (c *chain) check(ipt *iptables.IPTables) error {
|
||||||
|
|
||||||
exists, err := utils.ChainExists(ipt, c.table, c.name)
|
exists, err := utils.ChainExists(ipt, c.table, c.name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -20,11 +20,12 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/containernetworking/plugins/pkg/ns"
|
|
||||||
"github.com/containernetworking/plugins/pkg/testutils"
|
|
||||||
"github.com/coreos/go-iptables/iptables"
|
"github.com/coreos/go-iptables/iptables"
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
|
"github.com/containernetworking/plugins/pkg/testutils"
|
||||||
)
|
)
|
||||||
|
|
||||||
const TABLE = "filter" // We'll monkey around here
|
const TABLE = "filter" // We'll monkey around here
|
||||||
@ -37,7 +38,6 @@ var _ = Describe("chain tests", func() {
|
|||||||
var cleanup func()
|
var cleanup func()
|
||||||
|
|
||||||
beforeEach := func() {
|
beforeEach := func() {
|
||||||
|
|
||||||
// Save a reference to the original namespace,
|
// Save a reference to the original namespace,
|
||||||
// Add a new NS
|
// Add a new NS
|
||||||
currNs, err := ns.GetCurrentNS()
|
currNs, err := ns.GetCurrentNS()
|
||||||
@ -83,7 +83,6 @@ var _ = Describe("chain tests", func() {
|
|||||||
ipt.DeleteChain(TABLE, tlChainName)
|
ipt.DeleteChain(TABLE, tlChainName)
|
||||||
currNs.Set()
|
currNs.Set()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
It("creates and destroys a chain", func() {
|
It("creates and destroys a chain", func() {
|
||||||
@ -169,7 +168,6 @@ var _ = Describe("chain tests", func() {
|
|||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
Expect(len(rules)).To(Equal(3))
|
Expect(len(rules)).To(Equal(3))
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
It("deletes chains idempotently", func() {
|
It("deletes chains idempotently", func() {
|
||||||
@ -233,6 +231,5 @@ var _ = Describe("chain tests", func() {
|
|||||||
Fail("Chain was not deleted")
|
Fail("Chain was not deleted")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -31,12 +31,12 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
|
|
||||||
"github.com/containernetworking/cni/pkg/skel"
|
"github.com/containernetworking/cni/pkg/skel"
|
||||||
"github.com/containernetworking/cni/pkg/types"
|
"github.com/containernetworking/cni/pkg/types"
|
||||||
current "github.com/containernetworking/cni/pkg/types/100"
|
current "github.com/containernetworking/cni/pkg/types/100"
|
||||||
"github.com/containernetworking/cni/pkg/version"
|
"github.com/containernetworking/cni/pkg/version"
|
||||||
"golang.org/x/sys/unix"
|
|
||||||
|
|
||||||
bv "github.com/containernetworking/plugins/pkg/utils/buildversion"
|
bv "github.com/containernetworking/plugins/pkg/utils/buildversion"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -21,10 +21,11 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/containernetworking/plugins/pkg/utils"
|
|
||||||
"github.com/containernetworking/plugins/pkg/utils/sysctl"
|
|
||||||
"github.com/coreos/go-iptables/iptables"
|
"github.com/coreos/go-iptables/iptables"
|
||||||
"github.com/vishvananda/netlink"
|
"github.com/vishvananda/netlink"
|
||||||
|
|
||||||
|
"github.com/containernetworking/plugins/pkg/utils"
|
||||||
|
"github.com/containernetworking/plugins/pkg/utils/sysctl"
|
||||||
)
|
)
|
||||||
|
|
||||||
// This creates the chains to be added to iptables. The basic structure is
|
// This creates the chains to be added to iptables. The basic structure is
|
||||||
|
@ -24,15 +24,16 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/containernetworking/cni/libcni"
|
|
||||||
"github.com/containernetworking/cni/pkg/types/100"
|
|
||||||
"github.com/containernetworking/plugins/pkg/ns"
|
|
||||||
"github.com/containernetworking/plugins/pkg/testutils"
|
|
||||||
"github.com/coreos/go-iptables/iptables"
|
"github.com/coreos/go-iptables/iptables"
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
"github.com/onsi/gomega/gexec"
|
"github.com/onsi/gomega/gexec"
|
||||||
"github.com/vishvananda/netlink"
|
"github.com/vishvananda/netlink"
|
||||||
|
|
||||||
|
"github.com/containernetworking/cni/libcni"
|
||||||
|
"github.com/containernetworking/cni/pkg/types/100"
|
||||||
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
|
"github.com/containernetworking/plugins/pkg/testutils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func makeConfig(ver string) *libcni.NetworkConfigList {
|
func makeConfig(ver string) *libcni.NetworkConfigList {
|
||||||
|
@ -21,15 +21,14 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"testing"
|
||||||
"github.com/containernetworking/plugins/pkg/ns"
|
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
"github.com/onsi/gomega/gbytes"
|
"github.com/onsi/gomega/gbytes"
|
||||||
"github.com/onsi/gomega/gexec"
|
"github.com/onsi/gomega/gexec"
|
||||||
|
|
||||||
"testing"
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPortmap(t *testing.T) {
|
func TestPortmap(t *testing.T) {
|
||||||
|
@ -17,10 +17,10 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/containernetworking/cni/pkg/types"
|
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
|
"github.com/containernetworking/cni/pkg/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = Describe("portmapping configuration", func() {
|
var _ = Describe("portmapping configuration", func() {
|
||||||
@ -202,18 +202,22 @@ var _ = Describe("portmapping configuration", func() {
|
|||||||
fillDnatRules(&ch, conf, *n)
|
fillDnatRules(&ch, conf, *n)
|
||||||
|
|
||||||
Expect(ch.entryRules).To(Equal([][]string{
|
Expect(ch.entryRules).To(Equal([][]string{
|
||||||
{"-m", "comment", "--comment",
|
{
|
||||||
|
"-m", "comment", "--comment",
|
||||||
fmt.Sprintf("dnat name: \"test\" id: \"%s\"", containerID),
|
fmt.Sprintf("dnat name: \"test\" id: \"%s\"", containerID),
|
||||||
"-m", "multiport",
|
"-m", "multiport",
|
||||||
"-p", "tcp",
|
"-p", "tcp",
|
||||||
"--destination-ports", "8080,8081,8083,8084,8085,8086",
|
"--destination-ports", "8080,8081,8083,8084,8085,8086",
|
||||||
"a", "b"},
|
"a", "b",
|
||||||
{"-m", "comment", "--comment",
|
},
|
||||||
|
{
|
||||||
|
"-m", "comment", "--comment",
|
||||||
fmt.Sprintf("dnat name: \"test\" id: \"%s\"", containerID),
|
fmt.Sprintf("dnat name: \"test\" id: \"%s\"", containerID),
|
||||||
"-m", "multiport",
|
"-m", "multiport",
|
||||||
"-p", "udp",
|
"-p", "udp",
|
||||||
"--destination-ports", "8080,8082",
|
"--destination-ports", "8080,8082",
|
||||||
"a", "b"},
|
"a", "b",
|
||||||
|
},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
Expect(ch.rules).To(Equal([][]string{
|
Expect(ch.rules).To(Equal([][]string{
|
||||||
|
@ -32,13 +32,6 @@ func fmtIpPort(ip net.IP, port int) string {
|
|||||||
return fmt.Sprintf("%s:%d", ip.String(), port)
|
return fmt.Sprintf("%s:%d", ip.String(), port)
|
||||||
}
|
}
|
||||||
|
|
||||||
func localhostIP(isV6 bool) string {
|
|
||||||
if isV6 {
|
|
||||||
return "::1"
|
|
||||||
}
|
|
||||||
return "127.0.0.1"
|
|
||||||
}
|
|
||||||
|
|
||||||
// getRoutableHostIF will try and determine which interface routes the container's
|
// getRoutableHostIF will try and determine which interface routes the container's
|
||||||
// traffic. This is the one on which we disable martian filtering.
|
// traffic. This is the one on which we disable martian filtering.
|
||||||
func getRoutableHostIF(containerIP net.IP) string {
|
func getRoutableHostIF(containerIP net.IP) string {
|
||||||
|
@ -28,7 +28,6 @@ import (
|
|||||||
"github.com/containernetworking/cni/pkg/types"
|
"github.com/containernetworking/cni/pkg/types"
|
||||||
current "github.com/containernetworking/cni/pkg/types/100"
|
current "github.com/containernetworking/cni/pkg/types/100"
|
||||||
"github.com/containernetworking/cni/pkg/version"
|
"github.com/containernetworking/cni/pkg/version"
|
||||||
|
|
||||||
"github.com/containernetworking/plugins/pkg/ns"
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
bv "github.com/containernetworking/plugins/pkg/utils/buildversion"
|
bv "github.com/containernetworking/plugins/pkg/utils/buildversion"
|
||||||
)
|
)
|
||||||
@ -109,7 +108,6 @@ func parseConfig(stdin []byte) (*PluginConf, error) {
|
|||||||
|
|
||||||
// getIPCfgs finds the IPs on the supplied interface, returning as IPConfig structures
|
// getIPCfgs finds the IPs on the supplied interface, returning as IPConfig structures
|
||||||
func getIPCfgs(iface string, prevResult *current.Result) ([]*current.IPConfig, error) {
|
func getIPCfgs(iface string, prevResult *current.Result) ([]*current.IPConfig, error) {
|
||||||
|
|
||||||
if len(prevResult.IPs) == 0 {
|
if len(prevResult.IPs) == 0 {
|
||||||
// No IP addresses; that makes no sense. Pack it in.
|
// No IP addresses; that makes no sense. Pack it in.
|
||||||
return nil, fmt.Errorf("No IP addresses supplied on interface: %s", iface)
|
return nil, fmt.Errorf("No IP addresses supplied on interface: %s", iface)
|
||||||
@ -276,7 +274,8 @@ func doRoutes(ipCfgs []*current.IPConfig, origRoutes []*types.Route, iface strin
|
|||||||
Dst: &dest,
|
Dst: &dest,
|
||||||
Gw: ipCfg.Gateway,
|
Gw: ipCfg.Gateway,
|
||||||
Table: table,
|
Table: table,
|
||||||
LinkIndex: linkIndex}
|
LinkIndex: linkIndex,
|
||||||
|
}
|
||||||
|
|
||||||
err = netlink.RouteAdd(&route)
|
err = netlink.RouteAdd(&route)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -350,7 +349,6 @@ func cmdDel(args *skel.CmdArgs) error {
|
|||||||
|
|
||||||
// Tidy up the rules for the deleted interface
|
// Tidy up the rules for the deleted interface
|
||||||
func tidyRules(iface string) error {
|
func tidyRules(iface string) error {
|
||||||
|
|
||||||
// We keep on going on rule deletion error, but return the last failure.
|
// We keep on going on rule deletion error, but return the last failure.
|
||||||
var errReturn error
|
var errReturn error
|
||||||
|
|
||||||
|
@ -19,15 +19,14 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
"github.com/containernetworking/cni/pkg/skel"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
"github.com/containernetworking/plugins/pkg/ns"
|
. "github.com/onsi/gomega"
|
||||||
"github.com/containernetworking/plugins/pkg/testutils"
|
|
||||||
|
|
||||||
"github.com/vishvananda/netlink"
|
"github.com/vishvananda/netlink"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
"github.com/containernetworking/cni/pkg/skel"
|
||||||
. "github.com/onsi/gomega"
|
"github.com/containernetworking/plugins/pkg/ns"
|
||||||
|
"github.com/containernetworking/plugins/pkg/testutils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Structures specifying state at start.
|
// Structures specifying state at start.
|
||||||
@ -114,7 +113,6 @@ func readback(targetNs ns.NetNS, devNames []string) (netStatus, error) {
|
|||||||
routes, err := netlink.RouteListFiltered(netlink.FAMILY_ALL,
|
routes, err := netlink.RouteListFiltered(netlink.FAMILY_ALL,
|
||||||
routeFilter,
|
routeFilter,
|
||||||
netlink.RT_FILTER_OIF|netlink.RT_FILTER_TABLE)
|
netlink.RT_FILTER_OIF|netlink.RT_FILTER_TABLE)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -218,7 +216,8 @@ func createDefaultStatus() netStatus {
|
|||||||
|
|
||||||
return netStatus{
|
return netStatus{
|
||||||
Devices: devs,
|
Devices: devs,
|
||||||
Rules: rules}
|
Rules: rules,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ = Describe("sbr test", func() {
|
var _ = Describe("sbr test", func() {
|
||||||
@ -293,7 +292,8 @@ var _ = Describe("sbr test", func() {
|
|||||||
netlink.Route{
|
netlink.Route{
|
||||||
Gw: net.IPv4(192, 168, 1, 1),
|
Gw: net.IPv4(192, 168, 1, 1),
|
||||||
Table: 100,
|
Table: 100,
|
||||||
LinkIndex: expNet1.Routes[0].LinkIndex})
|
LinkIndex: expNet1.Routes[0].LinkIndex,
|
||||||
|
})
|
||||||
|
|
||||||
Expect(len(newStatus.Rules)).To(Equal(1))
|
Expect(len(newStatus.Rules)).To(Equal(1))
|
||||||
Expect(newStatus.Rules[0].Table).To(Equal(100))
|
Expect(newStatus.Rules[0].Table).To(Equal(100))
|
||||||
@ -367,7 +367,8 @@ var _ = Describe("sbr test", func() {
|
|||||||
preStatus.Devices[1].Routes = append(preStatus.Devices[1].Routes,
|
preStatus.Devices[1].Routes = append(preStatus.Devices[1].Routes,
|
||||||
netlink.Route{
|
netlink.Route{
|
||||||
Gw: net.IPv4(192, 168, 1, 1),
|
Gw: net.IPv4(192, 168, 1, 1),
|
||||||
LinkIndex: routes[0].LinkIndex})
|
LinkIndex: routes[0].LinkIndex,
|
||||||
|
})
|
||||||
|
|
||||||
err := setup(targetNs, preStatus)
|
err := setup(targetNs, preStatus)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
@ -480,7 +481,8 @@ var _ = Describe("sbr test", func() {
|
|||||||
netlink.Route{
|
netlink.Route{
|
||||||
Dst: expNet1.Routes[i].Dst,
|
Dst: expNet1.Routes[i].Dst,
|
||||||
Table: 101,
|
Table: 101,
|
||||||
LinkIndex: expNet1.Routes[i].LinkIndex})
|
LinkIndex: expNet1.Routes[i].LinkIndex,
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
// All 192.168.1.x routes expected in table 100
|
// All 192.168.1.x routes expected in table 100
|
||||||
expNet1.Routes[i].Table = 100
|
expNet1.Routes[i].Table = 100
|
||||||
@ -491,13 +493,15 @@ var _ = Describe("sbr test", func() {
|
|||||||
netlink.Route{
|
netlink.Route{
|
||||||
Gw: net.IPv4(192, 168, 1, 1),
|
Gw: net.IPv4(192, 168, 1, 1),
|
||||||
Table: 100,
|
Table: 100,
|
||||||
LinkIndex: expNet1.Routes[0].LinkIndex})
|
LinkIndex: expNet1.Routes[0].LinkIndex,
|
||||||
|
})
|
||||||
|
|
||||||
expNet1.Routes = append(expNet1.Routes,
|
expNet1.Routes = append(expNet1.Routes,
|
||||||
netlink.Route{
|
netlink.Route{
|
||||||
Gw: net.IPv4(192, 168, 101, 1),
|
Gw: net.IPv4(192, 168, 101, 1),
|
||||||
Table: 101,
|
Table: 101,
|
||||||
LinkIndex: expNet1.Routes[0].LinkIndex})
|
LinkIndex: expNet1.Routes[0].LinkIndex,
|
||||||
|
})
|
||||||
|
|
||||||
// 2 Rules will be created for each IP address. (100, 101)
|
// 2 Rules will be created for each IP address. (100, 101)
|
||||||
Expect(len(newStatus.Rules)).To(Equal(2))
|
Expect(len(newStatus.Rules)).To(Equal(2))
|
||||||
@ -514,7 +518,6 @@ var _ = Describe("sbr test", func() {
|
|||||||
devEth0 := newStatus.Devices[1]
|
devEth0 := newStatus.Devices[1]
|
||||||
Expect(equalRoutes(expNet1.Routes, devNet1.Routes)).To(BeTrue())
|
Expect(equalRoutes(expNet1.Routes, devNet1.Routes)).To(BeTrue())
|
||||||
Expect(equalRoutes(expEth0.Routes, devEth0.Routes)).To(BeTrue())
|
Expect(equalRoutes(expEth0.Routes, devEth0.Routes)).To(BeTrue())
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
It("fails with CNI spec versions that don't support plugin chaining", func() {
|
It("fails with CNI spec versions that don't support plugin chaining", func() {
|
||||||
@ -537,5 +540,4 @@ var _ = Describe("sbr test", func() {
|
|||||||
_, _, err = testutils.CmdAddWithArgs(args, func() error { return cmdAdd(args) })
|
_, _, err = testutils.CmdAddWithArgs(args, func() error { return cmdAdd(args) })
|
||||||
Expect(err).To(MatchError("This plugin must be called as chained plugin"))
|
Expect(err).To(MatchError("This plugin must be called as chained plugin"))
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user