Skip to content

Commit 8dfe9cf

Browse files
committed
address review: fix args
Signed-off-by: Swati Gupta <swatig@nvidia.com>
1 parent 4bd9e90 commit 8dfe9cf

4 files changed

Lines changed: 14 additions & 22 deletions

File tree

cmd/gpu-kubelet-plugin/allocatable.go

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -326,31 +326,23 @@ func (d *AllocatableDevice) Taints() []resourceapi.DeviceTaint {
326326
// (e.g., XID 48 followed by XID 63), the value is overwritten and only the most recent event data is retained.
327327
// Returns true if the taint set was modified.
328328
func (d *AllocatableDevice) AddOrUpdateTaint(taint *resourceapi.DeviceTaint) bool {
329-
t := *taint
330329
for i, existing := range d.taints {
331-
if existing.Key == t.Key {
332-
changed := false
330+
if existing.Key == taint.Key {
333331

334-
// Overwrite Value if it changed
335-
if existing.Value != t.Value {
336-
d.taints[i].Value = t.Value
337-
changed = true
332+
// 1. If nothing actually changed, exit early to avoid API calls
333+
if existing.Value == taint.Value && existing.Effect == taint.Effect {
334+
return false
338335
}
339336

340-
if existing.Effect != t.Effect {
341-
d.taints[i].Effect = t.Effect
342-
changed = true
343-
}
344-
345-
if changed {
346-
d.taints[i].TimeAdded = nil // reset timestamp for the API server
347-
}
348-
349-
return changed
337+
// 2. Otherwise, update the fields and the timestamp
338+
d.taints[i].Value = taint.Value
339+
d.taints[i].Effect = taint.Effect
340+
d.taints[i].TimeAdded = nil // reset timestamp for the API server
341+
return true
350342
}
351343
}
352344

353-
// Key doesn't exist yet, append the new taint
354-
d.taints = append(d.taints, t)
345+
// 3. Key doesn't exist yet, append the dereferenced struct
346+
d.taints = append(d.taints, *taint)
355347
return true
356348
}

cmd/gpu-kubelet-plugin/device_health.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ type DeviceHealthEvent struct {
7272
// healthEventToTaint maps a DeviceHealthEvent to the corresponding DRA
7373
// DeviceTaint using the Option A taint key schema: one key per health
7474
// dimension under the gpu.nvidia.com domain.
75-
func healthEventToTaint(event *DeviceHealthEvent, monitor deviceHealthMonitor) *resourceapi.DeviceTaint {
75+
func healthEventToTaint(monitor deviceHealthMonitor, event *DeviceHealthEvent) *resourceapi.DeviceTaint {
7676
switch event.EventType {
7777
case HealthEventXID:
7878
effect := resourceapi.DeviceTaintEffectNoSchedule

cmd/gpu-kubelet-plugin/device_health_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ func TestHealthEventToTaint(t *testing.T) {
224224

225225
for _, tc := range tests {
226226
t.Run(tc.name, func(t *testing.T) {
227-
taint := healthEventToTaint(tc.event, tc.monitor)
227+
taint := healthEventToTaint(tc.monitor, tc.event)
228228
assert.Equal(t, tc.expectedKey, taint.Key)
229229
assert.Equal(t, tc.expectedValue, taint.Value)
230230
assert.Equal(t, tc.expectedEffect, taint.Effect)

cmd/gpu-kubelet-plugin/driver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ func (d *driver) deviceHealthEvents(ctx context.Context, nodeName string) {
471471
return
472472
}
473473

474-
taint := healthEventToTaint(event, d.deviceHealthMonitor)
474+
taint := healthEventToTaint(d.deviceHealthMonitor, event)
475475
modified := false
476476
for _, dev := range event.Devices {
477477
klog.Warningf("Received %s health event for device %s", event.EventType, dev.UUID())

0 commit comments

Comments
 (0)