@@ -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"
@@ -222,7 +223,7 @@ func (s *DeviceState) prepareDevices(ctx context.Context, claim *resourceapi.Res
222223 configs = slices .Insert (configs , 0 , & OpaqueDeviceConfig {})
223224
224225 // build device status
225- var devicesStatus []* resourceapply. AllocatedDeviceStatusApplyConfiguration
226+ var devicesStatus []resourceapi. AllocatedDeviceStatus
226227
227228 // Look through the configs and figure out which one will be applied to
228229 // each device allocation result based on their order of precedence.
@@ -256,7 +257,7 @@ func (s *DeviceState) prepareDevices(ctx context.Context, claim *resourceapi.Res
256257 for config , results := range configResultsMap {
257258 if s .config .flags .deviceAttribute {
258259 klog .Infof ("Adding device attribute to claim %s/%s" , claim .Namespace , claim .Name )
259- if err := s .applyDeviceStatus (ctx , claim .Namespace , claim .Name , devicesStatus ... ); err != nil {
260+ if err := s .updateDeviceStatus (ctx , claim .Namespace , claim .Name , devicesStatus ... ); err != nil {
260261 klog .Warningf ("Failed to update device attributes for claim %s/%s: %v" , claim .Namespace , claim .Name , err )
261262 }
262263 }
@@ -377,7 +378,7 @@ func GetOpaqueDeviceConfigs(
377378 return resultConfigs , nil
378379}
379380
380- func (s * DeviceState ) buildDeviceStatus (res resourceapi.DeviceRequestAllocationResult ) * resourceapply. AllocatedDeviceStatusApplyConfiguration {
381+ func (s * DeviceState ) buildDeviceStatus (res resourceapi.DeviceRequestAllocationResult ) resourceapi. AllocatedDeviceStatus {
381382 dn := res .Device
382383 deviceInfo := make (map [string ]resourceapi.DeviceAttribute )
383384
@@ -398,30 +399,39 @@ func (s *DeviceState) buildDeviceStatus(res resourceapi.DeviceRequestAllocationR
398399 klog .Errorf ("Failed to marshal device data: %v" , err )
399400 jsonBytes = []byte ("{}" )
400401 }
401- data := runtime.RawExtension {
402- Raw : jsonBytes ,
403- }
404402
405- return resourceapply .AllocatedDeviceStatus ().
406- WithDevice ( dn ).
407- WithDriver ( res .Driver ).
408- WithPool ( res .Pool ).
409- // WithData records per-allocation metadata used for monitoring and debugging:
403+ return resourceapi .AllocatedDeviceStatus {
404+ Device : dn ,
405+ Driver : res .Driver ,
406+ Pool : res .Pool ,
407+ // Data records per-allocation metadata used for monitoring and debugging:
410408 // - Pod→GPU mapping: makes it easier to see which GPU a given pod is using,
411409 // which is not readily available elsewhere.
412410 // - Device attributes (e.g. UUID, model, driverVersion): remain available
413411 // even if the device is later removed from a ResourceSlice (for example,
414412 // because it becomes unhealthy), so past allocations can still be
415413 // correlated with later health or scheduling issues.
416- WithData (data )
414+ Data : & runtime.RawExtension {Raw : jsonBytes },
415+ }
417416}
418417
419- func (s * DeviceState ) applyDeviceStatus (ctx context.Context , ns , name string , devices ... * resourceapply.AllocatedDeviceStatusApplyConfiguration ) error {
420- claim := resourceapply .ResourceClaim (name , ns ).
421- WithStatus (resourceapply .ResourceClaimStatus ().WithDevices (devices ... ))
418+ func (s * DeviceState ) updateDeviceStatus (ctx context.Context , ns , name string , devices ... resourceapi.AllocatedDeviceStatus ) error {
419+ // Converting wrapper to use latest API types,
420+ // converts to/from server-supported version.
421+ c := draclient .New (s .config .coreclient )
422+ rc := c .ResourceClaims (ns )
423+
424+ return retry .RetryOnConflict (retry .DefaultRetry , func () error {
425+ claim , err := rc .Get (ctx , name , metav1.GetOptions {})
426+ if err != nil {
427+ return err
428+ }
422429
423- opts := metav1.ApplyOptions {FieldManager : s .config .flags .driverName , Force : true }
430+ // copy the object and update only status.devices
431+ claim = claim .DeepCopy ()
432+ claim .Status .Devices = devices
424433
425- _ , err := s .config .coreclient .ResourceV1 ().ResourceClaims (ns ).ApplyStatus (ctx , claim , opts )
426- return err
434+ _ , err = rc .UpdateStatus (ctx , claim , metav1.UpdateOptions {})
435+ return err
436+ })
427437}
0 commit comments