netshoot

package
v0.1.0-latest-stable Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// Image is the netshoot image used by the test pods in this package. It is exported so tests
	// that build their own Pod spec, rather than going through TestPodConfig, use the same image.
	Image = "mirror.gcr.io/nicolaka/netshoot:v0.13"
	// Defines the timeout for the EXEC command to complete
	DefaultExecTimeout = 2 * time.Minute
)

Variables

View Source
var (
	ErrCreateExecutor = errors.New("failed to create executor")
	ErrExecFailed     = errors.New("exec failed")
)

Functions

func AnalyzeIBWriteBWResult

func AnalyzeIBWriteBWResult(output string, minAvg float32)

AnalyzeIBWriteBWResult parses ib_write_bw --out_json output and asserts BWAverage > minAvg. Values are assumed Gbit/sec, callers must run ib_write_bw with --report_gbit. BWPeak is logged only (perftest zeroes it on -D runs once iters > 20000), the average assertion is the gate.

func AnalyzeIperfResults

func AnalyzeIperfResults(result IperfResult, reverse bool)

AnalyzeIperfResults logs the transfer and asserts the throughput threshold for a parsed iperf3 result.

func AssertPingFailure

func AssertPingFailure(restClient **rest.RESTClient, config **rest.Config, namespace, fromPod, toPodIP string)

AssertPingFailure asserts that ping between pods fails with ErrExecFailed error

func AssertPingFailureWithMTU

func AssertPingFailureWithMTU(restClient **rest.RESTClient, config **rest.Config, namespace, fromPod, toPodIP string, mtu, expectedNetworkMTU int)

AssertPingFailureWithMTU asserts that ping between pods fails with the specified MTU (MTU too large) and verifies that the MTU value in the error response matches the expected MTU

func AssertPingSuccess

func AssertPingSuccess(restClient **rest.RESTClient, config **rest.Config, namespace, fromPod, toPodIP string)

AssertPingSuccess asserts that ping between pods succeeds

func AssertPingSuccessWithMTU

func AssertPingSuccessWithMTU(restClient **rest.RESTClient, config **rest.Config, namespace, fromPod, toPodIP string, mtu int)

AssertPingSuccessWithMTU asserts that ping between pods succeeds with the specified MTU

func CreateAndWaitForNetutilsHostPod

func CreateAndWaitForNetutilsHostPod(ctx context.Context, testClient client.Client, pod *corev1.Pod, timeout time.Duration) *corev1.Pod

CreateAndWaitForNetutilsHostPod creates pod and waits for it to be ready.

func CreateAndWaitForPods

func CreateAndWaitForPods(ctx context.Context, client client.Client, configs []*TestPodConfig)

func CreateNadsFromConfig

func CreateNadsFromConfig(ctx context.Context, client client.Client, configs []*TestPodConfig)

func CreateNetutilsHostPod

func CreateNetutilsHostPod(ctx context.Context, testClient client.Client, pod *corev1.Pod) *corev1.Pod

CreateNetutilsHostPod creates pod and returns it without waiting for readiness.

func CreatePods

func CreatePods(ctx context.Context, client client.Client, configs []*TestPodConfig)

func DefaultErrorParser

func DefaultErrorParser(stdout, stderr string) string

DefaultErrorParser is the default error parsing function that truncates output.

func DeletePodBestEffort

func DeletePodBestEffort(ctx context.Context, testClient client.Client, pod *corev1.Pod)

DeletePodBestEffort deletes pod without ever failing the spec. Use it from DeferCleanup for test pods on a DPU cluster.

A DPU cluster is reached through a port forward that may already be closing by the time cleanup runs, and a torn down tunnel must not fail a spec whose assertions have all passed. A Pod left behind is idle and goes away with the cluster it sits on, so the error is only logged.

func ExecInContainerOnce

func ExecInContainerOnce(restClient *rest.RESTClient, config *rest.Config, namespace, podName, containerName string, command []string) (string, error)

ExecInContainerOnce executes a command in a specific container of a pod and returns the output and error. Use this instead of ExecInPodOnce when the pod has multiple containers.

func ExecInPodOnce

func ExecInPodOnce(restClient *rest.RESTClient, config *rest.Config, namespace, podName string, command []string) (string, error)

ExecInPodOnce runs a command in a pod once and returns stdout and any error. Uses DefaultErrorParser for error output.

func ExecInPodOnceWithErrorParser

func ExecInPodOnceWithErrorParser(restClient *rest.RESTClient, config *rest.Config, namespace, podName string, command []string, errorParser ErrorParserFunc) (string, error)

ExecInPodOnceWithErrorParser runs a command in a pod once and returns stdout and any error. It uses the provided error parser for error output.

func ExecInPodOnceWithStdin

func ExecInPodOnceWithStdin(restClient *rest.RESTClient, config *rest.Config, namespace, podName string, command []string, stdin io.Reader) (string, error)

ExecInPodOnceWithStdin runs a command in a pod once with stdin and returns stdout and any error. Uses DefaultErrorParser for error output.

func GetPodIP

func GetPodIP(ctx context.Context, testClient client.Client, namespace, podName string) string

func GetPodOnNode

func GetPodOnNode(pods []*corev1.Pod, nodeName string) *corev1.Pod

GetPodOnNode returns the first pod in the list scheduled on the given node name, or nil if none match.

func GetReadyPodsMatchingLabels

func GetReadyPodsMatchingLabels(ctx context.Context, c client.Client, namespace string, matchingLabels map[string]string, expected int) []*corev1.Pod

GetReadyPodsMatchingLabels waits for expected pods matching the given labels to be running and ready.

func IperfErrorParser

func IperfErrorParser(stdout, stderr string) string

IperfErrorParser is an error parsing function that extracts errors from Iperf3 JSON output.

func IsPodRunningAndReady

func IsPodRunningAndReady(pod *corev1.Pod) bool

IsPodRunningAndReady returns true if the pod is Running and has PodReady condition true.

func PingBurst

func PingBurst(restClient *rest.RESTClient, config *rest.Config, namespace, podName, dstIP string, count int) (string, error)

PingBurst sends count ICMP echo requests (fast interval, short per-packet wait) from a pod to dstIP and returns the ping output and error.

func RunRDMATrafficTest

func RunRDMATrafficTest(restClient **rest.RESTClient, restConfig **rest.Config, hostNamespace string, podName1, podName2, pod2IP string)

func RunTrafficTest

func RunTrafficTest(restClient **rest.RESTClient, restConfig **rest.Config, hostNamespace string, podName1, podName2, pod2IP string)

RunTrafficTest runs a bidirectional iperf3 throughput test and asserts the threshold in both directions. Use RunTrafficTestWithResult if you also need the parsed iperf results.

func StderrOnlyErrorParser

func StderrOnlyErrorParser(_ string, stderr string) string

StderrOnlyErrorParser formats stderr without exposing stdout.

func WaitForNetutilsPodReady

func WaitForNetutilsPodReady(ctx context.Context, testClient client.Client, pod *corev1.Pod, timeout time.Duration)

WaitForNetutilsPodReady waits for pod to become Running and Ready, failing fast if it goes Failed. Failure messages include pod.Spec.NodeName, if set, so per-node loops (e.g. one pod per DPU cluster node) point at the right node.

func WaitForPodsReady

func WaitForPodsReady(ctx context.Context, client client.Client, configs []*TestPodConfig, timeout time.Duration)

WaitForPodsReady waits for multiple pods to be running

Types

type ErrorParserFunc

type ErrorParserFunc func(stdout, stderr string) string

ErrorParserFunc defines a function type for parsing command output errors.

func MTUErrorParserGenerator

func MTUErrorParserGenerator(expectedMTU int) ErrorParserFunc

MTUErrorParserGenerator creates an error parser that extracts MTU error messages from the output. The returned parser returns the MTU error message if it exists in the output, otherwise an empty string.

type ExecOption

type ExecOption func(*execOptions)

ExecOption configures an executeCommandOnce call. See WithContainer, WithStdin, WithExecTimeout and WithErrorParser.

func WithContainer

func WithContainer(containerName string) ExecOption

WithContainer targets a specific container in the pod. Defaults to the pod's only/first container.

func WithErrorParser

func WithErrorParser(errorParser ErrorParserFunc) ExecOption

WithErrorParser overrides how stdout/stderr are inspected to enrich the returned error. Defaults to DefaultErrorParser.

func WithExecTimeout

func WithExecTimeout(execTimeout time.Duration) ExecOption

WithExecTimeout bounds how long a single attempt may block (e.g. waiting on a broken port-forward) before it is aborted. Defaults to DefaultExecTimeout.

func WithStdin

func WithStdin(stdin io.Reader) ExecOption

WithStdin attaches a stdin stream to the exec session. Defaults to no stdin.

type IBWriteBWResult

type IBWriteBWResult struct {
	TestInfo *struct {
		Device *string `json:"Device,omitempty"`
	} `json:"test_info,omitempty"`
	Results *struct {
		BWPeak    *float32 `json:"BW_peak,omitempty"`
		BWAverage *float32 `json:"BW_average,omitempty"`
	} `json:"results,omitempty"`
}

IBWriteBWResult is used to parse the traffic test result of an ib_write_bw command Example output:

{
  "test_info": {
    "test": "RDMA_Write_BW_Test",
    "Dual_port": "OFF",
    "Device": "mlx5_11",
    "Number_of_qps": 1,
    "Transport_type": "IB",
    "Connection_type": "RC",
    "Using_SRQ": "OFF",
    "PCIe_relax_order": "ON",
    "ibv_wr_API": "ON",
    "TX_depth": 128,
    "CQ_Moderation": 1,
    "Mtu": 1024,
    "Link_type": "Ethernet",
    "GID_index": 1,
    "Max_inline_data": 0,
    "rdma_cm_QPs": "OFF",
    "Use_ROCm_memory": "OFF",
    "Data_ex_method": "Ethernet"
  },
  "results": {
    "MsgSize": 65536,
    "n_iterations": 5000,
    "BW_peak": 5293.52,
    "BW_average": 2229.27,
    "MsgRate": 0.035668
  }
}

type IperfResult

type IperfResult struct {
	Start struct {
		Connected []struct {
			LocalHost  string `json:"local_host"`
			RemoteHost string `json:"remote_host"`
		} `json:"connected"`
		TCPMSSDefault int64 `json:"tcp_mss_default"`
	} `json:"start"`
	Intervals []struct {
		Sum struct {
			BitsPerSecond float64 `json:"bits_per_second"`
		} `json:"sum"`
	} `json:"intervals"`
	End struct {
		SumSent struct {
			BitsPerSecond float64 `json:"bits_per_second"`
			Bytes         int64   `json:"bytes"`
		} `json:"sum_sent"`
	} `json:"end"`
}

IperfResult is used to parse the traffic test result of an iperf3 command

func ParseIperfResult

func ParseIperfResult(output string) IperfResult

ParseIperfResult unmarshals iperf3 --json output into an IperfResult and validates that connection information is present.

type NetutilsPodBuilder

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

NetutilsPodBuilder builds a privileged hostNetwork pod running the netutils image (sleep infinity), used to inspect host/DPU-side network and device state from inside a cluster. Construct with NewNetutilsHostPod, chain With* calls, then Build.

func NewNetutilsHostPod

func NewNetutilsHostPod(name, namespace, nodeName, image string) *NetutilsPodBuilder

NewNetutilsHostPod starts a builder for a netutils pod named name in namespace, scheduled on nodeName, running image (full "repository:tag" ref).

func (*NetutilsPodBuilder) Build

func (b *NetutilsPodBuilder) Build() *corev1.Pod

Build returns the constructed pod.

func (*NetutilsPodBuilder) WithHostPathMount

func (b *NetutilsPodBuilder) WithHostPathMount(name, hostPath, mountPath string, readOnly bool, hostPathType *corev1.HostPathType) *NetutilsPodBuilder

WithHostPathMount adds a HostPath volume named name (path hostPath on the host) and mounts it at mountPath in the netutils container. hostPathType may be nil to leave the HostPath type unset.

func (*NetutilsPodBuilder) WithImagePullSecret

func (b *NetutilsPodBuilder) WithImagePullSecret(secret string) *NetutilsPodBuilder

WithImagePullSecret sets the pull secret used to fetch the netutils image.

func (*NetutilsPodBuilder) WithLabels

func (b *NetutilsPodBuilder) WithLabels(labels map[string]string) *NetutilsPodBuilder

WithLabels sets the pod's labels.

func (*NetutilsPodBuilder) WithLifecycle

func (b *NetutilsPodBuilder) WithLifecycle(lifecycle *corev1.Lifecycle) *NetutilsPodBuilder

WithLifecycle sets the netutils container's lifecycle hooks (e.g. PreStop).

func (*NetutilsPodBuilder) WithSysMount

func (b *NetutilsPodBuilder) WithSysMount() *NetutilsPodBuilder

WithSysMount is a convenience for the common read-only "/sys" mount.

func (*NetutilsPodBuilder) WithTerminationGracePeriod

func (b *NetutilsPodBuilder) WithTerminationGracePeriod(seconds int64) *NetutilsPodBuilder

WithTerminationGracePeriod sets the pod's termination grace period.

type TestPodConfig

type TestPodConfig struct {
	Name          string
	Namespace     string
	NADName       string
	InterfaceName string
	IP            string
	DST           string
	GW            string
	NodeName      string
	VFIndex       int
	CIDR          string
	Labels        map[string]string
	CommandArgs   []string
}

TestPodConfig represents the configuration for a test pod

type TrafficTestResult

type TrafficTestResult struct {
	Forward IperfResult
	Reverse IperfResult
}

TrafficTestResult holds the parsed iperf3 results for both directions of a bidirectional run: Forward is podName1 -> podName2, Reverse is podName2 -> podName1.

func RunTrafficTestWithResult

func RunTrafficTestWithResult(restClient **rest.RESTClient, restConfig **rest.Config, hostNamespace string, podName1, podName2, pod2IP string) TrafficTestResult

RunTrafficTestWithResult runs a bidirectional iperf3 throughput test, asserts the threshold in both directions and returns the parsed results for both directions.

Jump to

Keyboard shortcuts

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