mirror of
https://github.com/intel/intel-device-plugins-for-kubernetes.git
synced 2025-06-03 03:59:37 +00:00
Merge pull request #437 from rojkov/linter-checks
lint: enable exportloopref, prealloc and scopelint checks
This commit is contained in:
commit
ab1612dd7d
@ -11,6 +11,7 @@ linters:
|
|||||||
- deadcode
|
- deadcode
|
||||||
- dogsled
|
- dogsled
|
||||||
- errcheck
|
- errcheck
|
||||||
|
- exportloopref
|
||||||
- gocognit
|
- gocognit
|
||||||
- goconst
|
- goconst
|
||||||
- gocyclo
|
- gocyclo
|
||||||
@ -30,7 +31,9 @@ linters:
|
|||||||
- nakedret
|
- nakedret
|
||||||
- noctx
|
- noctx
|
||||||
- nolintlint
|
- nolintlint
|
||||||
|
- prealloc
|
||||||
- rowserrcheck
|
- rowserrcheck
|
||||||
|
- scopelint
|
||||||
- staticcheck
|
- staticcheck
|
||||||
- structcheck
|
- structcheck
|
||||||
- stylecheck
|
- stylecheck
|
||||||
@ -51,3 +54,11 @@ linters-settings:
|
|||||||
min-complexity: 15
|
min-complexity: 15
|
||||||
gocognit:
|
gocognit:
|
||||||
min-complexity: 31
|
min-complexity: 31
|
||||||
|
|
||||||
|
issues:
|
||||||
|
exclude-rules:
|
||||||
|
- path: _test\.go
|
||||||
|
linters:
|
||||||
|
# Until the testing package allows pinning variables disable scopelint
|
||||||
|
# for tests. See https://github.com/kyoh86/scopelint/issues/4.
|
||||||
|
- scopelint
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -259,7 +260,7 @@ func (dp *devicePlugin) getAFU(fpath string, devName string) (*afu, error) {
|
|||||||
if dp.ignoreAfuIDs {
|
if dp.ignoreAfuIDs {
|
||||||
afuID = "unused_afu_id"
|
afuID = "unused_afu_id"
|
||||||
} else {
|
} else {
|
||||||
data, err := ioutil.ReadFile(fpath)
|
data, err := ioutil.ReadFile(filepath.Clean(fpath))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithStack(err)
|
return nil, errors.WithStack(err)
|
||||||
}
|
}
|
||||||
@ -278,7 +279,7 @@ func (dp *devicePlugin) getAFU(fpath string, devName string) (*afu, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (dp *devicePlugin) getFME(interfaceIDPath string, devName string) (*region, error) {
|
func (dp *devicePlugin) getFME(interfaceIDPath string, devName string) (*region, error) {
|
||||||
data, err := ioutil.ReadFile(interfaceIDPath)
|
data, err := ioutil.ReadFile(filepath.Clean(interfaceIDPath))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithStack(err)
|
return nil, errors.WithStack(err)
|
||||||
}
|
}
|
||||||
@ -295,8 +296,6 @@ func (dp *devicePlugin) getFME(interfaceIDPath string, devName string) (*region,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (dp *devicePlugin) scanFPGAs() (dpapi.DeviceTree, error) {
|
func (dp *devicePlugin) scanFPGAs() (dpapi.DeviceTree, error) {
|
||||||
var devices []device
|
|
||||||
|
|
||||||
klog.V(4).Info("Start new FPGA scan")
|
klog.V(4).Info("Start new FPGA scan")
|
||||||
|
|
||||||
fpgaFiles, err := ioutil.ReadDir(dp.sysfsDir)
|
fpgaFiles, err := ioutil.ReadDir(dp.sysfsDir)
|
||||||
@ -305,6 +304,7 @@ func (dp *devicePlugin) scanFPGAs() (dpapi.DeviceTree, error) {
|
|||||||
return dp.getDevTree([]device{}), nil
|
return dp.getDevTree([]device{}), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
devices := make([]device, 0, len(fpgaFiles))
|
||||||
for _, fpgaFile := range fpgaFiles {
|
for _, fpgaFile := range fpgaFiles {
|
||||||
fname := fpgaFile.Name()
|
fname := fpgaFile.Name()
|
||||||
|
|
||||||
|
@ -183,8 +183,6 @@ func getRequestedResources(container corev1.Container) (map[string]int64, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *patcher) getPatchOps(containerIdx int, container corev1.Container) ([]string, error) {
|
func (p *patcher) getPatchOps(containerIdx int, container corev1.Container) ([]string, error) {
|
||||||
var ops []string
|
|
||||||
|
|
||||||
requestedResources, err := getRequestedResources(container)
|
requestedResources, err := getRequestedResources(container)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -197,6 +195,7 @@ func (p *patcher) getPatchOps(containerIdx int, container corev1.Container) ([]s
|
|||||||
resources := make(map[string]int64)
|
resources := make(map[string]int64)
|
||||||
envVars := make(map[string]string)
|
envVars := make(map[string]string)
|
||||||
counter := 0
|
counter := 0
|
||||||
|
ops := make([]string, 0, 2*len(requestedResources))
|
||||||
for rname, quantity := range requestedResources {
|
for rname, quantity := range requestedResources {
|
||||||
mode, found := p.resourceModeMap[rname]
|
mode, found := p.resourceModeMap[rname]
|
||||||
if !found {
|
if !found {
|
||||||
|
@ -104,7 +104,7 @@ func (pm *PatcherManager) mutate(ctx context.Context, req webhook.AdmissionReque
|
|||||||
Allowed: true,
|
Allowed: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
var ops []string
|
ops := []string{}
|
||||||
for containerIdx, container := range pod.Spec.Containers {
|
for containerIdx, container := range pod.Spec.Containers {
|
||||||
patchOps, err := patcher.getPatchOps(containerIdx, container)
|
patchOps, err := patcher.getPatchOps(containerIdx, container)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user