package k8sctx

import "gvisor.dev/gvisor/test/kubernetes/k8sctx"

Package k8sctx is used to manage the lifecycle of a Kubernetes test or benchmark running in one or more Kubernetes clusters. It is used to control the behavior of Kubernetes-based tests and benchmarks at runtime and to abstract away how the Kubernetes test clusters are created and managed from the test code.

Index

Functions

func ForEachCluster

func ForEachCluster(ctx context.Context, t *testing.T, k8sCtx KubernetesContext, fn func(cluster *testcluster.TestCluster))

ForEachCluster calls the given function for each available cluster sequentially. In order to run per-cluster subtests in parallel, call `t.Run` inside `fn` and then `t.Parallel` inside that.

Types

type KubernetesContext

type KubernetesContext interface {
	// Cluster returns a single cluster for the test or benchmark to use.
	// The cluster is guaranteed to not be in use by other tests or benchmarks
	// until the returned function is called.
	// If there are no available clusters, it returns a nil TestCluster.
	Cluster(ctx context.Context, t *testing.T) (*testcluster.TestCluster, func())

	// ResolveImage resolves a container image name (possibly with a label)
	// to a fully-qualified image name. It can also return an `image:label`
	// string if the Kubernetes cluster the test runs in will resolve it on
	// its own.
	ResolveImage(ctx context.Context, imageName string) (string, error)
}

KubernetesContext represents the Kubernetes execution context. It is used to keep track of available Kubernetes clusters to test on. Tests are expected to call `RegisterTest` for every of their test function, then `TestMain`.

func New

func New(testClusters ...*testcluster.TestCluster) KubernetesContext

New creates a KubernetesContext that set of test clusters.

Source Files

k8sctx.go

Directories

PathSynopsis
test/kubernetes/k8sctx/kubectlctxPackage kubectlctx provides a KubernetesContext that uses one or more kubectl configs to determine the cluster(s) to use for tests and benchmarks.
Version
v0.0.0-20250605235530-a6711d1e1dc6 (latest)
Published
Jun 5, 2025
Platform
linux/amd64
Imports
3 packages
Last checked
4 hours ago

Tools for package owners.