@@ -16,6 +16,13 @@ limitations under the License.
16
16
17
17
package framework
18
18
19
+ import (
20
+ resourceapi "k8s.io/api/resource/v1alpha3"
21
+ "k8s.io/apimachinery/pkg/types"
22
+ "k8s.io/apimachinery/pkg/util/sets"
23
+ "k8s.io/dynamic-resource-allocation/structured"
24
+ )
25
+
19
26
// NodeInfoLister interface represents anything that can list/get NodeInfo objects from node name.
20
27
type NodeInfoLister interface {
21
28
// List returns the list of NodeInfos.
@@ -40,3 +47,65 @@ type SharedLister interface {
40
47
NodeInfos () NodeInfoLister
41
48
StorageInfos () StorageInfoLister
42
49
}
50
+
51
+ // ResourceSliceLister can be used to obtain ResourceSlices.
52
+ type ResourceSliceLister interface {
53
+ // List returns a list of all ResourceSlices.
54
+ List () ([]* resourceapi.ResourceSlice , error )
55
+ }
56
+
57
+ // DeviceClassLister can be used to obtain DeviceClasses.
58
+ type DeviceClassLister interface {
59
+ // List returns a list of all DeviceClasses.
60
+ List () ([]* resourceapi.DeviceClass , error )
61
+ // Get returns the DeviceClass with the given className.
62
+ Get (className string ) (* resourceapi.DeviceClass , error )
63
+ }
64
+
65
+ // ResourceClaimTracker can be used to obtain ResourceClaims, and track changes to ResourceClaims in-memory.
66
+ //
67
+ // If the claims are meant to be allocated in the API during the binding phase (when used by scheduler), the tracker helps avoid
68
+ // race conditions between scheduling and binding phases (as well as between the binding phase and the informer cache update).
69
+ //
70
+ // If the binding phase is not run (e.g. when used by Cluster Autoscaler which only runs the scheduling phase, and simulates binding in-memory),
71
+ // the tracker allows the framework user to obtain the claim allocations produced by the DRA plugin, and persist them outside of the API (e.g. in-memory).
72
+ type ResourceClaimTracker interface {
73
+ // List lists ResourceClaims. The result is guaranteed to immediately include any changes made via AssumeClaimAfterAPICall(),
74
+ // and SignalClaimPendingAllocation().
75
+ List () ([]* resourceapi.ResourceClaim , error )
76
+ // Get works like List(), but for a single claim.
77
+ Get (namespace , claimName string ) (* resourceapi.ResourceClaim , error )
78
+ // ListAllAllocatedDevices lists all allocated Devices from allocated ResourceClaims. The result is guaranteed to immediately include
79
+ // any changes made via AssumeClaimAfterAPICall(), and SignalClaimPendingAllocation().
80
+ ListAllAllocatedDevices () (sets.Set [structured.DeviceID ], error )
81
+
82
+ // SignalClaimPendingAllocation signals to the tracker that the given ResourceClaim will be allocated via an API call in the
83
+ // binding phase. This change is immediately reflected in the result of List() and the other accessors.
84
+ SignalClaimPendingAllocation (claimUID types.UID , allocatedClaim * resourceapi.ResourceClaim ) error
85
+ // ClaimHasPendingAllocation answers whether a given claim has a pending allocation during the binding phase. It can be used to avoid
86
+ // race conditions in subsequent scheduling phases.
87
+ ClaimHasPendingAllocation (claimUID types.UID ) bool
88
+ // RemoveClaimPendingAllocation removes the pending allocation for the given ResourceClaim from the tracker if any was signaled via
89
+ // SignalClaimPendingAllocation(). Returns whether there was a pending allocation to remove. List() and the other accessors immediately
90
+ // stop reflecting the pending allocation in the results.
91
+ RemoveClaimPendingAllocation (claimUID types.UID ) (deleted bool )
92
+
93
+ // AssumeClaimAfterAPICall signals to the tracker that an API call modifying the given ResourceClaim was made in the binding phase, and the
94
+ // changes should be reflected in informers very soon. This change is immediately reflected in the result of List() and the other accessors.
95
+ // This mechanism can be used to avoid race conditions between the informer update and subsequent scheduling phases.
96
+ AssumeClaimAfterAPICall (claim * resourceapi.ResourceClaim ) error
97
+ // AssumedClaimRestore signals to the tracker that something went wrong with the API call modifying the given ResourceClaim, and
98
+ // the changes won't be reflected in informers after all. List() and the other accessors immediately stop reflecting the assumed change,
99
+ // and go back to the informer version.
100
+ AssumedClaimRestore (namespace , claimName string )
101
+ }
102
+
103
+ // SharedDRAManager can be used to obtain DRA objects, and track modifications to them in-memory - mainly by the DRA plugin.
104
+ // The plugin's default implementation obtains the objects from the API. A different implementation can be
105
+ // plugged into the framework in order to simulate the state of DRA objects. For example, Cluster Autoscaler
106
+ // can use this to provide the correct DRA object state to the DRA plugin when simulating scheduling changes in-memory.
107
+ type SharedDRAManager interface {
108
+ ResourceClaims () ResourceClaimTracker
109
+ ResourceSlices () ResourceSliceLister
110
+ DeviceClasses () DeviceClassLister
111
+ }
0 commit comments