@@ -27,7 +27,8 @@ import (
2727 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2828 "k8s.io/apimachinery/pkg/runtime"
2929 "k8s.io/apimachinery/pkg/runtime/serializer/json"
30- resourceapply "k8s.io/client-go/applyconfigurations/resource/v1"
30+ "k8s.io/client-go/util/retry"
31+ draclient "k8s.io/dynamic-resource-allocation/client"
3132 "k8s.io/dynamic-resource-allocation/resourceslice"
3233
3334 "k8s.io/klog/v2"
@@ -217,7 +218,7 @@ func (s *DeviceState) prepareDevices(ctx context.Context, claim *resourceapi.Res
217218 configs = slices .Insert (configs , 0 , & OpaqueDeviceConfig {})
218219
219220 // build device status
220- var devicesStatus []* resourceapply. AllocatedDeviceStatusApplyConfiguration
221+ var devicesStatus []resourceapi. AllocatedDeviceStatus
221222
222223 // Look through the configs and figure out which one will be applied to
223224 // each device allocation result based on their order of precedence.
@@ -251,7 +252,7 @@ func (s *DeviceState) prepareDevices(ctx context.Context, claim *resourceapi.Res
251252 for config , results := range configResultsMap {
252253 if s .config .flags .deviceAttribute {
253254 klog .Infof ("Adding device attribute to claim %s/%s" , claim .Namespace , claim .Name )
254- if err := s .applyDeviceStatus (ctx , claim .Namespace , claim .Name , devicesStatus ... ); err != nil {
255+ if err := s .updateDeviceStatus (ctx , claim .Namespace , claim .Name , devicesStatus ... ); err != nil {
255256 klog .Warningf ("Failed to update device attributes for claim %s/%s: %v" , claim .Namespace , claim .Name , err )
256257 }
257258 }
@@ -359,7 +360,7 @@ func GetOpaqueDeviceConfigs(
359360 return resultConfigs , nil
360361}
361362
362- func (s * DeviceState ) buildDeviceStatus (res resourceapi.DeviceRequestAllocationResult ) * resourceapply. AllocatedDeviceStatusApplyConfiguration {
363+ func (s * DeviceState ) buildDeviceStatus (res resourceapi.DeviceRequestAllocationResult ) resourceapi. AllocatedDeviceStatus {
363364 dn := res .Device
364365 deviceInfo := make (map [string ]resourceapi.DeviceAttribute )
365366
@@ -380,30 +381,39 @@ func (s *DeviceState) buildDeviceStatus(res resourceapi.DeviceRequestAllocationR
380381 klog .Errorf ("Failed to marshal device data: %v" , err )
381382 jsonBytes = []byte ("{}" )
382383 }
383- data := runtime.RawExtension {
384- Raw : jsonBytes ,
385- }
386384
387- return resourceapply .AllocatedDeviceStatus ().
388- WithDevice ( dn ).
389- WithDriver ( res .Driver ).
390- WithPool ( res .Pool ).
391- // WithData records per-allocation metadata used for monitoring and debugging:
385+ return resourceapi .AllocatedDeviceStatus {
386+ Device : dn ,
387+ Driver : res .Driver ,
388+ Pool : res .Pool ,
389+ // Data records per-allocation metadata used for monitoring and debugging:
392390 // - Pod→GPU mapping: makes it easier to see which GPU a given pod is using,
393391 // which is not readily available elsewhere.
394392 // - Device attributes (e.g. UUID, model, driverVersion): remain available
395393 // even if the device is later removed from a ResourceSlice (for example,
396394 // because it becomes unhealthy), so past allocations can still be
397395 // correlated with later health or scheduling issues.
398- WithData (data )
396+ Data : & runtime.RawExtension {Raw : jsonBytes },
397+ }
399398}
400399
401- func (s * DeviceState ) applyDeviceStatus (ctx context.Context , ns , name string , devices ... * resourceapply.AllocatedDeviceStatusApplyConfiguration ) error {
402- claim := resourceapply .ResourceClaim (name , ns ).
403- WithStatus (resourceapply .ResourceClaimStatus ().WithDevices (devices ... ))
400+ func (s * DeviceState ) updateDeviceStatus (ctx context.Context , ns , name string , devices ... resourceapi.AllocatedDeviceStatus ) error {
401+ // Converting wrapper to use latest API types,
402+ // converts to/from server-supported version.
403+ c := draclient .New (s .config .coreclient )
404+ rc := c .ResourceClaims (ns )
405+
406+ return retry .RetryOnConflict (retry .DefaultRetry , func () error {
407+ claim , err := rc .Get (ctx , name , metav1.GetOptions {})
408+ if err != nil {
409+ return err
410+ }
404411
405- opts := metav1.ApplyOptions {FieldManager : s .config .flags .driverName , Force : true }
412+ // copy the object and update only status.devices
413+ claim = claim .DeepCopy ()
414+ claim .Status .Devices = devices
406415
407- _ , err := s .config .coreclient .ResourceV1 ().ResourceClaims (ns ).ApplyStatus (ctx , claim , opts )
408- return err
416+ _ , err = rc .UpdateStatus (ctx , claim , metav1.UpdateOptions {})
417+ return err
418+ })
409419}
0 commit comments