utils

package
v0.18.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 43 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Timeout         = 30 * time.Second
	PollingInterval = 3 * time.Second
)
View Source
const (
	GogsUser      = "test"
	GogsPass      = "pass"
	GogsHTTPSPort = "3000"
	GogsSSHPort   = "22"
)

Variables

This section is empty.

Functions

func CreateBundle added in v0.10.0

func CreateBundle(ctx context.Context, k8sClient client.Client, name, namespace string, targets []v1alpha1.BundleTarget, targetRestrictions []v1alpha1.BundleTarget) (*v1alpha1.Bundle, error)

func CreateCluster added in v0.10.0

func CreateCluster(ctx context.Context, k8sClient client.Client, name, controllerNs string, labels map[string]string, clusterNs string) (*v1alpha1.Cluster, error)

func CreateGogsContainerWithHTTPS added in v0.16.0

func CreateGogsContainerWithHTTPS(ctx context.Context, assetPath string) (testcontainers.Container, []byte, *gogs.Client, error)

CreateGogsContainerWithHTTPS starts a gogs container backed by assetPath, generates a TLS certificate, and waits until the HTTPS endpoint accepts connections. It returns the container, the CA bundle PEM bytes, and an authenticated gogs client. assetPath must be the gitserver directory to bind-mount into the container at /data.

func CreateTempFolder added in v0.16.0

func CreateTempFolder(prefix string) string

CreateTempFolder returns a temporary directory for test data. On GitHub Actions, os.MkdirTemp is used to avoid cleanup failures; DeferCleanup fixes permissions locally in order to clean up automatically, since containers may create subdirs owned by a different UID.

func DisableReaper added in v0.15.4

func DisableReaper()

DisableReaper disables the testcontainers reaper (Ryuk) to avoid issues with Docker container state in local development environments. The reaper is mainly useful in CI but often causes race conditions locally. This should be called in init() functions of test packages that use testcontainers.

func ExtractResourceLogs added in v0.12.9

func ExtractResourceLogs(allLogs, resourceName string) string

ExtractResourceLogs extracts log lines related to a specific resource name

func FindCondition

func FindCondition(
	conds []genericcondition.GenericCondition,
	condType string,
) (genericcondition.GenericCondition, bool)

FindCondition returns the condition of the given type, and whether it exists.

func FromEnvTestConfig added in v0.10.0

func FromEnvTestConfig(cfg *rest.Config) []byte

FromEnvTestConfig returns a new Kubeconfig in byte form when running in envtest.

func GetGogsHTTPSURL added in v0.16.0

func GetGogsHTTPSURL(ctx context.Context, container testcontainers.Container) (string, error)

GetGogsHTTPSURL returns the mapped HTTPS base URL for a running gogs container.

func GetGogsKnownHostEntry added in v0.16.0

func GetGogsKnownHostEntry(ctx context.Context, container testcontainers.Container) (string, error)

GetGogsKnownHostEntry reads the container's SSH ECDSA host public key and returns a known_hosts format line suitable for use with CreateKnownHostsCallBack.

func GetGogsSSHURL added in v0.16.0

func GetGogsSSHURL(ctx context.Context, container testcontainers.Container) (string, error)

GetGogsSSHURL returns the mapped SSH base URL for a running gogs container.

func MakeSSHKeyPair added in v0.16.0

func MakeSSHKeyPair() (publicKey, privateKey string, _ error)

MakeSSHKeyPair generates an RSA-4096 key pair for git SSH authentication. Returns the public key in authorized_keys format and the private key in PEM format.

func NewClient added in v0.10.0

func NewClient(cfg *rest.Config) (client.Client, error)

NewClient returns a new controller-runtime client.

func NewEnvTest added in v0.10.0

func NewEnvTest(root string) *envtest.Environment

NewEnvTest returns a new envtest with the Fleet CRDs loaded. Run ginkgo with the -v flag to see the logs in real time.

func NewManager added in v0.10.0

func NewManager(cfg *rest.Config) (ctrl.Manager, error)

NewManager returns a new controller-runtime manager suitable for testing.

func NewNamespaceName

func NewNamespaceName() (string, error)

func ShouldSuppressLogs added in v0.15.4

func ShouldSuppressLogs() bool

ShouldSuppressLogs checks if logs should be suppressed based on the VERBOSE environment variable. Returns true when VERBOSE is not set (suppress logs), false when VERBOSE=1 (show all logs).

func StartTestEnv added in v0.11.4

func StartTestEnv(testEnv *envtest.Environment) (*rest.Config, error)

func SuppressLogs added in v0.15.4

func SuppressLogs()

SuppressLogs suppresses log output during integration tests unless VERBOSE=1 is set. This filters expected test warnings and informational messages to keep test output clean. To see all logs during debugging, run tests with: VERBOSE=1 go test ...

This suppresses: - Go standard library logger (log package) - used by Helm SDK for warnings

func WriteKubeConfig added in v0.10.0

func WriteKubeConfig(cfg *rest.Config, path string) error

Types

type ConflictInjector

type ConflictInjector struct {
	client.Client

	Target types.NamespacedName
	Match  func(client.Object) bool
	Inject func()
	// contains filtered or unexported fields
}

ConflictInjector wraps a client and runs Inject once, the first time the target object is read. That makes the caller's in-memory copy stale by the time it patches the status, deterministically reproducing the race between a status reconciler and the controller that owns the same object.

Match narrows which reads trigger the injection, so that reads of other kinds of object are ignored; it is required.

func (*ConflictInjector) Get

func (c *ConflictInjector) Get(
	ctx context.Context,
	key client.ObjectKey,
	obj client.Object,
	opts ...client.GetOption,
) error

type StaleReadClient

type StaleReadClient struct {
	client.Client

	Target   types.NamespacedName
	CopyInto func(into client.Object) bool
	// contains filtered or unexported fields
}

StaleReadClient wraps a client and serves a pre-captured, out-of-date copy of the target object for the first N reads, simulating a lagging informer cache. Later reads pass through to the real client, as a cache that has caught up would.

CopyInto writes the armed stale copy into the object being read, and reports whether that object was one this client should serve staleness for; it is required.

func (*StaleReadClient) Arm

func (c *StaleReadClient) Arm(staleUntilGet int)

Arm serves the stale copy for the next staleUntilGet reads of the target.

func (*StaleReadClient) Get

func (c *StaleReadClient) Get(
	ctx context.Context,
	key client.ObjectKey,
	obj client.Object,
	opts ...client.GetOption,
) error

Jump to

Keyboard shortcuts

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