Files
kubernetes/pkg/scheduler/framework
胡玮文 ed19492dc2 scheduler/volumebinding: passive assume cache
Currently volume and dynamic-resource plugin shares an AssumeCache
implementation. However, they features significantly different use case.  DRA
call Assume() on objects returned by APIServer, but volume call Assume() on
objects yet to be sent to the APIServer.

VolumeBinding plugin only makes one update request, while DynamicResource makes
2 requests (add finalizer then update allocation status).  Taking advantage of
this, currently the volume cache is simpler:

1. Reserve: assume PV/PVC will be updated
2. PreBind: really send the update request
3. AssumeCache receives an update from informer and overwrite the assumed state.
   a. if Prebind succeeded, this will surely include the update from step 2.
   b. if PreBind is not finished yet, and this is an irrelevant update, it is safe to
      overwrite the assumed state, because our update in PreBind will surely fail with Conflict.

While for DynamicResource:

1. Reserve: add devices to inFlightAllocations
2. PreBind:
   a. send the 2 update requests
   b. add the returned object into AssumeCache
   c. AssumeCache dispatch events synchronously to update allocatedDevices
   d. remove devices from inFlightAllocations

DynamicResource needs some features from AssumeCache that is not necessary for VolumeBinding:
1. DynamicResource needs strictly ordered update events to update allocatedDevices,
   including those from Assume() and Restore()
2. DynamicResource needs to compare ResourceVersion to prevent the assumed state from being
   overwritten by older version from informer.  While this works, the doc[1] says:
   "you must not compare resource versions for greater-than or less-than relationships".

Given so much difference, it can be beneficial to fork another simpler
AssumeCache for VolumeBinding plugin. Because of no need to send events, the
lite AssumeCache is a passive component. It only record the assumed version
without copying all objects from informer into its local cache. When reading,
we read from both informer and local cache.  So it will always be up-to-date
with informer, no need to wait for event handler.

This resolves a race condition where AssumeCache and scheduler queue both
receive events from informer. When a pod is scheduling due to PV update event,
the PVCache may be not updated yet because it has not processed the relevant
event.

The passive version still listens events from informer, but only for cleaning up
its local cache to save memory.

[1]: https://kubernetes.io/docs/reference/using-api/api-concepts/#resource-versions
2025-09-13 00:26:45 +08:00
..
2025-07-28 23:12:58 +09:00
2025-07-30 09:52:49 +09:00