helpers

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2025 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanName

func CleanName(generateName string) string

Do a best-effort cleanup of the provided value to make it a valid k8s generated resource name.

func FullName

func FullName(mr metaResource) string

func FullNameStr

func FullNameStr(namespace, name string) string

func TruncateString added in v0.0.3

func TruncateString(s string, maxLength int, truncatedSuffix string) string

func TruncateStringEllipsis added in v0.0.3

func TruncateStringEllipsis(s string, length int) string

func WaitForResourceCondition

func WaitForResourceCondition[T runtime.Object, TList runtime.Object, V interface{}](ctx *contexts.Context, timeout time.Duration, client ListerWatcher[TList], name string, processEvent WaitEventProcessor[T, V]) (result V, err error)

Wait for a check to pass on a given resource, optionally returning a value when the condition passes. Will not return until the condition is met, or an error occurs.

Types

type GenerateName

type GenerateName bool

func (GenerateName) SetName

func (gn GenerateName) SetName(metadata *metav1.ObjectMeta, name string)

type LabelableResource added in v0.0.9

type LabelableResource interface {
	GetLabels() map[string]string
	SetLabels(labels map[string]string)
}

This is a subset of metav1.Object that only includes label functions.

type ListerWatcher

type ListerWatcher[TList runtime.Object] interface {
	List(ctx context.Context, opts metav1.ListOptions) (TList, error)
	Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error)
}

Describes a type that can list and watch k8s resources. `TList` should be a list type (such corev1.PodList), rather than the listed type (such as corev1.Pod). Typically this should be provided via something like `client.CoreV1().Pods(<namespace>)`.

type MaxWaitTime

type MaxWaitTime time.Duration
var ShortWaitTime MaxWaitTime = MaxWaitTime(250 * time.Millisecond)

Very short wait time, mostly used for testing

func (MaxWaitTime) MaxWait

func (mwt MaxWaitTime) MaxWait(defaultVal time.Duration) time.Duration

type MockListerWatcher

type MockListerWatcher[TList runtime.Object] struct {
	mock.Mock
}

MockListerWatcher is an autogenerated mock type for the ListerWatcher type

func NewMockListerWatcher

func NewMockListerWatcher[TList runtime.Object](t interface {
	mock.TestingT
	Cleanup(func())
}) *MockListerWatcher[TList]

NewMockListerWatcher creates a new instance of MockListerWatcher. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockListerWatcher[TList]) EXPECT

func (_m *MockListerWatcher[TList]) EXPECT() *MockListerWatcher_Expecter[TList]

func (*MockListerWatcher[TList]) List

func (_m *MockListerWatcher[TList]) List(ctx context.Context, opts v1.ListOptions) (TList, error)

List provides a mock function with given fields: ctx, opts

func (*MockListerWatcher[TList]) Watch

func (_m *MockListerWatcher[TList]) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error)

Watch provides a mock function with given fields: ctx, opts

type MockListerWatcher_Expecter

type MockListerWatcher_Expecter[TList runtime.Object] struct {
	// contains filtered or unexported fields
}

func (*MockListerWatcher_Expecter[TList]) List

func (_e *MockListerWatcher_Expecter[TList]) List(ctx interface{}, opts interface{}) *MockListerWatcher_List_Call[TList]

List is a helper method to define mock.On call

  • ctx context.Context
  • opts v1.ListOptions

func (*MockListerWatcher_Expecter[TList]) Watch

func (_e *MockListerWatcher_Expecter[TList]) Watch(ctx interface{}, opts interface{}) *MockListerWatcher_Watch_Call[TList]

Watch is a helper method to define mock.On call

  • ctx context.Context
  • opts v1.ListOptions

type MockListerWatcher_List_Call

type MockListerWatcher_List_Call[TList runtime.Object] struct {
	*mock.Call
}

MockListerWatcher_List_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'List'

func (*MockListerWatcher_List_Call[TList]) Return

func (_c *MockListerWatcher_List_Call[TList]) Return(_a0 TList, _a1 error) *MockListerWatcher_List_Call[TList]

func (*MockListerWatcher_List_Call[TList]) Run

func (_c *MockListerWatcher_List_Call[TList]) Run(run func(ctx context.Context, opts v1.ListOptions)) *MockListerWatcher_List_Call[TList]

func (*MockListerWatcher_List_Call[TList]) RunAndReturn

func (_c *MockListerWatcher_List_Call[TList]) RunAndReturn(run func(context.Context, v1.ListOptions) (TList, error)) *MockListerWatcher_List_Call[TList]

type MockListerWatcher_Watch_Call

type MockListerWatcher_Watch_Call[TList runtime.Object] struct {
	*mock.Call
}

MockListerWatcher_Watch_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Watch'

func (*MockListerWatcher_Watch_Call[TList]) Return

func (*MockListerWatcher_Watch_Call[TList]) Run

func (_c *MockListerWatcher_Watch_Call[TList]) Run(run func(ctx context.Context, opts v1.ListOptions)) *MockListerWatcher_Watch_Call[TList]

func (*MockListerWatcher_Watch_Call[TList]) RunAndReturn

type MockmetaResource

type MockmetaResource struct {
	mock.Mock
}

MockmetaResource is an autogenerated mock type for the metaResource type

func NewMockmetaResource

func NewMockmetaResource(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockmetaResource

NewMockmetaResource creates a new instance of MockmetaResource. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockmetaResource) EXPECT

func (*MockmetaResource) GetName

func (_m *MockmetaResource) GetName() string

GetName provides a mock function with no fields

func (*MockmetaResource) GetNamespace

func (_m *MockmetaResource) GetNamespace() string

GetNamespace provides a mock function with no fields

type MockmetaResource_Expecter

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

func (*MockmetaResource_Expecter) GetName

GetName is a helper method to define mock.On call

func (*MockmetaResource_Expecter) GetNamespace

GetNamespace is a helper method to define mock.On call

type MockmetaResource_GetName_Call

type MockmetaResource_GetName_Call struct {
	*mock.Call
}

MockmetaResource_GetName_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetName'

func (*MockmetaResource_GetName_Call) Return

func (*MockmetaResource_GetName_Call) Run

func (*MockmetaResource_GetName_Call) RunAndReturn

type MockmetaResource_GetNamespace_Call

type MockmetaResource_GetNamespace_Call struct {
	*mock.Call
}

MockmetaResource_GetNamespace_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetNamespace'

func (*MockmetaResource_GetNamespace_Call) Return

func (*MockmetaResource_GetNamespace_Call) Run

func (*MockmetaResource_GetNamespace_Call) RunAndReturn

type ResourceLabeler added in v0.0.9

type ResourceLabeler interface {
	SetCommonLabels(labels map[string]string)
}

Describes a type that can label k8s resources. Used to set common labels on resources, which is important for integration with external systems like netpols.

type SimpleResourceLabeler added in v0.0.9

type SimpleResourceLabeler struct {
	CommonLabels map[string]string
}

func (SimpleResourceLabeler) LabelResource added in v0.0.9

func (srl SimpleResourceLabeler) LabelResource(resource LabelableResource)

Label a resource with the common labels provided to the labeler, if labels with the same keys do not already exist on the resource.

func (*SimpleResourceLabeler) SetCommonLabels added in v0.0.9

func (srl *SimpleResourceLabeler) SetCommonLabels(labels map[string]string)

type WaitEventProcessor

type WaitEventProcessor[T runtime.Object, V interface{}] func(*contexts.Context, T) (V, bool, error)

Callback for determining if a provided k8s object (`T`, such as corev1.Pod) matches an awaited condition. The function returns result `V` (can be `nil`/`interface{}` type if not needed), whether or not the object matches the condition, and an error if one occurred during processing.

Jump to

Keyboard shortcuts

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