Documentation
¶
Index ¶
- Constants
- func SetCrdManagerFactory(c *Component, factory crdManagerFactory)
- type CacheFactory
- type Component
- type FakeCache
- func (c *FakeCache) Get(ctx context.Context, key client.ObjectKey, obj client.Object, ...) error
- func (c *FakeCache) GetInformer(ctx context.Context, obj client.Object, opts ...cache.InformerGetOption) (cache.Informer, error)
- func (c *FakeCache) GetInformerForKind(ctx context.Context, gvk schema.GroupVersionKind, ...) (cache.Informer, error)
- func (c *FakeCache) IndexField(ctx context.Context, obj client.Object, field string, ...) error
- func (c *FakeCache) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error
- func (c *FakeCache) RemoveInformer(ctx context.Context, obj client.Object) error
- func (c *FakeCache) Start(ctx context.Context) error
- func (c *FakeCache) WaitForCacheSync(ctx context.Context) bool
- type FakeInformer
- func (f *FakeInformer) Add(obj any)
- func (f *FakeInformer) AddEventHandler(handler toolscache.ResourceEventHandler) (toolscache.ResourceEventHandlerRegistration, error)
- func (f *FakeInformer) AddEventHandlerWithResyncPeriod(handler toolscache.ResourceEventHandler, resyncPeriod time.Duration) (toolscache.ResourceEventHandlerRegistration, error)
- func (f *FakeInformer) AddIndexers(indexers toolscache.Indexers) error
- func (f *FakeInformer) Delete(obj any)
- func (f *FakeInformer) HasSynced() bool
- func (f *FakeInformer) IsStopped() bool
- func (f *FakeInformer) RemoveEventHandler(handle toolscache.ResourceEventHandlerRegistration) error
- func (f *FakeInformer) Update(oldObj, newObj any)
- type FakeK8sFactory
- type K8sFactory
- type TestCrdManagerFactory
- func (f *TestCrdManagerFactory) GetScrapeConfigJobNames() []string
- func (f *TestCrdManagerFactory) InjectStaticTargets(jobName, targetAddr string) (bool, error)
- func (f *TestCrdManagerFactory) New(opts component.Options, cluster cluster.Cluster, logger *slog.Logger, ...) crdManagerInterface
- func (f *TestCrdManagerFactory) TriggerServiceMonitorAdd(sm *promopv1.ServiceMonitor) bool
- func (f *TestCrdManagerFactory) TriggerServiceMonitorDelete(sm *promopv1.ServiceMonitor) bool
- func (f *TestCrdManagerFactory) TriggerServiceMonitorUpdate(oldSm, newSm *promopv1.ServiceMonitor) bool
Constants ¶
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
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 (*Component) CurrentHealth ¶
func (*Component) NotifyClusterChange ¶
func (c *Component) NotifyClusterChange()
NotifyClusterChange implements component.ClusterComponent.
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
RemoveInformer implements cache.Informers.
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
func (f *FakeInformer) AddEventHandler(handler toolscache.ResourceEventHandler) (toolscache.ResourceEventHandlerRegistration, error)
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
func (f *FakeK8sFactory) New(_ commonk8s.ClientArguments, _ *slog.Logger) (kubernetes.Interface, CacheFactory, error)
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.