Skip to content

Commit 45e4420

Browse files
authored
migrate to golangci-lint v2 (#1227)
1 parent bafe5af commit 45e4420

File tree

8 files changed

+62
-41
lines changed

8 files changed

+62
-41
lines changed

.github/workflows/golang.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
with:
3333
go-version: ${{ inputs.golang_version }}
3434
- name: Lint
35-
uses: golangci/golangci-lint-action@v6
35+
uses: golangci/golangci-lint-action@v7
3636
with:
3737
version: latest
3838
args: -v --timeout 5m

.golangci.yml

Lines changed: 51 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,59 @@
1-
run:
2-
timeout: 10m
1+
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
315

16+
version: "2"
417
linters:
518
enable:
619
- contextcheck
7-
- errcheck
820
- gocritic
9-
- gofmt
10-
- goimports
1121
- gosec
12-
- gosimple
13-
- govet
14-
- ineffassign
1522
- misspell
16-
- staticcheck
1723
- unconvert
18-
disable: []
19-
20-
linters-settings:
21-
goimports:
22-
local-prefixes: github.com/NVIDIA/k8s-device-plugin
23-
24-
issues:
25-
exclude:
26-
# A conversion of a uint8 to an int cannot overflow.
27-
- "G115: integer overflow conversion uint8 -> int"
28-
exclude-rules:
29-
# We use math/rand instead of crypto/rand for unique names in e2e tests.
30-
- path: tests/e2e/
31-
linters:
32-
- gosec
33-
text: "G404"
34-
# We create world-readable files in tests.
35-
- path: ".*_test.go"
36-
linters:
37-
- gosec
38-
text: "G306: Expect WriteFile permissions to be 0600 or less"
24+
exclusions:
25+
generated: lax
26+
presets:
27+
- comments
28+
- common-false-positives
29+
- legacy
30+
- std-error-handling
31+
rules:
32+
- linters:
33+
- gosec
34+
path: tests/e2e/
35+
text: G404
36+
- linters:
37+
- gosec
38+
path: .*_test.go
39+
text: 'G306: Expect WriteFile permissions to be 0600 or less'
40+
- path: (.+)\.go$
41+
text: 'G115: integer overflow conversion uint8 -> int'
42+
paths:
43+
- third_party$
44+
- builtin$
45+
- examples$
46+
formatters:
47+
enable:
48+
- gofmt
49+
- goimports
50+
settings:
51+
goimports:
52+
local-prefixes:
53+
- github.com/NVIDIA/k8s-device-plugin
54+
exclusions:
55+
generated: lax
56+
paths:
57+
- third_party$
58+
- builtin$
59+
- examples$

internal/plugin/mps.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (o *options) getMPSOptions(resourceManager rm.ResourceManager) (mpsOptions,
5353
enabled: true,
5454
resourceName: resourceManager.Resource(),
5555
daemon: mps.NewDaemon(resourceManager, mps.ContainerRoot),
56-
hostRoot: mps.Root(*o.config.Flags.CommandLineFlags.MpsRoot),
56+
hostRoot: mps.Root(*o.config.Flags.MpsRoot),
5757
}
5858
return m, nil
5959
}

internal/resource/nvml-device.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (d nvmlDevice) GetName() (string, error) {
8383

8484
// GetTotalMemoryMiB returns the total memory on a device in mebibytes (2^20 bytes)
8585
func (d nvmlDevice) GetTotalMemoryMiB() (uint64, error) {
86-
info, ret := d.Device.GetMemoryInfo()
86+
info, ret := d.GetMemoryInfo()
8787
if ret != nvml.SUCCESS {
8888
return 0, ret
8989
}

internal/resource/nvml-lib.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func NewNVMLManager(nvmllib nvml.Interface, devicelib device.Interface) Manager
3737

3838
// GetCudaDriverVersion : Return the cuda v using NVML
3939
func (l nvmlLib) GetCudaDriverVersion() (int, int, error) {
40-
v, ret := l.Interface.SystemGetCudaDriverVersion()
40+
v, ret := l.SystemGetCudaDriverVersion()
4141
if ret != nvml.SUCCESS {
4242
return 0, 0, ret
4343
}
@@ -68,7 +68,7 @@ func (l nvmlLib) GetDevices() ([]Device, error) {
6868

6969
// GetDriverVersion returns the driver version
7070
func (l nvmlLib) GetDriverVersion() (string, error) {
71-
v, ret := l.Interface.SystemGetDriverVersion()
71+
v, ret := l.SystemGetDriverVersion()
7272
if ret != nvml.SUCCESS {
7373
return "", ret
7474
}

internal/resource/nvml-mig-device.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (d nvmlMigDevice) GetCudaComputeCapability() (int, int, error) {
9595
// GetName returns the name of the nvmlMigDevice.
9696
// This is equal to the mig profile.
9797
func (d nvmlMigDevice) GetName() (string, error) {
98-
p, err := d.MigDevice.GetProfile()
98+
p, err := d.GetProfile()
9999
if err != nil {
100100
return "", fmt.Errorf("failed to get MIG profile: %v", err)
101101
}

internal/rm/health.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func (r *nvmlResourceManager) checkHealth(stop <-chan interface{}, devices Devic
177177
if d.IsMigDevice() && e.GpuInstanceId != 0xFFFFFFFF && e.ComputeInstanceId != 0xFFFFFFFF {
178178
gi := deviceIDToGiMap[d.ID]
179179
ci := deviceIDToCiMap[d.ID]
180-
if !(gi == e.GpuInstanceId && ci == e.ComputeInstanceId) {
180+
if gi != e.GpuInstanceId || ci != e.ComputeInstanceId {
181181
continue
182182
}
183183
klog.Infof("Event for mig device %v (gi=%v, ci=%v)", d.ID, gi, ci)

internal/rm/nvml_devices.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (d nvmlDevice) GetPaths() ([]string, error) {
8585

8686
// GetComputeCapability returns the CUDA Compute Capability for the device.
8787
func (d nvmlDevice) GetComputeCapability() (string, error) {
88-
major, minor, ret := d.Device.GetCudaComputeCapability()
88+
major, minor, ret := d.GetCudaComputeCapability()
8989
if ret != nvml.SUCCESS {
9090
return "", ret
9191
}
@@ -94,7 +94,7 @@ func (d nvmlDevice) GetComputeCapability() (string, error) {
9494

9595
// GetComputeCapability returns the CUDA Compute Capability for the device.
9696
func (d nvmlMigDevice) GetComputeCapability() (string, error) {
97-
parent, ret := d.Device.GetDeviceHandleFromMigDeviceHandle()
97+
parent, ret := d.GetDeviceHandleFromMigDeviceHandle()
9898
if ret != nvml.SUCCESS {
9999
return "", fmt.Errorf("failed to get parent device: %w", ret)
100100
}
@@ -186,7 +186,7 @@ func (d nvmlMigDevice) GetNumaNode() (bool, int, error) {
186186

187187
// GetTotalMemory returns the total memory available on the device.
188188
func (d nvmlDevice) GetTotalMemory() (uint64, error) {
189-
info, ret := d.Device.GetMemoryInfo()
189+
info, ret := d.GetMemoryInfo()
190190
if ret != nvml.SUCCESS {
191191
return 0, ret
192192
}
@@ -195,7 +195,7 @@ func (d nvmlDevice) GetTotalMemory() (uint64, error) {
195195

196196
// GetTotalMemory returns the total memory available on the device.
197197
func (d nvmlMigDevice) GetTotalMemory() (uint64, error) {
198-
info, ret := d.Device.GetMemoryInfo()
198+
info, ret := d.GetMemoryInfo()
199199
if ret != nvml.SUCCESS {
200200
return 0, ret
201201
}

0 commit comments

Comments
 (0)