framework

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMCPServerImage   = "quay.io/containers/kubernetes_mcp_server@sha256:6d650f4bd6ac303ad82713c997e73a2d001602f9bf17392c9b9a0e30e29c6423" // :v0.0.66
	AlternateMCPServerImage = "quay.io/containers/kubernetes_mcp_server@sha256:5df586e2c7ced2a3125f6e78923388d80b69de0a2ad1470325b05318f12725bd" // :v0.0.65
	BusyboxImage            = "docker.io/library/busybox@sha256:9db7b59979c38555a39def84a31fb98b5296952f9e3afd4f6f11f05b07adfab0"                // :1.37
)
View Source
const (
	DefaultNamespace          = "mcp-lifecycle-operator-system"
	DefaultServiceAccountName = "mcp-lifecycle-operator-controller-manager"
	DefaultMetricsServiceName = "mcp-lifecycle-operator-controller-manager-metrics-service"
)

Variables

This section is empty.

Functions

func AssertAddressURL

func AssertAddressURL(t *testing.T, server *mcpv1alpha1.MCPServer, port int32)

AssertAddressURL verifies the MCPServer's status address URL matches the expected port and path.

func AssertAddressUnset

func AssertAddressUnset(t *testing.T, server *mcpv1alpha1.MCPServer)

AssertAddressUnset verifies status.address.url is not published (issue #302).

func AssertConditionStable

func AssertConditionStable(ctx context.Context, t *testing.T, r *resources.Resources,
	server *mcpv1alpha1.MCPServer, condType string, status metav1.ConditionStatus, duration ...time.Duration)

AssertConditionStable re-fetches the MCPServer repeatedly for the given duration and fails if the condition ever deviates from the expected status.

func Clientset

func Clientset(t *testing.T, cfg *envconf.Config) *kubernetes.Clientset

Clientset returns a kubernetes.Clientset from the e2e-framework config.

func FindPodByLabel

func FindPodByLabel(ctx context.Context, t *testing.T, cfg *envconf.Config,
	namespace, labelSelector string, timeout ...time.Duration) *corev1.Pod

FindPodByLabel polls until a Running pod matching the label selector is found in the given namespace. An optional timeout can be provided; defaults to 3 minutes.

func GetMCPServerCondition

func GetMCPServerCondition(server *mcpv1alpha1.MCPServer, condType string) *metav1.Condition

GetMCPServerCondition returns a pointer to the named condition, or nil.

func NewMCPServer

func NewMCPServer(name, namespace string, opts ...MCPServerOption) *mcpv1alpha1.MCPServer

NewMCPServer creates an MCPServer with sensible defaults for e2e tests. Defaults: image=DefaultMCPServerImage, port=8080, args=["--port","8080","--read-only"].

func PodLogs

func PodLogs(ctx context.Context, t *testing.T, cfg *envconf.Config,
	podName, namespace string) string

PodLogs returns the log output of a pod's first container.

func PrewarmImages

func PrewarmImages(images ...string) env.Func

PrewarmImages returns an env.Func that pulls the given images on every node before tests start. Uses a DaemonSet per image so multi-node clusters are fully warmed. This prevents parallel tests from thundering-herd the registry with concurrent pulls of the same image.

func ProfileNames

func ProfileNames() []string

ProfileNames returns sorted profile names.

func Register

func Register(tier Tier, fn LocateFunc)

Register adds a locator to the default registry at the given tier.

func RegisterProfile

func RegisterProfile(p Profile)

RegisterProfile adds a profile to the global registry. If a profile with the same name already exists, the higher priority wins. Equal priority overwrites (last-write-wins).

func RegisterProfileFlag

func RegisterProfileFlag()

RegisterProfileFlag registers the -profile flag. Call before envconf.NewFromFlags().

func ResolveProfile

func ResolveProfile() map[string][]string

ResolveProfile returns the labels for the selected profile, or nil if no profile was selected. Exits with an error if the profile is unknown.

func ServerFromContext

func ServerFromContext(ctx context.Context) *mcpv1alpha1.MCPServer

ServerFromContext extracts the MCPServer stored by SetupMCPServer. Returns nil if the server was never stored in context.

func ServiceProxyHTTPClient

func ServiceProxyHTTPClient(t *testing.T, cfg *envconf.Config,
	namespace, serviceName string, port int, path string, opts ...ProxyOption) (*http.Client, string)

ServiceProxyHTTPClient returns an *http.Client and the full proxy URL for accessing a ClusterIP service via the Kubernetes API server proxy. The returned client is authenticated for the API server; the URL routes through /api/v1/namespaces/{ns}/services/{scheme}:{name}:{port}/proxy/{path}.

func SetupMCPServer

func SetupMCPServer(ctx context.Context, t *testing.T, cfg *envconf.Config, name string, waitForReady bool, opts ...MCPServerOption) context.Context

SetupMCPServer creates an MCPServer, optionally waits for Ready, and stores it in context. Pass waitForReady=true to block until the server reaches Ready=True before returning.

func TeardownMCPServer

func TeardownMCPServer(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context

TeardownMCPServer deletes the MCPServer from context and waits for owned Deployment and Service to be garbage collected.

func UpdateWithRetry

func UpdateWithRetry[T k8s.Object](ctx context.Context, t *testing.T, r *resources.Resources,
	obj T, mutate func(T))

UpdateWithRetry performs a read-modify-write loop with automatic retry on conflict. The mutate callback receives the freshly-fetched object so the caller always modifies the latest resourceVersion.

func WaitForEndpointsReady

func WaitForEndpointsReady(ctx context.Context, t *testing.T, cfg *envconf.Config, namespace, name string)

WaitForEndpointsReady waits until the named Service has at least one ready endpoint in its EndpointSlice. The API server proxy returns 503 until endpoints are propagated, so callers that use the proxy should wait first.

func WaitForMCPServerCondition

func WaitForMCPServerCondition(ctx context.Context, t *testing.T, r *resources.Resources,
	server *mcpv1alpha1.MCPServer, condType string, status metav1.ConditionStatus, timeout ...time.Duration)

WaitForMCPServerCondition polls until the named condition reaches the desired status. An optional timeout can be provided; defaults to 3 minutes.

func WaitForMCPServerConditionMessageContains

func WaitForMCPServerConditionMessageContains(ctx context.Context, t *testing.T, r *resources.Resources,
	server *mcpv1alpha1.MCPServer, condType string, status metav1.ConditionStatus, reason string,
	messageSubstring string, timeout ...time.Duration)

WaitForMCPServerConditionMessageContains polls until the named condition reaches the desired status and reason, and its message contains the given substring. An optional timeout can be provided; defaults to 3 minutes.

func WaitForMCPServerConditionReason

func WaitForMCPServerConditionReason(ctx context.Context, t *testing.T, r *resources.Resources,
	server *mcpv1alpha1.MCPServer, condType string, status metav1.ConditionStatus, reason string, timeout ...time.Duration)

WaitForMCPServerConditionReason polls until the named condition reaches the desired status and reason. An optional timeout can be provided; defaults to 3 minutes.

func WaitForMCPServerReconciled

func WaitForMCPServerReconciled(ctx context.Context, t *testing.T, r *resources.Resources,
	server *mcpv1alpha1.MCPServer, timeout ...time.Duration)

WaitForMCPServerReconciled polls until the controller has reconciled the current generation (observedGeneration >= generation) without requiring a specific Ready status. Use this after spec mutations where the pod may not become Ready (e.g. port changes when the container image uses a fixed port).

func WaitForMCPServerReconciledAndReady

func WaitForMCPServerReconciledAndReady(ctx context.Context, t *testing.T, r *resources.Resources,
	server *mcpv1alpha1.MCPServer, timeout ...time.Duration)

WaitForMCPServerReconciledAndReady polls until the controller has reconciled the current generation (observedGeneration >= generation) and Ready=True. Use this after mutating the MCPServer spec to avoid seeing stale Ready from before the update.

func WaitForPodPhase

func WaitForPodPhase(ctx context.Context, t *testing.T, cfg *envconf.Config,
	pod *corev1.Pod, phase corev1.PodPhase, timeout ...time.Duration)

WaitForPodPhase waits until a pod reaches the given phase. An optional timeout can be provided; defaults to 3 minutes.

Types

type ContextKey

type ContextKey string

ContextKey is used to store values in context.

const (
	NsKey     ContextKey = "namespace"
	ServerKey ContextKey = "mcpserver"
)

type LocateFunc

type LocateFunc func(ctx context.Context, cfg *envconf.Config) (OperatorRef, error)

LocateFunc finds the operator. A non-zero OperatorRef means found (possibly partial). A zero OperatorRef with nil error means not found. A non-nil error is propagated and aborts discovery.

type MCPServerOption

type MCPServerOption func(*mcpv1alpha1.MCPServer)

MCPServerOption configures an MCPServer for testing.

func WithArguments

func WithArguments(args ...string) MCPServerOption

WithArguments sets the MCPServer container arguments.

func WithEnvFrom

func WithEnvFrom(envFrom ...corev1.EnvFromSource) MCPServerOption

WithEnvFrom sets the MCPServer envFrom sources.

func WithExtraAnnotations

func WithExtraAnnotations(annotations map[string]string) MCPServerOption

WithExtraAnnotations sets custom annotations on the MCPServer.

func WithExtraLabels

func WithExtraLabels(labels map[string]string) MCPServerOption

WithExtraLabels sets custom labels on the MCPServer.

func WithImage

func WithImage(ref string) MCPServerOption

WithImage sets the container image ref.

func WithPath

func WithPath(path string) MCPServerOption

WithPath sets the MCPServer HTTP path.

func WithPodSecurityContext

func WithPodSecurityContext(psc *corev1.PodSecurityContext) MCPServerOption

WithPodSecurityContext sets the pod-level security context.

func WithPort

func WithPort(port int32) MCPServerOption

WithPort sets the MCPServer port.

func WithReplicas

func WithReplicas(n int32) MCPServerOption

WithReplicas sets the number of pod replicas.

func WithSecurityContext

func WithSecurityContext(sc *corev1.SecurityContext) MCPServerOption

WithSecurityContext sets the container security context.

func WithStorage

func WithStorage(storage ...mcpv1alpha1.StorageMount) MCPServerOption

WithStorage sets the MCPServer storage mounts.

func WithTransport

func WithTransport(transport *mcpv1alpha1.TransportConfig) MCPServerOption

WithTransport sets the MCPServer transport configuration.

type OperatorRef

type OperatorRef struct {
	Namespace          string
	ServiceAccountName string
	MetricsServiceName string
}

OperatorRef holds the discovered operator namespace and resource names.

func DiscoverOperator

func DiscoverOperator(ctx context.Context, cfg *envconf.Config) (OperatorRef, error)

DiscoverOperator runs the default registry through all tiers.

func FromDefaults

func FromDefaults(_ context.Context, _ *envconf.Config) (OperatorRef, error)

func FromEnvVars

func FromEnvVars(_ context.Context, _ *envconf.Config) (OperatorRef, error)

func FromPodLabels

func FromPodLabels(ctx context.Context, cfg *envconf.Config) (OperatorRef, error)

func MustDiscoverOperatorOnce

func MustDiscoverOperatorOnce(ctx context.Context, cfg *envconf.Config, t testing.TB) OperatorRef

type Profile

type Profile struct {
	Name     string
	Priority int
	Labels   map[string][]string
}

Profile is a named label selector for filtering e2e tests. Higher Priority wins when multiple registrations use the same Name. Upstream defaults use priority 0; downstream overrides should use > 0.

func LookupProfile

func LookupProfile(name string) (Profile, bool)

LookupProfile returns a profile by name.

type ProxyOption

type ProxyOption func(*proxyOptions)

ProxyOption configures optional parameters for ServiceProxyHTTPClient.

func WithScheme

func WithScheme(scheme string) ProxyOption

WithScheme sets the service scheme used in the API server proxy URL. Defaults to "http".

type Registry

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

Registry holds tier-keyed locators and caches the discovery result.

func (*Registry) DiscoverOperator

func (r *Registry) DiscoverOperator(ctx context.Context, cfg *envconf.Config) (OperatorRef, error)

func (*Registry) MustDiscoverOperatorOnce

func (r *Registry) MustDiscoverOperatorOnce(ctx context.Context, cfg *envconf.Config, t testing.TB) OperatorRef

MustDiscoverOperatorOnce runs DiscoverOperator at most once, caches the result, and calls t.Fatalf if discovery fails.

func (*Registry) Register

func (r *Registry) Register(tier Tier, fn LocateFunc)

Register adds a locator at the given tier, replacing any existing one.

type Tier

type Tier string

Tier determines evaluation order: Explicit -> Platform -> Fallback.

const (
	Explicit Tier = "Explicit"
	Platform Tier = "Platform"
	Fallback Tier = "Fallback"
)

Directories

Path Synopsis
labels
scenario
Package scenario provides the optional third label dimension for e2e tests.
Package scenario provides the optional third label dimension for e2e tests.

Jump to

Keyboard shortcuts

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