common

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KindPodMonitor     string = "podMonitor"
	KindServiceMonitor string = "serviceMonitor"
	KindProbe          string = "probe"
	KindScrapeConfig   string = "scrapeConfig"
)

Variables

This section is empty.

Functions

func SetCrdManagerFactory added in v1.14.0

func SetCrdManagerFactory(c *Component, factory crdManagerFactory)

SetCrdManagerFactory sets a custom crdManagerFactory on the component.

Types

type CacheFactory added in v1.14.0

type CacheFactory func(opts cache.Options) (cache.Cache, error)

CacheFactory creates controller-runtime caches with the given options. This is returned by K8sFactory.New and can be called multiple times (e.g., once per namespace).

type Component

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

func New

func New(o component.Options, args component.Arguments, kind string) (*Component, error)

func (*Component) CurrentHealth

func (c *Component) CurrentHealth() component.Health

func (*Component) DebugInfo

func (c *Component) DebugInfo() any

DebugInfo returns debug information for this component.

func (*Component) Handler

func (c *Component) Handler() http.Handler

func (*Component) NotifyClusterChange

func (c *Component) NotifyClusterChange()

NotifyClusterChange implements component.ClusterComponent.

func (*Component) Run

func (c *Component) Run(ctx context.Context) error

Run implements component.Component.

func (*Component) Update

func (c *Component) Update(args component.Arguments) error

Update implements component.Component.

type FakeCache added in v1.14.0

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

FakeCache is a test implementation of cache.Cache that uses FakeInformers.

func (*FakeCache) Get added in v1.14.0

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

Get implements client.Reader.

func (*FakeCache) GetInformer added in v1.14.0

func (c *FakeCache) GetInformer(ctx context.Context, obj client.Object, opts ...cache.InformerGetOption) (cache.Informer, error)

GetInformer implements cache.Informers.

func (*FakeCache) GetInformerForKind added in v1.14.0

func (c *FakeCache) GetInformerForKind(ctx context.Context, gvk schema.GroupVersionKind, opts ...cache.InformerGetOption) (cache.Informer, error)

GetInformerForKind implements cache.Informers.

func (*FakeCache) IndexField added in v1.14.0

func (c *FakeCache) IndexField(ctx context.Context, obj client.Object, field string, extractValue client.IndexerFunc) error

IndexField implements cache.Cache.

func (*FakeCache) List added in v1.14.0

func (c *FakeCache) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error

List implements client.Reader.

func (*FakeCache) RemoveInformer added in v1.14.0

func (c *FakeCache) RemoveInformer(ctx context.Context, obj client.Object) error

RemoveInformer implements cache.Informers.

func (*FakeCache) Start added in v1.14.0

func (c *FakeCache) Start(ctx context.Context) error

Start implements cache.Cache. It's a no-op for fake cache.

func (*FakeCache) WaitForCacheSync added in v1.14.0

func (c *FakeCache) WaitForCacheSync(ctx context.Context) bool

WaitForCacheSync implements cache.Cache. Always returns true for fake cache.

type FakeInformer added in v1.14.0

type FakeInformer struct {
	// Synced is returned by HasSynced to implement the Informer interface.
	Synced bool
	// contains filtered or unexported fields
}

FakeInformer provides fake Informer functionality for testing. It implements the cache.Informer interface from controller-runtime.

func (*FakeInformer) Add added in v1.14.0

func (f *FakeInformer) Add(obj any)

Add triggers an Add event for the given object.

func (*FakeInformer) AddEventHandler added in v1.14.0

AddEventHandler implements cache.Informer.

func (*FakeInformer) AddEventHandlerWithResyncPeriod added in v1.14.0

func (f *FakeInformer) AddEventHandlerWithResyncPeriod(handler toolscache.ResourceEventHandler, resyncPeriod time.Duration) (toolscache.ResourceEventHandlerRegistration, error)

AddEventHandlerWithResyncPeriod implements cache.Informer.

func (*FakeInformer) AddIndexers added in v1.14.0

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

AddIndexers implements cache.Informer.

func (*FakeInformer) Delete added in v1.14.0

func (f *FakeInformer) Delete(obj any)

Delete triggers a Delete event for the given object.

func (*FakeInformer) HasSynced added in v1.14.0

func (f *FakeInformer) HasSynced() bool

HasSynced implements cache.Informer.

func (*FakeInformer) IsStopped added in v1.14.0

func (f *FakeInformer) IsStopped() bool

IsStopped implements cache.Informer.

func (*FakeInformer) RemoveEventHandler added in v1.14.0

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

RemoveEventHandler implements cache.Informer.

func (*FakeInformer) Update added in v1.14.0

func (f *FakeInformer) Update(oldObj, newObj any)

Update triggers an Update event for the given objects.

type FakeK8sFactory added in v1.14.0

type FakeK8sFactory struct {
	K8sClient kubernetes.Interface
	// contains filtered or unexported fields
}

FakeK8sFactory is a test implementation of K8sFactory that returns fake clients and caches. It uses FakeInformer to allow tests to simulate Kubernetes events without a real cluster.

func NewFakeK8sFactory added in v1.14.0

func NewFakeK8sFactory(k8sClient kubernetes.Interface) *FakeK8sFactory

NewFakeK8sFactory creates a new FakeK8sFactory with the given fake Kubernetes client.

func (*FakeK8sFactory) GetInformer added in v1.14.0

func (f *FakeK8sFactory) GetInformer(obj client.Object) *FakeInformer

GetInformer returns the FakeInformer for the given object type, creating one if it doesn't exist.

func (*FakeK8sFactory) New added in v1.14.0

New returns the fake Kubernetes client and a cache factory that creates FakeCaches.

type K8sFactory added in v1.14.0

type K8sFactory interface {
	// New creates a Kubernetes client and a cache factory.
	// The cache factory can be called multiple times to create caches with different options.
	New(clientConfig commonk8s.ClientArguments, logger *slog.Logger) (kubernetes.Interface, CacheFactory, error)
}

K8sFactory creates Kubernetes clients and cache factories. This allows tests to inject fake implementations while production code uses real ones.

type TestCrdManagerFactory added in v1.14.0

type TestCrdManagerFactory struct {
	K8sClient kubernetes.Interface
	// LogBuffer is a synchronized buffer that captures log output.
	LogBuffer *syncbuffer.Buffer
	// contains filtered or unexported fields
}

TestCrdManagerFactory creates crdManagers configured for testing. It injects a FakeK8sFactory that provides fake Kubernetes clients and caches.

func (*TestCrdManagerFactory) GetScrapeConfigJobNames added in v1.14.0

func (f *TestCrdManagerFactory) GetScrapeConfigJobNames() []string

GetScrapeConfigJobNames returns the job names of all registered scrape configs.

func (*TestCrdManagerFactory) InjectStaticTargets added in v1.14.0

func (f *TestCrdManagerFactory) InjectStaticTargets(jobName, targetAddr string) (bool, error)

InjectStaticTargets injects static targets for a job, replacing k8s service discovery. This is useful for testing since k8s SD won't work without a real cluster. Returns false if the manager is not ready yet.

func (*TestCrdManagerFactory) New added in v1.14.0

func (f *TestCrdManagerFactory) New(opts component.Options, cluster cluster.Cluster, logger *slog.Logger, args *operator.Arguments, kind string, ls labelstore.LabelStore) crdManagerInterface

New implements crdManagerFactory.

func (*TestCrdManagerFactory) TriggerServiceMonitorAdd added in v1.14.0

func (f *TestCrdManagerFactory) TriggerServiceMonitorAdd(sm *promopv1.ServiceMonitor) bool

TriggerServiceMonitorAdd triggers the add handler for a ServiceMonitor. Returns true if the trigger was executed, false if the manager is not ready yet.

func (*TestCrdManagerFactory) TriggerServiceMonitorDelete added in v1.14.0

func (f *TestCrdManagerFactory) TriggerServiceMonitorDelete(sm *promopv1.ServiceMonitor) bool

TriggerServiceMonitorDelete triggers the delete handler for a ServiceMonitor. Returns true if the trigger was executed, false if the manager is not ready yet.

func (*TestCrdManagerFactory) TriggerServiceMonitorUpdate added in v1.14.0

func (f *TestCrdManagerFactory) TriggerServiceMonitorUpdate(oldSm, newSm *promopv1.ServiceMonitor) bool

TriggerServiceMonitorUpdate triggers the update handler for a ServiceMonitor. Returns true if the trigger was executed, false if the manager is not ready yet.

Jump to

Keyboard shortcuts

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