Skip to content

Commit b00fcdc

Browse files
committed
fix: lint issues
1 parent 5b86d3d commit b00fcdc

27 files changed

+166
-146
lines changed

cmd/hypervisor/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
)
2525

2626
var (
27-
hardwareVendor = flag.String("hardware-vendor", "", "Hardware vendor: NVIDIA, AMD, Intel, etc.")
2827
acceleratorLibPath = flag.String("accelerator-lib",
2928
"../provider/build/libaccelerator_stub.so", "Path to accelerator library")
3029
isolationMode = flag.String("isolation-mode", "shared",
@@ -63,7 +62,6 @@ func main() {
6362
klog.Infof("Using accelerator library path from env: %s", libPath)
6463
}
6564
if vendor := os.Getenv(TFHardwareVendorEnv); vendor != "" {
66-
hardwareVendor = &vendor
6765
klog.Infof("Hardware vendor from env: %s", vendor)
6866
}
6967

@@ -123,7 +121,9 @@ func main() {
123121
if err != nil {
124122
klog.Fatalf("Failed to start worker controller: %v", err)
125123
}
126-
defer workerController.Stop()
124+
defer func() {
125+
_ = workerController.Stop()
126+
}()
127127
klog.Info("Worker controller started")
128128

129129
// initialize metrics recorder

cmd/hypervisor/shm_init/mount_shm.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ func RunMountShm() {
2020
sizeMB := mountShmFlags.Int("size", 0, "Size in MB (required)")
2121

2222
klog.InitFlags(nil)
23-
mountShmFlags.Parse(os.Args[2:])
23+
if err := mountShmFlags.Parse(os.Args[2:]); err != nil {
24+
klog.Fatalf("Failed to parse flags: %v", err)
25+
}
2426

2527
if *mountPoint == "" {
2628
klog.Fatalf("mount-point is required")

internal/gpuallocator/filter/partition_template_filter_test.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ func TestPartitionTemplateFilter(t *testing.T) {
3232
}
3333

3434
tests := []struct {
35-
name string
36-
isolationMode tfv1.IsolationModeType
37-
requiredTemplate string
38-
maxPartitionsMap map[string]uint32
39-
gpus []*tfv1.GPU
40-
expectedCount int
41-
expectedGPUNames []string
35+
name string
36+
isolationMode tfv1.IsolationModeType
37+
requiredTemplate string
38+
maxPartitionsMap map[string]uint32
39+
gpus []*tfv1.GPU
40+
expectedCount int
41+
expectedGPUNames []string
4242
}{
4343
{
4444
name: "non-partitioned mode should pass all GPUs",
@@ -67,7 +67,7 @@ func TestPartitionTemplateFilter(t *testing.T) {
6767
{
6868
ObjectMeta: metav1.ObjectMeta{Name: "gpu-1"},
6969
Status: tfv1.GPUStatus{
70-
GPUModel: "A100",
70+
GPUModel: "A100",
7171
PartitionTemplates: []tfv1.PartitionTemplate{},
7272
},
7373
},
@@ -173,4 +173,3 @@ func TestPartitionTemplateFilter(t *testing.T) {
173173
})
174174
}
175175
}
176-

internal/gpuallocator/partitioned_scheduling_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ import (
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2727
)
2828

29+
const testGPUModel = "A100_SXM_80G"
30+
2931
func TestMatchPartitionTemplate(t *testing.T) {
3032
// Setup: Initialize partition template map
31-
gpuModel := "A100_SXM_80G"
33+
gpuModel := testGPUModel
3234
PartitionTemplateMap[gpuModel] = map[string]config.PartitionTemplateInfo{
3335
"1g.24gb": {
3436
TemplateID: "1g.24gb",
@@ -218,7 +220,7 @@ func TestMatchPartitionTemplate(t *testing.T) {
218220

219221
func TestCalculatePartitionResourceUsage(t *testing.T) {
220222
// Setup
221-
gpuModel := "A100_SXM_80G"
223+
gpuModel := testGPUModel
222224
templateID := "1g.24gb"
223225
PartitionTemplateMap[gpuModel] = map[string]config.PartitionTemplateInfo{
224226
templateID: {
@@ -240,7 +242,7 @@ func TestCalculatePartitionResourceUsage(t *testing.T) {
240242

241243
func TestCheckPartitionAvailability(t *testing.T) {
242244
// Setup
243-
gpuModel := "A100_SXM_80G"
245+
gpuModel := testGPUModel
244246
templateID := "1g.24gb"
245247
PartitionTemplateMap[gpuModel] = map[string]config.PartitionTemplateInfo{
246248
templateID: {
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package api
22

33
type Worker struct {
4-
WorkerUID string
4+
WorkerUID string
55
AllocatedDevices []string
6-
Status string
7-
IsolationMode IsolationMode
8-
}
6+
Status string
7+
IsolationMode IsolationMode
8+
}

internal/hypervisor/backend/kubernetes/deviceplugin.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func (dp *DevicePlugin) Start() error {
110110
if err != nil {
111111
return fmt.Errorf("failed to dial device plugin socket: %w", err)
112112
}
113-
conn.Close()
113+
_ = conn.Close()
114114

115115
// Register with kubelet
116116
if err := dp.register(); err != nil {
@@ -138,7 +138,9 @@ func (dp *DevicePlugin) register() error {
138138
if err != nil {
139139
return fmt.Errorf("failed to dial kubelet: %w", err)
140140
}
141-
defer conn.Close()
141+
defer func() {
142+
_ = conn.Close()
143+
}()
142144

143145
client := pluginapi.NewRegistrationClient(conn)
144146
req := &pluginapi.RegisterRequest{
@@ -162,12 +164,8 @@ func (dp *DevicePlugin) register() error {
162164

163165
// dial establishes a connection to a Unix socket
164166
func (dp *DevicePlugin) dial(unixSocketPath string, timeout time.Duration) (*grpc.ClientConn, error) {
165-
ctx, cancel := context.WithTimeout(context.Background(), timeout)
166-
defer cancel()
167-
168-
conn, err := grpc.DialContext(ctx, unixSocketPath,
167+
conn, err := grpc.NewClient(unixSocketPath,
169168
grpc.WithTransportCredentials(insecure.NewCredentials()),
170-
grpc.WithBlock(),
171169
grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
172170
return net.DialTimeout("unix", addr, timeout)
173171
}),
@@ -290,9 +288,7 @@ func (dp *DevicePlugin) Allocate(ctx context.Context, req *pluginapi.AllocateReq
290288

291289
// Compose allocation request
292290
deviceUUIDs := make([]string, 0, len(containerReq.DevicesIds))
293-
for _, deviceID := range containerReq.DevicesIds {
294-
deviceUUIDs = append(deviceUUIDs, deviceID)
295-
}
291+
deviceUUIDs = append(deviceUUIDs, containerReq.DevicesIds...)
296292

297293
allocReq := &api.DeviceAllocateRequest{
298294
WorkerUID: podUID,

internal/hypervisor/backend/kubernetes/external_dp/detector_test.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,13 @@ func TestReadCheckpointFile(t *testing.T) {
6767

6868
tmpFile, err := os.CreateTemp("", "checkpoint-*.json")
6969
assert.NoError(t, err)
70-
defer os.Remove(tmpFile.Name())
70+
defer func() {
71+
_ = os.Remove(tmpFile.Name())
72+
}()
7173

7274
_, err = tmpFile.WriteString(testData)
7375
assert.NoError(t, err)
74-
tmpFile.Close()
76+
_ = tmpFile.Close()
7577

7678
detector := &DevicePluginDetector{
7779
checkpointPath: tmpFile.Name(),
@@ -109,8 +111,7 @@ func TestExtractDeviceIDs(t *testing.T) {
109111
},
110112
}
111113

112-
allocated, registered, err := detector.extractDeviceIDs(checkpoint)
113-
assert.NoError(t, err)
114+
allocated, registered := detector.extractDeviceIDs(checkpoint)
114115
assert.Contains(t, allocated, "gpu-7d8429d5-531d-d6a6-6510-3b662081a75a")
115116
assert.Contains(t, registered, "gpu-7d8429d5-531d-d6a6-6510-3b662081a75a")
116117
}
@@ -153,11 +154,13 @@ func TestProcessDeviceState_DeviceAdded(t *testing.T) {
153154

154155
tmpFile, err := os.CreateTemp("", "checkpoint-*.json")
155156
assert.NoError(t, err)
156-
defer os.Remove(tmpFile.Name())
157+
defer func() {
158+
_ = os.Remove(tmpFile.Name())
159+
}()
157160

158161
_, err = tmpFile.WriteString(checkpointData)
159162
assert.NoError(t, err)
160-
tmpFile.Close()
163+
_ = tmpFile.Close()
161164

162165
// Mock GPU resource
163166
gpu := &tfv1.GPU{
@@ -205,11 +208,13 @@ func TestProcessDeviceState_DeviceRemoved(t *testing.T) {
205208

206209
tmpFile, err := os.CreateTemp("", "checkpoint-*.json")
207210
assert.NoError(t, err)
208-
defer os.Remove(tmpFile.Name())
211+
defer func() {
212+
_ = os.Remove(tmpFile.Name())
213+
}()
209214

210215
_, err = tmpFile.WriteString(checkpointData)
211216
assert.NoError(t, err)
212-
tmpFile.Close()
217+
_ = tmpFile.Close()
213218

214219
// Mock GPU resource that was previously allocated
215220
gpu := &tfv1.GPU{

internal/hypervisor/backend/kubernetes/external_dp/kubelet_checkpoint.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func (d *DevicePluginDetector) Start() error {
138138
func (d *DevicePluginDetector) Stop() {
139139
close(d.stopCh)
140140
if d.watcher != nil {
141-
d.watcher.Close()
141+
_ = d.watcher.Close()
142142
}
143143
}
144144

@@ -238,10 +238,7 @@ func (d *DevicePluginDetector) processDeviceState(patchAllDevices bool) error {
238238
}
239239

240240
// Extract registered device IDs (for comparison)
241-
_, registeredDeviceIDs, err := d.extractDeviceIDs(checkpoint)
242-
if err != nil {
243-
return fmt.Errorf("failed to extract device IDs: %w", err)
244-
}
241+
_, registeredDeviceIDs := d.extractDeviceIDs(checkpoint)
245242

246243
// Get current pods to check for deleted pods
247244
currentPods := d.kubeletClient.GetAllPods()
@@ -424,7 +421,7 @@ func (d *DevicePluginDetector) readCheckpointFile() (*KubeletCheckpoint, error)
424421
}
425422

426423
// extractDeviceIDs extracts allocated and registered device IDs from checkpoint
427-
func (d *DevicePluginDetector) extractDeviceIDs(checkpoint *KubeletCheckpoint) (allocated, registered map[string]bool, err error) {
424+
func (d *DevicePluginDetector) extractDeviceIDs(checkpoint *KubeletCheckpoint) (allocated, registered map[string]bool) {
428425
allocated = make(map[string]bool)
429426
registered = make(map[string]bool)
430427

@@ -455,7 +452,7 @@ func (d *DevicePluginDetector) extractDeviceIDs(checkpoint *KubeletCheckpoint) (
455452
}
456453
}
457454

458-
return allocated, registered, nil
455+
return allocated, registered
459456
}
460457

461458
// findEntryForDevice finds the pod device entry for a given device ID

internal/hypervisor/backend/kubernetes/kubelet.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ func (kc *KubeletClient) Start() error {
110110
}
111111

112112
// Create informer
113+
//nolint:staticcheck // NewInformer is deprecated but NewInformerWithOptions has incompatible signature
113114
_, controller := cache.NewInformer(
114115
lw,
115116
&corev1.Pod{},

internal/hypervisor/backend/kubernetes/ns_mapper.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ func getContainerPIDFromStatus(procDir string) (uint32, error) {
9292
if err != nil {
9393
return 0, fmt.Errorf("failed to open status file: %w", err)
9494
}
95-
defer file.Close()
95+
defer func() {
96+
_ = file.Close()
97+
}()
9698

9799
scanner := bufio.NewScanner(file)
98100
for scanner.Scan() {

0 commit comments

Comments
 (0)