ci(lint): setup golangci-lint

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
Matthieu MOREL
2023-02-28 22:27:25 +00:00
parent 86e39cfe3c
commit d12b81dec5
110 changed files with 419 additions and 479 deletions

View File

@ -18,9 +18,10 @@ import (
"fmt"
"strings"
"github.com/containernetworking/plugins/pkg/utils"
"github.com/coreos/go-iptables/iptables"
"github.com/mattn/go-shellwords"
"github.com/containernetworking/plugins/pkg/utils"
)
type chain struct {
@ -36,7 +37,6 @@ type chain struct {
// setup idempotently creates the chain. It will not error if the chain exists.
func (c *chain) setup(ipt *iptables.IPTables) error {
err := utils.EnsureChain(ipt, c.table, c.name)
if err != nil {
return err
@ -103,7 +103,6 @@ func (c *chain) teardown(ipt *iptables.IPTables) error {
// check the chain.
func (c *chain) check(ipt *iptables.IPTables) error {
exists, err := utils.ChainExists(ipt, c.table, c.name)
if err != nil {
return err

View File

@ -20,11 +20,12 @@ import (
"runtime"
"sync"
"github.com/containernetworking/plugins/pkg/ns"
"github.com/containernetworking/plugins/pkg/testutils"
"github.com/coreos/go-iptables/iptables"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/containernetworking/plugins/pkg/ns"
"github.com/containernetworking/plugins/pkg/testutils"
)
const TABLE = "filter" // We'll monkey around here
@ -37,7 +38,6 @@ var _ = Describe("chain tests", func() {
var cleanup func()
beforeEach := func() {
// Save a reference to the original namespace,
// Add a new NS
currNs, err := ns.GetCurrentNS()
@ -83,7 +83,6 @@ var _ = Describe("chain tests", func() {
ipt.DeleteChain(TABLE, tlChainName)
currNs.Set()
}
}
It("creates and destroys a chain", func() {
@ -169,7 +168,6 @@ var _ = Describe("chain tests", func() {
Expect(err).NotTo(HaveOccurred())
Expect(len(rules)).To(Equal(3))
})
It("deletes chains idempotently", func() {
@ -233,6 +231,5 @@ var _ = Describe("chain tests", func() {
Fail("Chain was not deleted")
}
}
})
})

View File

@ -31,12 +31,12 @@ import (
"log"
"net"
"golang.org/x/sys/unix"
"github.com/containernetworking/cni/pkg/skel"
"github.com/containernetworking/cni/pkg/types"
current "github.com/containernetworking/cni/pkg/types/100"
"github.com/containernetworking/cni/pkg/version"
"golang.org/x/sys/unix"
bv "github.com/containernetworking/plugins/pkg/utils/buildversion"
)

View File

@ -21,10 +21,11 @@ import (
"strconv"
"strings"
"github.com/containernetworking/plugins/pkg/utils"
"github.com/containernetworking/plugins/pkg/utils/sysctl"
"github.com/coreos/go-iptables/iptables"
"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

View File

@ -24,15 +24,16 @@ import (
"os/exec"
"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/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
"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 {

View File

@ -21,15 +21,14 @@ import (
"path/filepath"
"strconv"
"strings"
"github.com/containernetworking/plugins/pkg/ns"
"testing"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes"
"github.com/onsi/gomega/gexec"
"testing"
"github.com/containernetworking/plugins/pkg/ns"
)
func TestPortmap(t *testing.T) {

View File

@ -17,10 +17,10 @@ package main
import (
"fmt"
"github.com/containernetworking/cni/pkg/types"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/containernetworking/cni/pkg/types"
)
var _ = Describe("portmapping configuration", func() {
@ -202,18 +202,22 @@ var _ = Describe("portmapping configuration", func() {
fillDnatRules(&ch, conf, *n)
Expect(ch.entryRules).To(Equal([][]string{
{"-m", "comment", "--comment",
{
"-m", "comment", "--comment",
fmt.Sprintf("dnat name: \"test\" id: \"%s\"", containerID),
"-m", "multiport",
"-p", "tcp",
"--destination-ports", "8080,8081,8083,8084,8085,8086",
"a", "b"},
{"-m", "comment", "--comment",
"a", "b",
},
{
"-m", "comment", "--comment",
fmt.Sprintf("dnat name: \"test\" id: \"%s\"", containerID),
"-m", "multiport",
"-p", "udp",
"--destination-ports", "8080,8082",
"a", "b"},
"a", "b",
},
}))
Expect(ch.rules).To(Equal([][]string{

View File

@ -32,13 +32,6 @@ func fmtIpPort(ip net.IP, port int) string {
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
// traffic. This is the one on which we disable martian filtering.
func getRoutableHostIF(containerIP net.IP) string {