controller-runtimesigs.k8s.io/controller-runtime/pkg/controller/controllertest Index | Files

package controllertest

import "sigs.k8s.io/controller-runtime/pkg/controller/controllertest"

Package controllertest contains fake informers for testing controllers When in doubt, it's almost always better to test against a real API server using envtest.Environment.

Index

Types

type ErrorType

type ErrorType struct{}

ErrorType implements runtime.Object but isn't registered in any scheme and should cause errors in tests as a result.

func (ErrorType) DeepCopyObject

func (ErrorType) DeepCopyObject() runtime.Object

DeepCopyObject implements runtime.Object.

func (ErrorType) GetObjectKind

func (ErrorType) GetObjectKind() schema.ObjectKind

GetObjectKind implements runtime.Object.

type FakeInformer

type FakeInformer struct {
	// Synced is returned by the HasSynced functions to implement the Informer interface
	Synced bool

	// RunCount is incremented each time RunInformersAndControllers is called
	RunCount int
	// contains filtered or unexported fields
}

FakeInformer provides fake Informer functionality for testing.

func (*FakeInformer) Add

func (f *FakeInformer) Add(obj metav1.Object)

Add fakes an Add event for obj.

func (*FakeInformer) AddEventHandler

AddEventHandler implements the Informer interface. Adds an EventHandler to the fake Informers. TODO(community): Implement Registration.

func (*FakeInformer) AddEventHandlerWithOptions

AddEventHandlerWithOptions implements the Informer interface. Adds an EventHandler to the fake Informers (ignores options). TODO(community): Implement Registration.

func (*FakeInformer) AddEventHandlerWithResyncPeriod

func (f *FakeInformer) AddEventHandlerWithResyncPeriod(handler cache.ResourceEventHandler, _ time.Duration) (cache.ResourceEventHandlerRegistration, error)

AddEventHandlerWithResyncPeriod implements the Informer interface. Adds an EventHandler to the fake Informers (ignores resyncPeriod). TODO(community): Implement Registration.

func (*FakeInformer) AddIndexers

func (f *FakeInformer) AddIndexers(indexers cache.Indexers) error

AddIndexers does nothing. TODO(community): Implement this.

func (*FakeInformer) Delete

func (f *FakeInformer) Delete(obj metav1.Object)

Delete fakes an Delete event for obj.

func (*FakeInformer) GetController

func (f *FakeInformer) GetController() cache.Controller

GetController does nothing. TODO(community): Implement this.

func (*FakeInformer) GetIndexer

func (f *FakeInformer) GetIndexer() cache.Indexer

GetIndexer does nothing. TODO(community): Implement this.

func (*FakeInformer) GetStore

func (f *FakeInformer) GetStore() cache.Store

GetStore does nothing. TODO(community): Implement this.

func (*FakeInformer) HasSynced

func (f *FakeInformer) HasSynced() bool

HasSynced implements the Informer interface. Returns f.Synced.

func (*FakeInformer) Informer

func (f *FakeInformer) Informer() cache.SharedIndexInformer

Informer returns the fake Informer.

func (*FakeInformer) IsStopped

func (f *FakeInformer) IsStopped() bool

IsStopped does nothing. TODO(community): Implement this.

func (*FakeInformer) LastSyncResourceVersion

func (f *FakeInformer) LastSyncResourceVersion() string

LastSyncResourceVersion does nothing. TODO(community): Implement this.

func (*FakeInformer) RemoveEventHandler

func (f *FakeInformer) RemoveEventHandler(handle cache.ResourceEventHandlerRegistration) error

RemoveEventHandler does nothing. TODO(community): Implement this.

func (*FakeInformer) Run

func (f *FakeInformer) Run(<-chan struct{})

Run implements the Informer interface. Increments f.RunCount.

func (*FakeInformer) RunWithContext

func (f *FakeInformer) RunWithContext(_ context.Context)

func (*FakeInformer) SetTransform

func (f *FakeInformer) SetTransform(t cache.TransformFunc) error

SetTransform does nothing. TODO(community): Implement this.

func (*FakeInformer) SetWatchErrorHandler

func (f *FakeInformer) SetWatchErrorHandler(cache.WatchErrorHandler) error

SetWatchErrorHandler does nothing. TODO(community): Implement this.

func (*FakeInformer) SetWatchErrorHandlerWithContext

func (f *FakeInformer) SetWatchErrorHandlerWithContext(cache.WatchErrorHandlerWithContext) error

SetWatchErrorHandlerWithContext does nothing. TODO(community): Implement this.

func (*FakeInformer) Update

func (f *FakeInformer) Update(oldObj, newObj metav1.Object)

Update fakes an Update event for obj.

type Queue

type Queue = TypedQueue[reconcile.Request]

Queue implements a RateLimiting queue as a non-ratelimited queue for testing. This helps testing by having functions that use a RateLimiting queue synchronously add items to the queue.

type TypedQueue

type TypedQueue[request comparable] struct {
	workqueue.TypedInterface[request]
	AddedRateLimitedLock sync.Mutex
	AddedRatelimited     []any
}

TypedQueue implements a RateLimiting queue as a non-ratelimited queue for testing. This helps testing by having functions that use a RateLimiting queue synchronously add items to the queue.

func (*TypedQueue[request]) AddAfter

func (q *TypedQueue[request]) AddAfter(item request, duration time.Duration)

AddAfter implements RateLimitingInterface.

func (*TypedQueue[request]) AddRateLimited

func (q *TypedQueue[request]) AddRateLimited(item request)

AddRateLimited implements RateLimitingInterface. TODO(community): Implement this.

func (*TypedQueue[request]) Forget

func (q *TypedQueue[request]) Forget(item request)

Forget implements RateLimitingInterface. TODO(community): Implement this.

func (*TypedQueue[request]) NumRequeues

func (q *TypedQueue[request]) NumRequeues(item request) int

NumRequeues implements RateLimitingInterface. TODO(community): Implement this.

type UnconventionalListType

type UnconventionalListType struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`
	Spec              string `json:"spec,omitempty"`
}

UnconventionalListType is used to test CRDs with List types that have a slice of pointers rather than a slice of literals.

func (*UnconventionalListType) DeepCopy

DeepCopy implements *UnconventionalListType Handwritten for simplicity.

func (*UnconventionalListType) DeepCopyObject

func (u *UnconventionalListType) DeepCopyObject() runtime.Object

DeepCopyObject implements runtime.Object Handwritten for simplicity.

type UnconventionalListTypeList

type UnconventionalListTypeList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata,omitempty"`
	Items           []*UnconventionalListType `json:"items"`
}

UnconventionalListTypeList is used to test CRDs with List types that have a slice of pointers rather than a slice of literals.

func (*UnconventionalListTypeList) DeepCopy

DeepCopy implements *UnconventionalListTypeListt Handwritten for simplicity.

func (*UnconventionalListTypeList) DeepCopyObject

func (u *UnconventionalListTypeList) DeepCopyObject() runtime.Object

DeepCopyObject implements runtime.Object Handwritten for simplicity.

Source Files

doc.go testing.go unconventionallisttypecrd.go util.go

Version
v0.21.0 (latest)
Published
May 20, 2025
Platform
linux/amd64
Imports
9 packages
Last checked
25 minutes ago

Tools for package owners.