@@ -159,7 +159,7 @@ func (m *ResourceClaimManager) Stop() error {
159159
160160func (m * ResourceClaimManager ) addOrUpdate (ctx context.Context , obj any ) error {
161161 rc , ok := obj .(* resourcev1.ResourceClaim )
162- if ! ok || rc == nil {
162+ if ! ok {
163163 return fmt .Errorf ("failed to cast object to ResourceClaim" )
164164 }
165165
@@ -168,13 +168,22 @@ func (m *ResourceClaimManager) addOrUpdate(ctx context.Context, obj any) error {
168168 }
169169
170170 // Check the allocationResult of ResourceClaim to determine whether it should be monitored.
171- isEligible , domainID := m .checkClaimEligibleForComputeDomainLabeling (rc )
172- if ! isEligible {
171+ req , err := m .getComputeDomainChannelRequestConfig (rc )
172+ if err != nil {
173+ return fmt .Errorf ("error getting config for ComputeDomainChannel request from ResourceClaim %s/%s: %w" , rc .Namespace , rc .Name , err )
174+ }
175+
176+ if req == nil {
173177 return nil
174178 }
175179
176- if domainID == "" {
177- return fmt .Errorf ("matching ResourceClaim %s/%s has no domainID in allocation config" , rc .Namespace , rc .Name )
180+ // Get domain id
181+ domainID := req .DomainID
182+
183+ //Check namespace
184+ err = m .AssertComputeDomainNamespace (rc .Namespace , domainID )
185+ if err != nil {
186+ return fmt .Errorf ("failed to assert Namespace for computeDomain with domainID %s and ResourceClaim %s/%s: %w" , domainID , rc .Namespace , rc .Name , err )
178187 }
179188
180189 currentAllocationTimestamp := ""
@@ -198,12 +207,6 @@ func (m *ResourceClaimManager) addOrUpdate(ctx context.Context, obj any) error {
198207 // Cancel a monitor that has already timed out.
199208 m .cancelTimeoutedMonitor (ctx , rc , rcMonitors , currentAllocationTimestamp )
200209
201- //Check namespace
202- err = m .AssertComputeDomainNamespace (rc .Namespace , domainID )
203- if err != nil {
204- return fmt .Errorf ("failed to assert Namespace for computeDomain with domainID %s and ResourceClaim %s/%s: %w" , domainID , rc .Namespace , rc .Name , err )
205- }
206-
207210 //Check if monitoring already launched and return if yes
208211 if _ , loaded := rcMonitors .Load (currentAllocationTimestamp ); loaded {
209212 return nil
@@ -300,17 +303,24 @@ func (m *ResourceClaimManager) addOrUpdate(ctx context.Context, obj any) error {
300303 return nil
301304}
302305
303- // Checks if ResourceClaim is Eligible for Compute Domain Labeling and returns domainID
304- func (m * ResourceClaimManager ) checkClaimEligibleForComputeDomainLabeling (rc * resourcev1.ResourceClaim ) (bool , string ) {
305- var domainID string
306+ // getComputeDomainChannelRequestConfig determines if a ResourceClaim is a monitoring target by filtering
307+ // the allocationResult and returns the config information associated with the target allocationResult.
308+ //
309+ // The processing target must meet the following conditions:
310+ // - The driver is "compute-domain.nvidia.com"
311+ // - The device is a channel device (determined by whether its corresponding config is ComputeDomainChannelConfig)
312+ // - The device has BindingConditions
313+ // - The device is not set any BindingConditions/BindingFailureConditions
314+ func (m * ResourceClaimManager ) getComputeDomainChannelRequestConfig (rc * resourcev1.ResourceClaim ) (* nvapi.ComputeDomainChannelConfig , error ) {
315+ var config * nvapi.ComputeDomainChannelConfig
306316
307317 configs , err := GetOpaqueDeviceConfigs (
308318 nvapi .StrictDecoder ,
309319 DriverName ,
310320 rc .Status .Allocation .Devices .Config ,
311321 )
312322 if err != nil {
313- return false , ""
323+ return nil , err
314324 }
315325
316326 var configResults []* resourcev1.DeviceRequestAllocationResult
@@ -324,8 +334,8 @@ func (m *ResourceClaimManager) checkClaimEligibleForComputeDomainLabeling(rc *re
324334 if slices .Contains (c .Requests , result .Request ) {
325335 if _ , ok := c .Config .(* nvapi.ComputeDomainChannelConfig ); ok {
326336 configResults = append (configResults , & result )
327- if domainID == "" {
328- domainID = c .Config .(* nvapi.ComputeDomainChannelConfig ). DomainID
337+ if config == nil {
338+ config = c .Config .(* nvapi.ComputeDomainChannelConfig )
329339 }
330340 break
331341 }
@@ -341,19 +351,19 @@ func (m *ResourceClaimManager) checkClaimEligibleForComputeDomainLabeling(rc *re
341351 for _ , cond := range deviceStatus .Conditions {
342352 // Check the device is not set BindingConditions
343353 if cond .Type == nvapi .ComputeDomainBindingConditions && cond .Status == metav1 .ConditionTrue {
344- return false , domainID
354+ return nil , nil
345355 }
346356 // Check the device is not set BindingFailureConditions
347357 if cond .Type == nvapi .ComputeDomainBindingFailureConditions && cond .Status == metav1 .ConditionTrue {
348- return false , domainID
358+ return nil , nil
349359 }
350360 }
351361 }
352362 }
353- return true , domainID
363+ return config , nil
354364 }
355365 }
356- return false , domainID
366+ return nil , nil
357367
358368}
359369
@@ -418,8 +428,8 @@ func (m *ResourceClaimManager) setBindingConditions(ctx context.Context, rc *res
418428 for _ , allocationDevice := range rcToUpdate .Status .Allocation .Devices .Results {
419429 device := & resourcev1.AllocatedDeviceStatus {
420430 Driver : allocationDevice .Driver ,
421- Device : allocationDevice .Device ,
422431 Pool : allocationDevice .Pool ,
432+ Device : allocationDevice .Device ,
423433 }
424434 rcToUpdate .Status .Devices = append (rcToUpdate .Status .Devices , * device )
425435 }
0 commit comments