utils

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: May 22, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TemplatePorts = []int{31445, 31444, 31081, 9090, 8443, 8088, 8081, 8080}

TemplatePorts lists every port number used in test gateway manifests. Sorted descending so substitution always replaces longer ports first (e.g. 31081 before 8081) and avoids partial-match corruption.

Functions

func CreateRuntimeObject

func CreateRuntimeObject(ctx context.Context, client ctrlruntimeclient.Client, obj ctrlruntimeclient.Object, waitForResult bool) error

func CreateRuntimeObjectsFromYAMLFiles

func CreateRuntimeObjectsFromYAMLFiles(params RuntimeYamlParams) error

CreateRuntimeObjectsFromYAMLFiles reads YAML files, decodes them into Kubernetes objects, and creates them using the provided client. It handles multi-document YAML files (separated by "---").

func DeleteRuntimeObject

func DeleteRuntimeObject(ctx context.Context, client ctrlruntimeclient.Client, obj ctrlruntimeclient.Object, waitForResult bool) error

func DeleteRuntimeObjectsFromYAMLFiles

func DeleteRuntimeObjectsFromYAMLFiles(params RuntimeYamlParams) error

func DerivePortMap added in v1.0.3

func DerivePortMap(namespace string, templatePorts []int) map[int]int

DerivePortMap deterministically maps each template port to a unique unprivileged port derived from the test namespace name. Using a hash avoids any TOCTOU race: no listener is opened and immediately closed, so no other process can steal the port between allocation and the eventual HAProxy bind.

Port range: 20000–29999. This sits below Linux's default ephemeral range (32768–60999), above the IANA registered range, and is unlikely to be used by system services. With 5000 available base slots (one per 2 ports) and the small number of test packages, hash collisions between packages are astronomically unlikely.

func ExportBackend added in v1.0.3

func ExportBackend(be *models.Backend)

func ExportFrontend added in v1.0.3

func ExportFrontend(fe *models.Frontend)

func GetCRDFixturePath

func GetCRDFixturePath() string

func GetIntTestNamespace

func GetIntTestNamespace(levelsUp int) (string, error)

func RuntimeFromBytes

func RuntimeFromBytes(ctrlclient ctrlruntimeclient.Client, manifest []byte) (runtime.Object, *schema.GroupVersionKind, error)

RuntimeFromBytes returns a list of Kubernetes runtime objects from their yaml templates.

func SortListenerStatus added in v1.0.0

func SortListenerStatus(listeners []gatewayv1.ListenerStatus)

func SubstitutePortsInContent added in v1.0.3

func SubstitutePortsInContent(content []byte, portMap map[int]int) []byte

SubstitutePortsInContent replaces every template port number that appears in content with its actual counterpart from portMap. Ports are processed in descending order so that a longer port (e.g. 31081) is replaced before a shorter one it contains (e.g. 8081), preventing partial-match corruption.

func SubstitutePortsInString added in v1.0.3

func SubstitutePortsInString(s string, portMap map[int]int) string

SubstitutePortsInString is the string-valued variant of SubstitutePortsInContent.

func WaitFor

func WaitFor(ctx context.Context, interval time.Duration, timeout time.Duration, callback func() bool) bool

WaitFor is a convenience wrapper that makes simple, "brute force" waiting loops easier to write.

Types

type RuntimeYamlParams

type RuntimeYamlParams struct {
	Ctx               context.Context
	CrtlruntimeClient ctrlruntimeclient.Client
	PortMap           map[int]int // template port → actual port; applied to YAML before parse
	Dir               string
	Namespace         string
	ManifestNames     []string
	WaitForResult     bool // Flag to wait for object to be created/deleted
}

Jump to

Keyboard shortcuts

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