helpers

package
v1.2.0-pre.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 42 Imported by: 0

Documentation

Overview

This package contains various helper functions for writing Tetragon e2e tests, including many setup and feature functions.

Index

Constants

This section is empty.

Variables

View Source
var (
	TetragonContainerName = "tetragon"
	TetragonJsonPathname  = "/var/run/cilium/tetragon/tetragon.log"
)

Functions

func CreateExportDir

func CreateExportDir(ctx context.Context, t *testing.T) (context.Context, error)

func CreateNamespace

func CreateNamespace(namespace string, waitForCreation bool) env.Func

CreateNamespace is a wrapper around envfuncs.CreateNamespace with optional support to wait for namespace creation.

func DeleteNamespace

func DeleteNamespace(namespace string, waitForDeletion bool) env.Func

DeleteNamespace is a wrapper around envfuncs.DeleteNamespace with optional support to wait for namespace deletion.

func DumpInfo

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

func ExecInPod

func ExecInPod(ctx context.Context, client klient.Client, namespace, pod, container string, stdout, stderr io.Writer, command []string) error

func ExecInPodCombinedOutput

func ExecInPodCombinedOutput(ctx context.Context, client klient.Client, namespace, pod, container string, command []string) ([]byte, error)

func ExecInPodOutput

func ExecInPodOutput(ctx context.Context, client klient.Client, namespace, pod, container string, command []string) ([]byte, error)

func GetClusterName

func GetClusterName() string

GetClusterName fetches the cluster name configured with -cluster-name or the temporary kind cluster name.

func GetExportDir

func GetExportDir(ctx context.Context) (string, error)

func GetMinKernelVersion

func GetMinKernelVersion(t *testing.T, testenv env.Environment) string

func GetTempKindClusterName

func GetTempKindClusterName(ctx context.Context) string

GetTempKindClusterName returns the name of the temporary kind cluster if it exists, otherwise it returns an empty string.

func LoadCRDFile

func LoadCRDFile(namespace string, file string, waitForPods bool) env.Func

LoadCRDFile decodes a CRD file and calls LoadObjects on the result.

func LoadCRDString

func LoadCRDString(namespace string, yamlStr string, waitForPods bool) env.Func

LoadCRDString decodes a CRD from a yaml string and calls LoadObjects on the result.

func LoadObjects

func LoadObjects(namespace string, objs []k8s.Object, waitForPods bool) env.Func

LoadObjects loads a list of k8s.Object and optionally waits for all resources to be created and pods to be ready.

func MaybeCreateTempKindCluster

func MaybeCreateTempKindCluster(testenv env.Environment, namePrefix string) env.Func

MaybeCreateTempKindCluster creates a new temporary kind cluster in case no kubeconfig file is specified on the command line.

func NewObjectList

func NewObjectList(objs []k8s.Object) k8s.ObjectList

NewObjectList creates a new k8s.ObjectList from a list of k8s.Object

func PortForwardPod

func PortForwardPod(testenv env.Environment, pod *corev1.Pod, out, outErr *os.File, retries uint, retryBackoff time.Duration, ports ...string) env.Func

PortForwardPod forwards one or more ports to a given pod. Port forwards are automatically cleaned up when the test exits. Ports should be specified in the form "src:dst" where "src" and "dst" are port numbers.

out and outErr are pointers to os.File that should be used by the portforwarder for its stdout and stderr respectively. These can be set to nil to ignore output.

retries and retryBackoff can be used to configure how many times this function should retry on failure to set up the port forward and how long it should wait between retries.

func PortForwardTetragonPods

func PortForwardTetragonPods(testenv env.Environment) env.Func

PortForwardTetragonPods forwards gRPC and metrics ports for Tetragon pods.

func RunCommand

func RunCommand(ctx context.Context, client klient.Client, podNamespace, podName, containerName string, cmd string, args ...string) ([]byte, error)

RunCommand runs a command in a pod and returns the combined stdout and stderr delimited by markers as a byte slice. For lower level control use the ExecInPod* helpers instead.

func SetMinKernelVersion

func SetMinKernelVersion() env.Func

func StartGopsDumper

func StartGopsDumper(ctx context.Context, exportDir string, interval time.Duration)

StartGopsDumper starts a goroutine that dumps gops information at a regular interval until the context is done. We want to do this in case the pod crashes or gets restarted during a failing test. This way we can at least have a snapshot of the gops dumps to look back on.

func StartMetricsDumper

func StartMetricsDumper(ctx context.Context, exportDir string, interval time.Duration)

StartMetricsDumper starts a goroutine that dumps metrics at a regular interval until the context is done. We want to do this in case the pod crashes or gets restarted during a failing test. This way we can at least have a snapshot of the metrics to look back on.

func UnloadCRDFile

func UnloadCRDFile(namespace string, file string, waitForDeletion bool) env.Func

UnloadCRDFile decodes a CRD file and calls UnloadObjects on the result.

func UnloadCRDString

func UnloadCRDString(namespace string, yamlStr string, waitForDeletion bool) env.Func

UnloadCRDString decodes a CRD yaml string and calls UnloadObjects on the result.

func UnloadObjects

func UnloadObjects(namespace string, objs []k8s.Object, waitForDeletion bool) env.Func

UnloadObjects unloads a list of k8s.Object and optionally waits for all resources to be deleted.

Types

type TestEnvFunc

type TestEnvFunc = func(ctx context.Context, cfg *envconf.Config, t *testing.T) (context.Context, error)

Directories

Path Synopsis
Package gops is a simple gops client implementation to dump gops info from end-to-end tests.
Package gops is a simple gops client implementation to dump gops info from end-to-end tests.
Package grpc provides some helpers for contacting with the gRPC tetragon service.
Package grpc provides some helpers for contacting with the gRPC tetragon service.

Jump to

Keyboard shortcuts

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