dra

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package dra implements a DRA (Dynamic Resource Allocation) kubelet plugin.

The package owns the kubelet-facing plumbing of the driver: registration, the gRPC lifecycle, publishing ResourceSlices and the mechanics of CDI spec files. It does not know what any of the devices it publishes mean. Which devices exist, what their attributes say, which resources a claim gets and what ends up in its CDI edits are all decided by the active policy.

The plugin is owned by the resource manager, not by a policy, the same way the NRI plugin is: the resource manager constructs it, starts and stops it, and passes itself as the Locker so that kubelet-initiated requests serialize against the NRI-initiated ones.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClaimConfigs

ClaimConfigs returns the device class and claim configs, class configs first.

func ClaimOfCDIDevice

func ClaimOfCDIDevice(qualifiedName string) (driver string, uid types.UID, index int, ok bool)

ClaimOfCDIDevice returns the driver, the claim UID and the index of the allocation result of a CDI device written for a prepared claim. ok is false for any other device.

func ContainerClaims

func ContainerClaims(c cache.Container, driver string) map[types.UID][]int

ContainerClaims returns the claims of the given driver a container holds, with the indexes of the allocation results of each claim it holds. A container which names some requests of a claim holds only their results.

func DriverName

func DriverName(policyName string) string

DriverName returns the name of the DRA driver of the named policy.

Types

type Options

type Options struct {
	// NodeName is the node this plugin publishes resources for. Required.
	NodeName string
	// KubeClient is used to publish ResourceSlices. Required.
	KubeClient kubernetes.Interface
	// Owner is who we serialize kubelet requests against and ask to shut us
	// down. Required.
	Owner Owner
	// Policy allocates the resources of the claims we prepare. Required.
	Policy policy.Policy
	// RegistrarDir is where the plugin registration socket is created.
	// Empty selects the kubelet's registry directory.
	RegistrarDir string
	// PluginDataDir is where the plugin's own socket is created.
	// Empty selects the driver's directory under the kubelet plugin directory.
	PluginDataDir string
	// CDIDir is where the CDI specs of prepared claims are written.
	// Empty selects the CDI directory runtimes watch for generated specs.
	CDIDir string
}

Options are the parameters New needs beyond the driver name.

type Owner

type Owner interface {
	// The plugin takes the lock for every kubelet request.
	sync.Locker
	// ClaimAllocated and ClaimReleased commit an allocation change the policy
	// just made for a claim. They are called with the lock held, once per
	// claim, and they are what make the change outlive us and reach the
	// containers it affects. An error from ClaimAllocated means the claim's
	// resources may still be in use by other containers.
	ClaimAllocated() error
	ClaimReleased() error
	// RequestShutdown asks the owner to shut down, for errors the plugin cannot
	// recover from. It runs on the very goroutine whose failure it reports, and
	// Stop() waits for that goroutine, so it must not stop us from there: it
	// has to return and leave that to the shutdown it triggers.
	RequestShutdown(reason string)
}

Owner is what the plugin needs from whoever owns it.

type Plugin

type Plugin struct {
	// contains filtered or unexported fields
}

Plugin is a DRA kubelet plugin.

func New

func New(driverName string, opts Options) (*Plugin, error)

New creates a plugin for the named DRA driver.

func (*Plugin) AllowClaims

func (p *Plugin) AllowClaims()

AllowClaims lets the plugin serve claims. The driver is registered with the kubelet as soon as the plugin starts, but a claim must not be allocated while the owner is still synchronizing its own state with the container runtime: the allocation would run concurrently with that synchronization, and a commit made during it does not stick. The owner calls this once it has synchronized.

Until then claims are refused with an error, which costs nothing but a retry: the kubelet asks again, and a pod needing a claim cannot start before the containers already running have been synchronized anyway.

func (*Plugin) HandleError

func (p *Plugin) HandleError(_ context.Context, err error, msg string)

HandleError handles errors the kubeletplugin helper runs into in the background. A failed ResourceSlice publication is recoverable, the helper retries it, so logging it is enough. Anything else is one of the helper's gRPC servers giving up: the driver stays registered with kubelet but can no longer serve it, and nothing we do here would bring it back, so we ask our owner to shut down.

func (*Plugin) ListAttributesSupported

func (p *Plugin) ListAttributesSupported() bool

ListAttributesSupported tells whether the API server accepts device attributes with a list of values. False if DRA is off.

func (*Plugin) PrepareResourceClaims

func (p *Plugin) PrepareResourceClaims(_ context.Context, claims []*resourceapi.ResourceClaim) (map[types.UID]kubeletplugin.PrepareResult, error)

PrepareResourceClaims prepares the given claims: the policy allocates the resources of each claim and we hand the kubelet the CDI devices which grant them to the containers using the claim.

Every claim is answered on its own. The kubelet asks for all the claims of a pod in a single request, but it records the answer per claim and retries the ones which failed, so failing them all together would only throw away the claims we did prepare.

func (*Plugin) Publish

func (p *Plugin) Publish(devices []resourceapi.Device) error

Publish replaces the published devices with the given ones. Devices published before the plugin is started get published when it starts.

func (*Plugin) Start

func (p *Plugin) Start(ctx context.Context) error

Start registers the plugin with the kubelet and publishes its resources.

func (*Plugin) Stop

func (p *Plugin) Stop()

Stop unregisters the plugin and stops serving kubelet requests. Stop must not be called with the Locker held: a request in flight holds the Locker and Stop waits for it to finish.

func (*Plugin) UnprepareResourceClaims

func (p *Plugin) UnprepareResourceClaims(_ context.Context, claims []kubeletplugin.NamespacedObject) (map[types.UID]error, error)

UnprepareResourceClaims releases the resources prepared for the given claims.

func (*Plugin) WatchHealthStatus

func (p *Plugin) WatchHealthStatus(_ context.Context, _ chan<- kubeletplugin.DeviceHealthReport) error

WatchHealthStatus declines to report device health. Our devices are the node's own CPUs and memory: the kubelet already knows whether the node is healthy, and there is nothing per-device we could tell it that it does not know. Declining makes the kubelet stop asking.

Jump to

Keyboard shortcuts

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