helpers

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2025 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateTestCWSA

func CreateTestCWSA(
	name string, scopes map[string][]string, permissions []rbacv1.PolicyRule,
) *agentoctopuscomv1beta1.ClusterWorkloadServiceAccount

CreateTestCWSA creates a ClusterWorkloadServiceAccount for testing

func CreateTestCWSAWithRoles

func CreateTestCWSAWithRoles(
	name string, scopes map[string][]string, permissions []rbacv1.PolicyRule,
	clusterRoles []rbacv1.RoleRef,
) *agentoctopuscomv1beta1.ClusterWorkloadServiceAccount

CreateTestCWSAWithRoles creates a ClusterWorkloadServiceAccount with inline permissions and role references

func CreateTestWSA

func CreateTestWSA(
	name, namespace string, scopes map[string][]string, permissions []rbacv1.PolicyRule,
) *agentoctopuscomv1beta1.WorkloadServiceAccount

CreateTestWSA creates a WorkloadServiceAccount for testing with the given scope and permissions

func CreateTestWSAWithRoles

func CreateTestWSAWithRoles(
	name, namespace string, scopes map[string][]string, permissions []rbacv1.PolicyRule,
	roles []rbacv1.RoleRef, clusterRoles []rbacv1.RoleRef,
) *agentoctopuscomv1beta1.WorkloadServiceAccount

CreateTestWSAWithRoles creates a WorkloadServiceAccount with inline permissions and role references

func DefaultCRDPaths

func DefaultCRDPaths(levelsUp int) []string

DefaultCRDPaths returns the standard CRD paths for different test locations

func DefaultWebhookPaths

func DefaultWebhookPaths(levelsUp int) []string

DefaultWebhookPaths returns the standard webhook paths for different test locations

func DeleteAll

func DeleteAll(cfg *rest.Config, k8sClient client.Client, objs ...client.Object)

DeleteAll deletes all provided objects and waits for cleanup, including namespace finalization

func FilterClusterRoleBindingsByPrefix

func FilterClusterRoleBindingsByPrefix(
	clusterRoleBindings []rbacv1.ClusterRoleBinding, prefix string,
) []rbacv1.ClusterRoleBinding

FilterClusterRoleBindingsByPrefix filters cluster role bindings by name prefix

func FilterRoleBindingsByPrefix

func FilterRoleBindingsByPrefix(roleBindings []rbacv1.RoleBinding, prefix string) []rbacv1.RoleBinding

FilterRoleBindingsByPrefix filters role bindings by name prefix

func GetFirstFoundEnvTestBinaryDir

func GetFirstFoundEnvTestBinaryDir() string

GetFirstFoundEnvTestBinaryDir locates the first binary in the specified path. ENVTEST-based tests depend on specific binaries, usually located in paths set by controller-runtime. When running tests directly (e.g., via an IDE) without using Makefile targets, the 'BinaryAssetsDirectory' must be explicitly configured.

This function streamlines the process by finding the required binaries, similar to setting the 'KUBEBUILDER_ASSETS' environment variable. To ensure the binaries are properly set up, run 'make setup-envtest' beforehand.

func TearDownEnvTest

func TearDownEnvTest(result *EnvTestResult)

TearDownEnvTest tears down the envtest environment

Types

type EnvTestConfig

type EnvTestConfig struct {
	// CRDDirectoryPaths are paths to directories containing CRDs
	CRDDirectoryPaths []string
	// ErrorIfCRDPathMissing determines if an error should be thrown if CRD path is missing
	ErrorIfCRDPathMissing bool
	// WebhookPaths are paths to directories containing webhook configurations (optional, for webhook tests)
	WebhookPaths []string
	// Scheme is the runtime scheme to use
	Scheme *runtime.Scheme
}

EnvTestConfig holds configuration for setting up an envtest environment

type EnvTestResult

type EnvTestResult struct {
	Ctx       context.Context
	Cancel    context.CancelFunc
	K8sClient client.Client
	Cfg       *rest.Config
	TestEnv   *envtest.Environment
}

EnvTestResult holds the result of setting up an envtest environment

func SetupEnvTest

func SetupEnvTest(config EnvTestConfig) *EnvTestResult

SetupEnvTest sets up a basic envtest environment for controller/rules tests

func SetupEnvTestWithWebhook

func SetupEnvTestWithWebhook(config WebhookTestConfig) *EnvTestResult

SetupEnvTestWithWebhook sets up an envtest environment with webhook support

type WebhookTestConfig

type WebhookTestConfig struct {
	EnvTestConfig
	// SetupWebhookFunc is a function that sets up webhooks on the manager
	SetupWebhookFunc func(mgr ctrl.Manager) error
}

WebhookTestConfig holds configuration specific to webhook tests

Jump to

Keyboard shortcuts

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