controller

package
v0.30.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 17, 2024 License: Apache-2.0 Imports: 24 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClaimAllocation

type ClaimAllocation struct {
	PodClaimName    string
	Claim           *resourcev1alpha2.ResourceClaim
	Class           *resourcev1alpha2.ResourceClass
	ClaimParameters interface{}
	ClassParameters interface{}

	// UnsuitableNodes needs to be filled in by the driver when
	// Driver.UnsuitableNodes gets called.
	UnsuitableNodes []string

	// Driver must populate this field with resources that were
	// allocated for the claim in case of successful allocation.
	Allocation *resourcev1alpha2.AllocationResult
	// In case of error allocating particular claim, driver must
	// populate this field.
	Error error
}

ClaimAllocation represents information about one particular pod.Spec.ResourceClaim entry.

type Controller

type Controller interface {
	// Run starts the controller.
	Run(workers int)

	// SetReservedFor can be used to disable adding the Pod which
	// triggered allocation to the status.reservedFor. Normally,
	// DRA drivers should always do that, so it's the default.
	// But nothing in the protocol between the scheduler and
	// a driver requires it, so at least for testing the control
	// plane components it is useful to disable it.
	SetReservedFor(enabled bool)
}

Controller watches ResourceClaims and triggers allocation and deallocation as needed.

func New

func New(
	ctx context.Context,
	name string,
	driver Driver,
	kubeClient kubernetes.Interface,
	informerFactory informers.SharedInformerFactory) Controller

New creates a new controller.

type Driver

type Driver interface {
	// GetClassParameters is called to retrieve the parameter object
	// referenced by a class. The content should be validated now if
	// possible. class.Parameters may be nil.
	//
	// The caller wraps the error to include the parameter reference.
	GetClassParameters(ctx context.Context, class *resourcev1alpha2.ResourceClass) (interface{}, error)

	// GetClaimParameters is called to retrieve the parameter object
	// referenced by a claim. The content should be validated now if
	// possible. claim.Spec.Parameters may be nil.
	//
	// The caller wraps the error to include the parameter reference.
	GetClaimParameters(ctx context.Context, claim *resourcev1alpha2.ResourceClaim, class *resourcev1alpha2.ResourceClass, classParameters interface{}) (interface{}, error)

	// Allocate is called when all same-driver ResourceClaims for Pod are ready
	// to be allocated. The selectedNode is empty for ResourceClaims with immediate
	// allocation, in which case the resource driver decides itself where
	// to allocate. If there is already an on-going allocation, the driver
	// may finish it and ignore the new parameters or abort the on-going
	// allocation and try again with the new parameters.
	//
	// Parameters have been retrieved earlier.
	//
	// Driver must set the result of allocation for every claim in "claims"
	// parameter items. If there is no error and allocation
	// is successful - claims[i].Allocation field should be set. In case of
	// particular claim allocation failure - respective item's claims[i].Error field
	// should be set and claims[i].Allocation will be ignored.
	//
	// If selectedNode is set, the driver must attempt to allocate for that
	// node. If that is not possible, it must return an error. The
	// controller will call UnsuitableNodes and pass the new information to
	// the scheduler, which will then lead to selecting a different node
	// if the current one is not suitable.
	//
	// The Claim, ClaimParameters, Class, ClassParameters fields of "claims" parameter
	// items are read-only and must not be modified. This call must be idempotent.
	Allocate(ctx context.Context, claims []*ClaimAllocation, selectedNode string)

	// Deallocate gets called when a ResourceClaim is ready to be
	// freed.
	//
	// The claim is read-only and must not be modified. This call must be
	// idempotent. In particular it must not return an error when the claim
	// is currently not allocated.
	//
	// Deallocate may be called when a previous allocation got
	// interrupted. Deallocate must then stop any on-going allocation
	// activity and free resources before returning without an error.
	Deallocate(ctx context.Context, claim *resourcev1alpha2.ResourceClaim) error

	// UnsuitableNodes checks all pending claims with delayed allocation
	// for a pod. All claims are ready for allocation by the driver
	// and parameters have been retrieved.
	//
	// The driver may consider each claim in isolation, but it's better
	// to mark nodes as unsuitable for all claims, if all claims
	// cannot be allocated for it (for example, two GPUs requested but
	// the node only has one).
	//
	// The potentialNodes slice contains all potential nodes selected
	// by the scheduler plus the selected node. The response must
	// not contain any other nodes. Implementations do not have to
	// care about size limits in the PodSchedulingContext status, the
	// caller will handle that.
	//
	// The result of the check is in ClaimAllocation.UnsuitableNodes.
	// An error indicates that the entire check must be repeated.
	UnsuitableNodes(ctx context.Context, pod *v1.Pod, claims []*ClaimAllocation, potentialNodes []string) error
}

Driver provides the actual allocation and deallocation operations.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL