kubernetesk8s.io/kubernetes/test/e2e/dra/utils Index | Files

package utils

import "k8s.io/kubernetes/test/e2e/dra/utils"

Index

Functions

func DriverResources

func DriverResources(maxAllocations int, devicesPerNode ...map[string]map[resourceapi.QualifiedName]resourceapi.DeviceAttribute) driverResourcesGenFunc

func DriverResourcesNow

func DriverResourcesNow(nodes *Nodes, maxAllocations int, devicesPerNode ...map[string]map[resourceapi.QualifiedName]resourceapi.DeviceAttribute) map[string]resourceslice.DriverResources

func ExtendedResourceName

func ExtendedResourceName(i int) string

ExtendedResourceName returns hard coded extended resource name with a variable suffix from the input integer when it's greater than or equal to 0. "example.com/resource" is not special, any valid extended resource name can be used instead, except when using example device plugin in the test, which hard coded it, see test/e2e/dra/deploy_device_plugin.go. i == -1 is special, the extended resource name has no extra suffix, it is used in the test where a cluster has both DRA driver and device plugin.

func NetworkResources

func NetworkResources(maxAllocations int, tainted bool) driverResourcesGenFunc

func TaintAllDevices

func TaintAllDevices(taints ...resourceapi.DeviceTaint) driverResourcesMutatorFunc

func TestContainerEnv

func TestContainerEnv(ctx context.Context, f *framework.Framework, pod *v1.Pod, containerName string, fullMatch bool, env ...string)

func ToDriverResources

func ToDriverResources(counters []resourceapi.CounterSet, devices ...resourceapi.Device) driverResourcesGenFunc

Types

type Builder

type Builder struct {
	UseExtendedResourceName bool

	ClassParameters string // JSON
	// contains filtered or unexported fields
}

Builder contains a running counter to make objects unique within thir namespace.

func NewBuilder

func NewBuilder(f *framework.Framework, driver *Driver) *Builder

func NewBuilderNow

func NewBuilderNow(ctx context.Context, f *framework.Framework, driver *Driver) *Builder

func (*Builder) ClaimSpec

func (b *Builder) ClaimSpec() resourceapi.ResourceClaimSpec

claimSpecWithV1beta2 returns the device request for a claim or claim template with the associated config using the latest API.

func (*Builder) Class

func (b *Builder) Class(i int) *resourceapi.DeviceClass

Class returns the device Class that the builder's other objects reference. The input i is used to pick the extended resource name whose suffix has the same i for the device class. i == -1 is special, the extended resource name has no extra suffix, it is used in the test where a cluster has both DRA driver and device plugin.

func (*Builder) ClassName

func (b *Builder) ClassName() string

ClassName returns the default device class name.

func (*Builder) ClientV1

func (b *Builder) ClientV1() cgoresource.ResourceV1Interface

ClientV1 returns a wrapper for client-go which provides the V1 API on top of whatever is enabled in the cluster.

func (*Builder) Create

func (b *Builder) Create(ctx context.Context, objs ...klog.KMetadata) []klog.KMetadata

Create takes a bunch of objects and calls their Create function.

func (*Builder) DeletePodAndWaitForNotFound

func (b *Builder) DeletePodAndWaitForNotFound(ctx context.Context, pod *v1.Pod)

func (*Builder) ExternalClaim

func (b *Builder) ExternalClaim() *resourceapi.ResourceClaim

ExternalClaim returns external resource claim that test pods can reference

func (*Builder) ParametersEnv

func (b *Builder) ParametersEnv() (string, []string)

ParametersEnv returns the default user env variables as JSON (config) and key/value list (pod env).

func (*Builder) Pod

func (b *Builder) Pod() *v1.Pod

makePod returns a simple Pod with no resource claims. The Pod prints its env and waits.

func (*Builder) PodExternal

func (b *Builder) PodExternal() *v1.Pod

PodExternal adds a pod that references external resource claim with default class name and parameters.

func (*Builder) PodExternalMultiple

func (b *Builder) PodExternalMultiple() *v1.Pod

podShared returns a pod with 3 containers that reference external resource claim with default class name and parameters.

func (*Builder) PodInline

func (b *Builder) PodInline() (*v1.Pod, *resourceapi.ResourceClaimTemplate)

makePodInline adds an inline resource claim with default class name and parameters.

func (*Builder) PodInlineMultiple

func (b *Builder) PodInlineMultiple() (*v1.Pod, *resourceapi.ResourceClaimTemplate)

func (*Builder) PodInlineWithV1beta1

func (b *Builder) PodInlineWithV1beta1() (*v1.Pod, *resourcev1beta1.ResourceClaimTemplate)

func (*Builder) PodInlineWithV1beta2

func (b *Builder) PodInlineWithV1beta2() (*v1.Pod, *resourcev1beta2.ResourceClaimTemplate)

func (*Builder) TestPod

func (b *Builder) TestPod(ctx context.Context, f *framework.Framework, pod *v1.Pod, env ...string)

TestPod runs pod and checks if container logs contain expected environment variables

type Driver

type Driver struct {

	// NameSuffix can be set while registering a test to deploy different
	// drivers in the same test namespace.
	NameSuffix string

	// InstanceSuffix can be set while registering a test to deploy two different
	// instances of the same driver. Used to generate unique objects in the API server.
	// The socket path is still the same.
	InstanceSuffix string

	// RollingUpdate can be set to true to enable using different socket names
	// for different pods and thus seamless upgrades. Must be supported by the kubelet!
	RollingUpdate bool

	// Normally, tearing down the driver should cause ResourceSlices to get removed eventually.
	// The exception is when the driver is part of a rolling update and is torn down first.
	ExpectResourceSliceRemoval bool

	// Name gets derived automatically from the current test namespace and
	// (if set) the NameSuffix while setting up the driver for a test.
	Name string

	// Nodes contains entries for each node selected for a test when the test runs.
	// In addition, there is one entry for a fictional node.
	Nodes map[string]KubeletPlugin

	// IsLocal can be set to true when using local-up-cluster.sh *and* ensuring
	// that /var/lib/kubelet/plugins, /var/lib/kubelet/plugins_registry and
	// /var/run/cdi are writable by the current user.
	IsLocal bool

	NodeV1      bool
	NodeV1beta1 bool

	// Register the DRA test driver with the kubelet and expect DRA to work (= feature.DynamicResourceAllocation).
	WithKubelet bool
	// contains filtered or unexported fields
}

func NewDriver

func NewDriver(f *framework.Framework, nodes *Nodes, driverResourcesGenerator driverResourcesGenFunc, driverResourcesMutators ...driverResourcesMutatorFunc) *Driver

NewDriver sets up controller (as client of the cluster) and kubelet plugin (via proxy) before the test runs. It cleans up after the test.

Call this outside of ginkgo.It, then use the instance inside ginkgo.It.

func NewDriverInstance

func NewDriverInstance(f *framework.Framework) *Driver

NewDriverInstance is a variant of NewDriver where the driver is inactive and must be started explicitly with Run. May be used inside ginkgo.It.

func (*Driver) CallCount

func (d *Driver) CallCount(m MethodInstance) int64

func (*Driver) ClientV1

func (d *Driver) ClientV1() cgoresource.ResourceV1Interface

ClientV1 returns a wrapper for client-go which provides the V1 API on top of whatever is enabled in the cluster.

func (*Driver) Fail

func (d *Driver) Fail(m MethodInstance, injectError bool)

func (*Driver) ImpersonateKubeletPlugin

func (d *Driver) ImpersonateKubeletPlugin(pod *v1.Pod) kubernetes.Interface

func (*Driver) IsGone

func (d *Driver) IsGone(ctx context.Context)

IsGone checks that the kubelet is done with the driver. This is done by waiting for the kubelet to remove the driver's ResourceSlices, which takes at least 30 seconds because of the delay in the kubelet.

Only use this in tests where kubelet support for DRA is guaranteed.

func (*Driver) NewGetSlices

NewGetSlices generates a function for gomega.Eventually/Consistently which returns the ResourceSliceList.

func (*Driver) Nodenames

func (d *Driver) Nodenames() (nodenames []string)

func (*Driver) Run

func (d *Driver) Run(nodes *Nodes, driverResources map[string]resourceslice.DriverResources)

func (*Driver) SetUp

func (d *Driver) SetUp(nodes *Nodes, driverResources map[string]resourceslice.DriverResources)

func (*Driver) TearDown

func (d *Driver) TearDown(ctx context.Context)

type KubeletPlugin

type KubeletPlugin struct {
	*app.ExamplePlugin
	ClientSet kubernetes.Interface
}

type MethodInstance

type MethodInstance struct {
	NodeName   string
	FullMethod string
}

type Nodes

type Nodes struct {
	// NodeNames has the main set of node names.
	NodeNames []string

	// NumReservedNodes specifies the desired number of
	// extra nodes that get set aside. That many node names
	// will be stored in ExtraNodeNames.
	//
	// Must be <= the minimum number of requested nodes.
	NumReservedNodes int
	// ExtraNodeNames has exactly as many node names as
	// requested via NumReservedNodes. Those nodes are
	// different than the nodes listed in NodeNames.
	ExtraNodeNames []string
	// contains filtered or unexported fields
}

func NewNodes

func NewNodes(f *framework.Framework, minNodes, maxNodes int) *Nodes

NewNodes selects nodes to run the test on.

Call this outside of ginkgo.It, then use the instance inside ginkgo.It.

func NewNodesNow

func NewNodesNow(ctx context.Context, f *framework.Framework, minNodes, maxNodes int) *Nodes

NewNodesNow is a variant of NewNodes which can be used inside a ginkgo.It.

Source Files

builder.go deploy.go

Version
v1.34.0-rc.0
Published
Aug 6, 2025
Platform
linux/amd64
Imports
66 packages
Last checked
9 minutes ago

Tools for package owners.