Skip to content

Commit 09aa883

Browse files
[no-relnote] Fix copylocks: use pointer receivers and avoid Device struct copies
Signed-off-by: Carlos Eduardo Arango Gutierrez <[email protected]>
1 parent c88d0d4 commit 09aa883

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

internal/rm/device_map.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/NVIDIA/go-nvlib/pkg/nvlib/info"
2424
"github.com/NVIDIA/go-nvml/pkg/nvml"
2525
"k8s.io/klog/v2"
26+
pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
2627

2728
spec "github.com/NVIDIA/k8s-device-plugin/api/config/v1"
2829
)
@@ -324,9 +325,19 @@ func updateDeviceMapWithReplicas(replicatedResources *spec.ReplicatedResources,
324325
for _, id := range ids {
325326
for i := 0; i < r.Replicas; i++ {
326327
annotatedID := string(NewAnnotatedID(id, i))
327-
replicatedDevice := *(oDevices[r.Name][id])
328-
replicatedDevice.ID = annotatedID
329-
replicatedDevice.Replicas = r.Replicas
328+
original := oDevices[r.Name][id]
329+
replicatedDevice := Device{
330+
Device: pluginapi.Device{
331+
ID: annotatedID,
332+
Health: original.Health,
333+
Topology: original.Topology,
334+
},
335+
Paths: original.Paths,
336+
Index: original.Index,
337+
TotalMemory: original.TotalMemory,
338+
ComputeCapability: original.ComputeCapability,
339+
Replicas: r.Replicas,
340+
}
330341
devices.insert(name, &replicatedDevice)
331342
}
332343
}

internal/rm/devices.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,9 @@ func (ds Devices) AlignedAllocationSupported() bool {
213213
return true
214214
}
215215

216-
// AlignedAllocationSupported checks whether the device supports an aligned allocation
217-
func (d Device) AlignedAllocationSupported() bool {
216+
// AlignedAllocationSupported checks whether the device supports an aligned
217+
// allocation
218+
func (d *Device) AlignedAllocationSupported() bool {
218219
if d.IsMigDevice() {
219220
return false
220221
}
@@ -229,12 +230,12 @@ func (d Device) AlignedAllocationSupported() bool {
229230
}
230231

231232
// IsMigDevice returns checks whether d is a MIG device or not.
232-
func (d Device) IsMigDevice() bool {
233+
func (d *Device) IsMigDevice() bool {
233234
return strings.Contains(d.Index, ":")
234235
}
235236

236237
// GetUUID returns the UUID for the device from the annotated ID.
237-
func (d Device) GetUUID() string {
238+
func (d *Device) GetUUID() string {
238239
return AnnotatedID(d.ID).GetID()
239240
}
240241

0 commit comments

Comments
 (0)