Documentation
¶
Overview ¶
Package e2eish runs a policy against a synthetic machine, the way the resource manager drives it, to replay e2e tests as unit tests. See "Replaying test logs as unit tests" in test/e2e/README.md.
Index ¶
- Constants
- Variables
- func Disjoint(sets ...Set) bool
- func Generate(t *testing.T, plugin *Plugin)
- func IDs(s Set) []int
- func NewMachine(t *testing.T, topo Topology, host Host) system.System
- func PodQOS(pod *corev1.Pod) string
- func Reexec(t *testing.T, env ...string) bool
- func Replay(t *testing.T, plugin *Plugin)
- func RequireDisjoint(t require.TestingT, sets ...Set)
- type Container
- type ContainerOption
- type CtrSpec
- type Group
- type Harness
- func (h *Harness) Allowed(name string) (cpuset.CPUSet, string)
- func (h *Harness) CreateContainer(spec CtrSpec, name string) (cache.Container, error)
- func (h *Harness) CreateFromPod(ns string, pod *corev1.Pod, cdiDevices map[string][]string)
- func (h *Harness) DeletePods(names ...string)
- func (h *Harness) InsertContainer(spec CtrSpec, name string) cache.Container
- func (h *Harness) InsertPod(ns, name, qos string, labels, annotations map[string]string) cache.Pod
- func (h *Harness) Launch(cfg any)
- func (h *Harness) LaunchFails(cfg any)
- func (h *Harness) LaunchMayFail(cfg any) bool
- func (h *Harness) PrepareClaim(claim *resourceapi.ResourceClaim, ...)
- func (h *Harness) ReleaseClaims(uids ...types.UID)
- func (h *Harness) ResizeContainer(pod, name string, res Resources)
- func (h *Harness) Running() []string
- func (h *Harness) Spec(name string) CtrSpec
- func (h *Harness) StopContainer(c cache.Container)
- type Host
- type Owner
- type Plugin
- type Pod
- type PodOption
- func FromClaimTemplate(claim, template string) PodOption
- func InNamespace(ns string) PodOption
- func WithAnnotations(annotations map[string]string) PodOption
- func WithContainers(ctrs ...*Container) PodOption
- func WithInitContainers(ctrs ...*Container) PodOption
- func WithLabels(labels map[string]string) PodOption
- func WithRunning(names ...string) PodOption
- type PodSpec
- type Resources
- type Script
- func (s *Script) CPUIDs(ids ...int) Set
- func (s *Script) CPUs(ctr string) Set
- func (s *Script) Consts(code string)
- func (s *Script) Cores(ctr string) Set
- func (s *Script) CreateBestEffort(spec PodSpec)
- func (s *Script) CreateBurstable(spec PodSpec)
- func (s *Script) CreateClaimTemplate(ns, y string)
- func (s *Script) CreateDeviceClass(y string)
- func (s *Script) CreateGuaranteed(spec PodSpec)
- func (s *Script) CreatePod(name string, options ...PodOption)
- func (s *Script) DeleteAllPodsIn(ns string)
- func (s *Script) DeletePods(ns string, names ...string)
- func (s *Script) Dies(ctr string) Set
- func (s *Script) Harness() *Harness
- func (s *Script) Launch(topo Topology, values ...string)
- func (s *Script) LaunchFails(topo Topology, values ...string)
- func (s *Script) LaunchMayFail(topo Topology, values ...string)
- func (s *Script) Mems(ctr string) Set
- func (s *Script) NodeIDs(ids ...int) Set
- func (s *Script) Nodes(ctr string) Set
- func (s *Script) PackageIDs(ids ...int) Set
- func (s *Script) Packages(ctr string) Set
- func (s *Script) ResizeContainer(ns, pod, ctr string, res Resources)
- func (s *Script) ResumeWithRuntimePods(pods ...*Pod)
- func (s *Script) SetCmdline(cmdline string)
- func (s *Script) SetNUMA(enabled bool)
- func (s *Script) Skip(reason string)
- func (s *Script) SyncWithRuntimePods(pods ...*Pod)
- func (s *Script) Terminate()
- func (s *Script) Threads(ctr string) Set
- func (s *Script) VerifyPy(expr string)
- type Set
- type Topology
Constants ¶
const ( DefaultCPU = "1" DefaultMem = "100M" DefaultCPUReq = "1" DefaultCPULim = "2" DefaultMemReq = "100M" DefaultMemLim = "200M" )
Template defaults of a PodSpec.
const ( Guaranteed = "guaranteed" Burstable = "burstable" BestEffort = "besteffort" )
QoS classes of the templates.
const NoInterrupts = "e2eish: no interrupt matches this"
NoInterrupts is a controllable interrupt pattern which matches no interrupt, to keep a policy off the IRQs of the host.
Variables ¶
var ( // Log is the logger of the harness, for the steps of a test. Log = logger.NewLogger("e2eish") )
Functions ¶
func Generate ¶ added in v0.15.1
Generate writes a Go test for each e2e test log of the plugin in $E2EISH_GENERATE, one e2eish-gen-TOPOLOGY_test.go file for each topology, in the package directory. Build with the e2eish_generate tag, which leaves out the files generated before. The tests run a Script, with the variable e2eishPlugin of the package as the plugin. See "Generating unit tests from test logs" in test/e2e/README.md.
func IDs ¶ added in v0.15.1
IDs is the *_ids helpers: the numbers of the names, sorted. Every name must end in a number of its own, like cpu03, node1 or package0, which is what the names of cpus, nodes, mems and packages do. The composite names of cores, threads and dies, like node1/core3, have no number of their own and panic.
func NewMachine ¶
NewMachine builds the machine qemu gives the e2e VM of the topology. CPUs are numbered package by package, die by die, node by node, core by core, with sibling threads adjacent, and dies are numbered across packages. Node distances are 10 to self, 11 within a die and 21 otherwise, unless NodeDist says else. Each core has its own L1 and L2, and its first CPU is its cluster ID. Each die has an L3. Cache overrides of the host replace these. A kernel with NUMA disabled has no nodes in sysfs.
func Reexec ¶
Reexec runs the test again in a child process with the given VAR=VALUE environment, for variables a package reads when the test binary starts. It returns true in the parent, which has nothing left to do then. The parent logs what the child test logged, and skips if the child skipped.
func Replay ¶
Replay replays the E2EISH records of the e2e test logs in testdata/e2eish-replay and $E2EISH_REPLAY against the policy of the plugin, each as a subtest. See "Replaying test logs as unit tests" in test/e2e/README.md.
func RequireDisjoint ¶ added in v0.15.1
RequireDisjoint requires that no two of the sets share a name.
Types ¶
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
Container is a container of a Pod, built with options.
func NewContainer ¶
func NewContainer(name string, options ...ContainerOption) *Container
NewContainer returns a container with the options.
type ContainerOption ¶
type ContainerOption func(*Container)
ContainerOption is an option of a Container.
func WithClaim ¶ added in v0.15.1
func WithClaim(claim, request string) ContainerOption
WithClaim gives a container a claim of its pod. An empty request gives it everything the claim holds, a named one only what that request of the claim holds.
func WithExtendedResource ¶
func WithExtendedResource(name, quantity string) ContainerOption
WithExtendedResource gives a container an extended resource, like example.com/foo. Its request is its limit, as kubernetes requires.
func WithLimits ¶
func WithLimits(cpu, mem string) ContainerOption
WithLimits sets the CPU and memory limits of a container, as resource quantities. "" leaves one unset.
func WithRequests ¶
func WithRequests(cpu, mem string) ContainerOption
WithRequests sets the CPU and memory requests of a container, as resource quantities. "" leaves one unset.
type CtrSpec ¶
CtrSpec is what a container is created from. QoS is "" for guaranteed, burstable or besteffort. CDIDevices are the qualified names of the CDI devices the runtime reports for the container, those of its DRA claims.
type Group ¶
type Group struct {
Mem string // memory per node, like 2G for 2Gi
Cores int // cores per node, none for memory-only nodes
Threads int // threads per core, 2 by default
Nodes int // nodes per die, 1 by default
Dies int // dies per package, 1 by default
Packages int // 1 by default
NodeDist map[int]int // distances to other nodes, both ways
}
Group is one entry of an e2e topology.var.json. Zero fields take the defaults of test/e2e/lib/topology2qemuopts.py.
type Harness ¶
type Harness struct {
T *testing.T
Plugin *Plugin
Machine system.System
Cache cache.Cache
Policy policyapi.Backend
Owner *Owner
// DRAEnabled is what the configuration of the next launch says, which
// the Owner of that launch publishes the devices of the policy by.
DRAEnabled bool
Pods map[string]cache.Pod // live pods by name
Ctrs map[string]cache.Container // live containers by name
// contains filtered or unexported fields
}
Harness is one e2e test run of a policy: a machine, and the policy and cache of the policy last launched.
func (*Harness) Allowed ¶
Allowed is report allowed: the CPUs and memory nodes a container may use, as the e2e tests see them in /proc/self/status. The memory nodes are a cpuset string, "" for all of them.
func (*Harness) CreateContainer ¶
CreateContainer does what the resource manager does for CreateContainer and StartContainer. A container which fails allocation is left stale.
func (*Harness) CreateFromPod ¶
CreateFromPod creates a pod and starts its containers as the kubelet would for the pod object, init containers first, one at a time to completion. Containers which fail allocation are left stale.
- ns: the namespace of the pod
- pod: the pod object
- cdiDevices: the CDI devices of each container, by container name, those the prepared DRA claims of the pod granted it
func (*Harness) DeletePods ¶
DeletePods is kubectl delete pods.
func (*Harness) InsertContainer ¶
InsertContainer adds a container to the cache, as the resource manager does first for CreateContainer, with the resources the kubelet would give it.
func (*Harness) InsertPod ¶
InsertPod does what the resource manager does for RunPodSandbox. qos is "" for guaranteed, burstable or besteffort.
func (*Harness) Launch ¶
Launch is helm-launch: it starts a fresh policy with the configuration. Like helm-terminate, it drops the state of any earlier policy.
func (*Harness) LaunchFails ¶
LaunchFails is expect-launch-failure.
func (*Harness) LaunchMayFail ¶
LaunchMayFail is helm-launch with expect_error=1. It tells if the policy started.
func (*Harness) PrepareClaim ¶ added in v0.15.1
func (h *Harness) PrepareClaim(claim *resourceapi.ResourceClaim, results []resourceapi.DeviceRequestAllocationResult)
PrepareClaim does what the resource manager does for a claim the kubelet prepares: the policy allocates the resources of it.
func (*Harness) ReleaseClaims ¶ added in v0.15.1
ReleaseClaims does what the resource manager does for the claims the kubelet unprepares.
func (*Harness) ResizeContainer ¶ added in v0.15.1
ResizeContainer does what the resource manager does for UpdateContainer: it gives a container of a pod the resources of an in-place resize, and has the policy update what it allocated when they really changed.
func (*Harness) StopContainer ¶
StopContainer does what the resource manager does for StopContainer and RemoveContainer.
type Host ¶
type Host struct {
Caches string // the OVERRIDE_SYS_CACHES JSON of an e2e helm config
NoNUMA bool // the kernel has NUMA disabled
Isolated string // CPUs isolated on the kernel command line
}
Host is what the e2e VM changes of the machine of its topology.
type Owner ¶
Owner is the owner of the policy, the resource manager. It keeps the DRA devices the policy publishes.
func (*Owner) DRAEnabled ¶ added in v0.15.1
DRAEnabled implements policyapi.Owner.
func (*Owner) DRAListAttributesSupported ¶
DRAListAttributesSupported implements policyapi.Owner. It is true, as the harness has no API server which could reject a list attribute.
func (*Owner) Devices ¶
func (o *Owner) Devices() []resourceapi.Device
Devices returns the DRA devices the policy published last.
func (*Owner) PublishDRADevices ¶
func (o *Owner) PublishDRADevices(devices []resourceapi.Device) error
PublishDRADevices implements policyapi.Owner.
func (*Owner) UpdateContainers ¶
UpdateContainers implements policyapi.Owner.
type Plugin ¶
type Plugin struct {
// Name is the name of its helm chart, in deployment/helm.
Name string
// CRD is the file of its configuration CRD in the crds of the chart.
CRD string
// DRADriver is the name of the DRA driver of the policy. An empty one
// means the replay cannot follow the resource claims of a pod.
DRADriver string
// New creates a policy.
New func() policyapi.Backend
// Config returns a new, empty configuration, for a launch to unmarshal
// the configuration into.
Config func() any
// OffHost returns a copy of a configuration with NoInterrupts as its
// only controllable interrupts.
OffHost func(cfg any) any
// Unsupported tells why the replay cannot follow a configuration or a
// pod, if it cannot. Either can be nil.
UnsupportedConfig func(cfg any) string
UnsupportedPod func(pod *corev1.Pod) string
}
Plugin is what the harness needs to know of a policy.
func (*Plugin) HelmConfig ¶
func (p *Plugin) HelmConfig(values ...json.RawMessage) (cfg any, env map[string]string, draEnabled bool, err error)
HelmConfig returns the configuration, the extra environment, and whether DRA is enabled, as a helm launch of the plugin with the given values files gives them to the policy. The values of the chart are merged with the given ones in order, as helm does, and the defaults of the CRD are applied to the configuration, as the API server does.
draEnabled is not part of the policy's own configuration: the resource manager reads it, and it is what decides whether the devices the policy publishes reach a cluster at all.
type Pod ¶
type Pod struct {
// contains filtered or unexported fields
}
Pod is a pod of a Script step, built with options.
type PodOption ¶
type PodOption func(*Pod)
PodOption is an option of a Pod.
func FromClaimTemplate ¶ added in v0.15.1
FromClaimTemplate gives a pod a DRA resource claim of its own, created from the named ResourceClaimTemplate. Its containers hold it by the claim name with WithClaim.
func WithAnnotations ¶
WithAnnotations gives a pod annotations.
func WithContainers ¶
WithContainers gives a pod containers.
func WithInitContainers ¶
WithInitContainers gives a pod init containers.
func WithLabels ¶
WithLabels gives a pod labels.
func WithRunning ¶
WithRunning tells which containers of a runtime pod run. By default all of them do.
type PodSpec ¶
type PodSpec struct {
Name string // pod<N> by default, with N pods created before
Namespace string
ContCount int // 1 by default
IContCount int // init containers
CPU, Mem string // guaranteed, 1 and 100M by default
CPUReq string // burstable, 1 by default
CPULim string // burstable, 2 by default, "0" for none
MemReq string // burstable, 100M by default, "0" for none
MemLim string // burstable, 200M by default, "0" for none
Labels map[string]string // besides app
Annotations map[string]string
}
PodSpec is a pod as the guaranteed, burstable and besteffort templates of the e2e tests create it: containers NAMEc0, NAMEc1..., init containers NAMEc0i..., all with the same resources, and the label app=NAME. Unset fields take the defaults of the templates.
type Resources ¶
type Resources struct {
CPUReq, CPULim int64 // in milli-CPUs, 0 for unset
MemReq, MemLim int64 // in bytes, 0 for unset
}
Resources are the resources of a container, as the kubelet gives them.
func ResourcesOf ¶
ResourcesOf gives the resources of a container. A request left out is the limit.
type Script ¶
type Script struct {
// contains filtered or unexported fields
}
Script runs the steps of an e2e test, one method for each kind of record of its log. Replay drives it from the records of a log, a generated test calls it directly. Helm values are given as YAML, pods as Pods.
func NewE2EScript ¶ added in v0.15.1
NewE2EScript returns a script for the plugin which is also the source of an e2e test, the target, like n4c16/test50-name, of the test suite of the plugin. A passing test writes it, with E2EISH_EMIT set. See "Generating e2e tests from unit tests" in test/e2e/README.md.
func NewScript ¶
NewScript returns a script for the plugin. A test with overrides read when the binary starts runs the script in a Reexec child.
func (*Script) CPUIDs ¶ added in v0.15.1
CPUIDs is the set of the CPUs, as topology.py names them on the machine.
func (*Script) CPUs ¶ added in v0.15.1
CPUs is cpus["ctr"] of e2e verify expressions, and the others likewise.
func (*Script) CreateBestEffort ¶
CreateBestEffort is create besteffort, of the pod of the spec.
func (*Script) CreateBurstable ¶
CreateBurstable is create burstable, of the pod of the spec.
func (*Script) CreateClaimTemplate ¶ added in v0.15.1
CreateClaimTemplate is kubectl create of the DRA ResourceClaimTemplate of the YAML, in the namespace, which the claims of a pod naming it are created from.
func (*Script) CreateDeviceClass ¶ added in v0.15.1
CreateDeviceClass is kubectl create of the DRA DeviceClass of the YAML, which the device requests of a claim select devices through.
func (*Script) CreateGuaranteed ¶
CreateGuaranteed is create guaranteed, of the pod of the spec.
func (*Script) DeleteAllPodsIn ¶
DeleteAllPodsIn is kubectl delete of all the pods in the namespace.
func (*Script) DeletePods ¶
DeletePods is kubectl delete of pods in the namespace. Pods not there are left alone.
func (*Script) Launch ¶
Launch is helm-launch of the plugin on the topology, with helm values files merged in order, as helm merges them.
func (*Script) LaunchFails ¶
LaunchFails is expect-launch-failure and the helm-launch after it.
func (*Script) LaunchMayFail ¶
LaunchMayFail is helm-launch with expect_error=1.
func (*Script) NodeIDs ¶ added in v0.15.1
NodeIDs is the set of the nodes, as topology.py names them on the machine.
func (*Script) PackageIDs ¶ added in v0.15.1
PackageIDs is the set of the packages, as topology.py names them.
func (*Script) ResizeContainer ¶ added in v0.15.1
ResizeContainer is an in-place resize of the resources of a container of a pod, which the runtime gives the policy as a resource update.
func (*Script) ResumeWithRuntimePods ¶
ResumeWithRuntimePods ends a skipped block, with the pods running in the runtime then. The pods and containers gone since the skip are deleted.
func (*Script) SetCmdline ¶
SetCmdline sets the kernel command line, for the next launch. Only isolcpus is supported.
func (*Script) SetNUMA ¶
SetNUMA enables or disables NUMA on the kernel command line, for the next launch.
func (*Script) Skip ¶
Skip starts a block of the e2e test the replay cannot follow. The pod changes and assertions of the block are ignored.
func (*Script) SyncWithRuntimePods ¶
SyncWithRuntimePods is the Synchronize of a starting plugin, with the pods running in the runtime then.
type Set ¶ added in v0.15.1
type Set map[string]struct{}
Set is a set of topology.py names, like the sets of the variables e2e verify expressions see. testify asserts work on it as on any map.
func Difference ¶ added in v0.15.1
Difference returns the names of a which b does not have.
func Intersection ¶ added in v0.15.1
Intersection returns the names of all the sets.