BeRegistered checks that plugin registration has completed.
var BeRegistered = gcustom.MakeMatcher(func(actualCalls []GRPCCall) (bool, error) { for _, call := range actualCalls { if call.FullMethod == "/pluginregistration.Registration/NotifyRegistrationStatus" && call.Err == nil { return true, nil } } return false, nil }).WithMessage("contain successful NotifyRegistrationStatus call")
NodePrepareResouceCalled checks that NodePrepareResource API has been called
var NodePrepareResourceCalled = gcustom.MakeMatcher(func(actualCalls []GRPCCall) (bool, error) { for _, call := range actualCalls { if strings.HasSuffix(call.FullMethod, "/NodePrepareResource") && call.Err == nil { return true, nil } } return false, nil }).WithMessage("contain NodePrepareResource call")
NodePrepareResoucesCalled checks that NodePrepareResources API has been called
var NodePrepareResourcesCalled = gcustom.MakeMatcher(func(actualCalls []GRPCCall) (bool, error) { for _, call := range actualCalls { if strings.HasSuffix(call.FullMethod, "/NodePrepareResources") && call.Err == nil { return true, nil } } return false, nil }).WithMessage("contain NodePrepareResources call")
func NewCommand() *cobra.Command
NewCommand creates a *cobra.Command object with default parameters.
type AllocateWrapperType func(ctx context.Context, claimAllocations []*controller.ClaimAllocation, selectedNode string, handler func(ctx context.Context, claimAllocations []*controller.ClaimAllocation, selectedNode string), )
ClaimID contains both claim name and UID to simplify debugging. The namespace is not included because it is random in E2E tests and the UID is sufficient to make the ClaimID unique.
type ClaimID struct { Name string UID string }
type ExampleController struct {
// contains filtered or unexported fields
}
func NewController(clientset kubernetes.Interface, resources Resources) *ExampleController
func (c *ExampleController) Allocate(ctx context.Context, claimAllocations []*controller.ClaimAllocation, selectedNode string)
func (c *ExampleController) Deallocate(ctx context.Context, claim *resourcev1alpha2.ResourceClaim) error
func (c *ExampleController) GetClaimParameters(ctx context.Context, claim *resourcev1alpha2.ResourceClaim, class *resourcev1alpha2.ResourceClass, classParameters interface{}) (interface{}, error)
func (c *ExampleController) GetClassParameters(ctx context.Context, class *resourcev1alpha2.ResourceClass) (interface{}, error)
func (c *ExampleController) GetNumAllocations() int64
GetNumAllocations returns the number of times that a claim was allocated. Idempotent calls to Allocate that do not need to allocate the claim again do not contribute to that counter.
func (c *ExampleController) GetNumDeallocations() int64
GetNumDeallocations returns the number of times that a claim was allocated. Idempotent calls to Allocate that do not need to allocate the claim again do not contribute to that counter.
func (c *ExampleController) Run(ctx context.Context, workers int)
func (c *ExampleController) UnsuitableNodes(ctx context.Context, pod *v1.Pod, claims []*controller.ClaimAllocation, potentialNodes []string) (finalErr error)
type ExamplePlugin struct {
// contains filtered or unexported fields
}
func StartPlugin(ctx context.Context, cdiDir, driverName string, nodeName string, fileOps FileOperations, opts ...kubeletplugin.Option) (*ExamplePlugin, error)
StartPlugin sets up the servers that are necessary for a DRA kubelet plugin.
func (ex *ExamplePlugin) Block()
Block sets a flag to block Node[Un]PrepareResources to emulate time consuming or stuck calls
func (ex *ExamplePlugin) GetGRPCCalls() []GRPCCall
func (ex *ExamplePlugin) GetPreparedResources() []ClaimID
func (ex *ExamplePlugin) IsRegistered() bool
func (ex *ExamplePlugin) NodeListAndWatchResources(req *drapbv1alpha3.NodeListAndWatchResourcesRequest, stream drapbv1alpha3.Node_NodeListAndWatchResourcesServer) error
func (ex *ExamplePlugin) NodePrepareResource(ctx context.Context, req *drapbv1alpha2.NodePrepareResourceRequest) (*drapbv1alpha2.NodePrepareResourceResponse, error)
NodePrepareResource ensures that the CDI file for the claim exists. It uses a deterministic name to simplify NodeUnprepareResource (no need to remember or discover the name) and idempotency (when called again, the file simply gets written again).
func (ex *ExamplePlugin) NodePrepareResources(ctx context.Context, req *drapbv1alpha3.NodePrepareResourcesRequest) (*drapbv1alpha3.NodePrepareResourcesResponse, error)
func (ex *ExamplePlugin) NodeUnprepareResource(ctx context.Context, req *drapbv1alpha2.NodeUnprepareResourceRequest) (*drapbv1alpha2.NodeUnprepareResourceResponse, error)
NodeUnprepareResource removes the CDI file created by NodePrepareResource. It's idempotent, therefore it is not an error when that file is already gone.
func (ex *ExamplePlugin) NodeUnprepareResources(ctx context.Context, req *drapbv1alpha3.NodeUnprepareResourcesRequest) (*drapbv1alpha3.NodeUnprepareResourcesResponse, error)
func (ex *ExamplePlugin) Stop()
stop ensures that all servers are stopped and resources freed.
FileOperations defines optional callbacks for handling CDI files and some other configuration.
type FileOperations struct { // Create must overwrite the file. Create func(name string, content []byte) error // Remove must remove the file. It must not return an error when the // file does not exist. Remove func(name string) error // NumResourceInstances determines whether the plugin reports resources // instances and how many. A negative value causes it to report "not implemented" // in the NodeListAndWatchResources gRPC call. NumResourceInstances int }
type GRPCCall struct { // FullMethod is the fully qualified, e.g. /package.service/method. FullMethod string // Request contains the parameters of the call. Request interface{} // Response contains the reply of the plugin. It is nil for calls that are in progress. Response interface{} // Err contains the error return value of the plugin. It is nil for calls that are in progress or succeeded. Err error }
type Resources struct { DriverName string DontSetReservedFor bool NodeLocal bool // Nodes is a fixed list of node names on which resources are // available. Mutually exclusive with NodeLabels. Nodes []string // NodeLabels are labels which determine on which nodes resources are // available. Mutually exclusive with Nodes. NodeLabels labels.Set MaxAllocations int Shareable bool // AllocateWrapper, if set, gets called for each Allocate call. AllocateWrapper AllocateWrapperType }
func (r Resources) AllNodes(nodeLister listersv1.NodeLister) []string
func (r Resources) NewAllocation(node string, data []byte) *resourcev1alpha2.AllocationResult