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

@ -35,14 +35,15 @@ import (
"github.com/containernetworking/cni/pkg/types"
current "github.com/containernetworking/cni/pkg/types/100"
"github.com/containernetworking/cni/pkg/version"
"github.com/containernetworking/plugins/pkg/ns"
bv "github.com/containernetworking/plugins/pkg/utils/buildversion"
)
const defaultDataDir = "/run/cni/tuning"
const defaultAllowlistDir = "/etc/cni/tuning/"
const defaultAllowlistFile = "allowlist.conf"
const (
defaultDataDir = "/run/cni/tuning"
defaultAllowlistDir = "/etc/cni/tuning/"
defaultAllowlistFile = "allowlist.conf"
)
// TuningConf represents the network tuning configuration.
type TuningConf struct {
@ -225,7 +226,7 @@ func createBackup(ifName, containerID, backupPath string, tuningConf *TuningConf
}
if _, err := os.Stat(backupPath); os.IsNotExist(err) {
if err = os.MkdirAll(backupPath, 0600); err != nil {
if err = os.MkdirAll(backupPath, 0o600); err != nil {
return fmt.Errorf("failed to create backup directory: %v", err)
}
}
@ -234,7 +235,7 @@ func createBackup(ifName, containerID, backupPath string, tuningConf *TuningConf
if err != nil {
return fmt.Errorf("failed to marshall data for %q: %v", ifName, err)
}
if err = os.WriteFile(path.Join(backupPath, containerID+"_"+ifName+".json"), data, 0600); err != nil {
if err = os.WriteFile(path.Join(backupPath, containerID+"_"+ifName+".json"), data, 0o600); err != nil {
return fmt.Errorf("failed to save file %s.json: %v", ifName, err)
}
@ -348,7 +349,7 @@ func cmdAdd(args *skel.CmdArgs) error {
return fmt.Errorf("invalid net sysctl key: %q", key)
}
content := []byte(value)
err := os.WriteFile(fileName, content, 0644)
err := os.WriteFile(fileName, content, 0o644)
if err != nil {
return err
}
@ -507,7 +508,7 @@ func validateSysctlConf(tuningConf *TuningConf) error {
if !isPresent {
return nil
}
for sysctl, _ := range tuningConf.SysCtl {
for sysctl := range tuningConf.SysCtl {
match, err := contains(sysctl, allowlist)
if err != nil {
return err

View File

@ -15,10 +15,10 @@
package main
import (
"testing"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"testing"
)
func TestTuning(t *testing.T) {

View File

@ -21,17 +21,16 @@ import (
"os"
"path/filepath"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/vishvananda/netlink"
"golang.org/x/sys/unix"
"github.com/containernetworking/cni/pkg/skel"
"github.com/containernetworking/cni/pkg/types"
"github.com/containernetworking/cni/pkg/types/100"
"github.com/containernetworking/plugins/pkg/ns"
"github.com/containernetworking/plugins/pkg/testutils"
"golang.org/x/sys/unix"
"github.com/vishvananda/netlink"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
func buildOneConfig(name, cniVersion string, orig *TuningConf, prevResult types.Result) (*TuningConf, []byte, error) {
@ -74,11 +73,10 @@ func buildOneConfig(name, cniVersion string, orig *TuningConf, prevResult types.
}
return conf, newBytes, nil
}
func createSysctlAllowFile(sysctls []string) error {
err := os.MkdirAll(defaultAllowlistDir, 0755)
err := os.MkdirAll(defaultAllowlistDir, 0o755)
if err != nil {
return err
}