mirror of
https://github.com/intel/intel-device-plugins-for-kubernetes.git
synced 2025-06-03 03:59:37 +00:00
Merge pull request #223 from bart0sh/PR0063-fix-golangci-lint-findings
Fix golangci-lint findings
This commit is contained in:
commit
c48c502d00
@ -52,12 +52,6 @@ type Config struct {
|
|||||||
Env []string `json:"env"`
|
Env []string `json:"env"`
|
||||||
} `json:"process"`
|
} `json:"process"`
|
||||||
Linux struct {
|
Linux struct {
|
||||||
Resources struct {
|
|
||||||
Devices []struct {
|
|
||||||
Major int `json:"major,omitempty"`
|
|
||||||
Minor int `json:"minor,omitempty"`
|
|
||||||
} `json:"devices"`
|
|
||||||
} `json:"resources"`
|
|
||||||
Devices []Device `json:"devices"`
|
Devices []Device `json:"devices"`
|
||||||
} `json:"linux"`
|
} `json:"linux"`
|
||||||
}
|
}
|
||||||
@ -103,13 +97,13 @@ type fpgaParams struct {
|
|||||||
portDevice string
|
portDevice string
|
||||||
}
|
}
|
||||||
|
|
||||||
func newHookEnv(sysFsPrefix, bitstreamDir string, config string, execer utilsexec.Interface) (*hookEnv, error) {
|
func newHookEnv(sysFsPrefix, bitstreamDir string, config string, execer utilsexec.Interface) *hookEnv {
|
||||||
return &hookEnv{
|
return &hookEnv{
|
||||||
sysFsPrefix: sysFsPrefix,
|
sysFsPrefix: sysFsPrefix,
|
||||||
bitstreamDir: bitstreamDir,
|
bitstreamDir: bitstreamDir,
|
||||||
config: config,
|
config: config,
|
||||||
execer: execer,
|
execer: execer,
|
||||||
}, nil
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (he *hookEnv) getConfig(stdinJ *Stdin) (*Config, error) {
|
func (he *hookEnv) getConfig(stdinJ *Stdin) (*Config, error) {
|
||||||
@ -167,7 +161,7 @@ func (he *hookEnv) getFPGAParams(config *Config) ([]fpgaParams, error) {
|
|||||||
for num, region := range regionEnv {
|
for num, region := range regionEnv {
|
||||||
afu, ok := afuEnv[num]
|
afu, ok := afuEnv[num]
|
||||||
if !ok {
|
if !ok {
|
||||||
errors.Errorf("Environment variable %s%s is not set", fpgaAfuEnvPrefix, num)
|
return nil, errors.Errorf("Environment variable %s%s is not set", fpgaAfuEnvPrefix, num)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find a device suitable for the region/interface id
|
// Find a device suitable for the region/interface id
|
||||||
@ -270,6 +264,9 @@ func (he *hookEnv) process(reader io.Reader) error {
|
|||||||
defer bitstream.Close()
|
defer bitstream.Close()
|
||||||
|
|
||||||
err = port.PR(bitstream, false)
|
err = port.PR(bitstream, false)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
programmedAfu = port.GetAcceleratorTypeUUID()
|
programmedAfu = port.GetAcceleratorTypeUUID()
|
||||||
|
|
||||||
@ -286,12 +283,9 @@ func main() {
|
|||||||
os.Setenv("PATH", "/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin")
|
os.Setenv("PATH", "/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin")
|
||||||
}
|
}
|
||||||
|
|
||||||
he, err := newHookEnv("", fpgaBitStreamDirectory, configJSON, utilsexec.New())
|
he := newHookEnv("", fpgaBitStreamDirectory, configJSON, utilsexec.New())
|
||||||
if err == nil {
|
|
||||||
err = he.process(os.Stdin)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
if err := he.process(os.Stdin); err != nil {
|
||||||
fmt.Printf("%+v\n", err)
|
fmt.Printf("%+v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
@ -158,10 +158,7 @@ func TestGetConfig(t *testing.T) {
|
|||||||
t.Fatalf("can't decode %s: %+v", fname, err)
|
t.Fatalf("can't decode %s: %+v", fname, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
he, err := newHookEnv("", "", tc.configJSON, nil)
|
he := newHookEnv("", "", tc.configJSON, nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("can't create HookEnv for config JSON %s: %+v", tc.configJSON, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
config, err := he.getConfig(stdinJ)
|
config, err := he.getConfig(stdinJ)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -287,10 +284,7 @@ func TestGetFPGAParams(t *testing.T) {
|
|||||||
t.Fatalf("can't create temp files: %+v", err)
|
t.Fatalf("can't create temp files: %+v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
he, err := newHookEnv(tmpdir, "", tc.configJSON, nil)
|
he := newHookEnv(tmpdir, "", tc.configJSON, nil)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("can't create HookEnv for config JSON %s: %+v", tc.configJSON, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
stdinJ, err := getStdin(stdin)
|
stdinJ, err := getStdin(stdin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user