...

Package ktest

import "edge-infra.dev/test/f2/x/ktest"
Overview
Index
Subdirectories

Overview ▾

Constants

const (
    MaxNamespaceLen = 63
    Timeout         = time.Second * 30
    Tick            = time.Second * 1
)

func FieldManagerOwner

func FieldManagerOwner() sap.Owner

FieldManagerOwner creates a consistent ownership key for resource fields that are created/updated by test framework code.

type K8s

K8s is a framework extension for Kubernetes that registers consistent lifeycle hooks for K8s tests, flag binding, config parsing, and other test utilities.

type K8s struct {
    Env       *envtest.Environment
    Namespace string
    Client    client.Client
    Manager   manager.Manager
    *kpoll.KPoll

    Timeout time.Duration
    Tick    time.Duration
    // contains filtered or unexported fields
}

func FromContext

func FromContext(ctx fctx.Context) (*K8s, error)

FromContext attempts to fetch an instance of K8s from the test context and returns an error if it is not discovered.

func FromContextT

func FromContextT(ctx fctx.Context, t *testing.T) *K8s

FromContextT is a testing variant of FromContext that immediately fails the test if K8s isnt presnt in the testing context.

func New

func New(opts ...Option) *K8s

New creates a K8s framework

func (*K8s) BindFlags

func (k *K8s) BindFlags(fs *flag.FlagSet)

BindFlags registers test flags for the framework extension.

func (*K8s) GetContainerLogs

func (k *K8s) GetContainerLogs(ctx context.Context, podname string, namespace string, container string) (io.ReadCloser, error)

Return a stream of the logs for a given container within the defined pod & namespace

func (*K8s) IntoContext

func (k *K8s) IntoContext(ctx fctx.Context) fctx.Context

IntoContext stores the framework extension in the test context.

func (*K8s) Labels

func (k *K8s) Labels() map[string]string

func (*K8s) RegisterFns

func (k *K8s) RegisterFns(f f2.Framework)

RegisterFns is called by the framework after binding and parsing test flags.

type Option

Option is a ktest framework extension option. The behavior of individual options may be modified by providing test flags exposed by this package.

type Option func(*options)

func SkipNamespaceCreation

func SkipNamespaceCreation() Option

SkipNamespaceCreation will make the framework skip creation of a namespace for each test case. Useful for tests that don't operate against any Namespaced resources.

func SkipNamespaceDeletion

func SkipNamespaceDeletion() Option

SkipNamespaceDeletion will make the framework skip deletion of a namespace for each test case.

func WithCertManager

func WithCertManager() Option

WithCertManager ensures that cert-manager is installed for the test run.

func WithCtrlManager

func WithCtrlManager(fn func(...controller.Option) (manager.Manager, error)) Option

WithCtrlManager sets up the framework for testing a controller-runtime Manager

func WithEnvtestOptions

func WithEnvtestOptions(opts ...envtest.Option) Option

func WithGracefulTimeout

func WithGracefulTimeout(timeout string) Option

WithGracefulTimeout allows an optional timeout duration to be passed during ktest setup. The desired timeout is passed as a string and parsed using time.ParseDuration. e.g. WithGracefulTimeout("1m30s") Passing "0" disables graceful shutdown while passing a negative value allows the graceful shutdown to complete with no timeout. Defaults to defaultGracefulShutdownPeriod (30s)

func WithKonfigKonnector

func WithKonfigKonnector() Option

WithKonfigKonnector controls whether or not K8s config connector is installed and configured for the test run.

func WithMetricsAddress

func WithMetricsAddress(addr int) Option

WithMetricsAddress enables the manager's metrics server. The passed port will be used if available. Otherwise, a random available port will be used. Passing 0 will allow a random available port to be used by default.

func WithScheme

func WithScheme(scheme *runtime.Scheme) Option

WithScheme sets the Scheme that will be used when creating the [K8s.Client]. If it is not set, the Scheme provided by [K8s.Manager] will be used. Ie, WithScheme takes precedence over WithCtrlManager when setting the client.Client Scheme

type PortForward

struct to contain the portforwarder and the namespace to search in for the pod

type PortForward struct {
    // Namespace that portforwarding should be set up to target
    // If the namespace is not set then portforwarding will be set up to the unique namespace
    // created for the test by the ktest extension
    Namespace string
    // contains filtered or unexported fields
}

func (*PortForward) Forward

func (pf *PortForward) Forward(serviceName string, portnr int) f2.StepFn

Sets up a port forward for a pod associated to a service Will not panic on a connection failure after the portforward is set up (e.g if the pod is deleted).

func (*PortForward) ForwardPod

func (pf *PortForward) ForwardPod(podName string, portnr int) f2.StepFn

ForwardPod Sets up a port forward to a specific pod

func (*PortForward) ForwardPodCtx

func (pf *PortForward) ForwardPodCtx(ctx f2.Context, podName string, portnr int) error

ForwardPodCtx Sets up a port forward to a specific pod

func (PortForward) Retrieve

func (pf PortForward) Retrieve(t *testing.T) string

retrieve the address (localhost) and dynamically assigned port

Subdirectories

Name Synopsis
..
envtest Package envtest helps to set up various pieces of controller-runtime's envtest library to simplify writing K8s controller tests
kpoll Package kpoll provides a wrapper around gotest.tools/v3/poll to facilitate continually evaluating checks on K8s objects against a live cluster.
kustomization package kustomization provides a set of helpers useful when applying manifests to a k8s cluster during L2 integration tests