Documentation ¶
Overview ¶
Package collectors implements the collectors' logic.
Index ¶
- Variables
- func IndexPodByNode(ctx context.Context, fi client.FieldIndexer) error
- func IndexPodByPrefixName(ctx context.Context, fi client.FieldIndexer) error
- func NewPartialObjectMetadata(kind string, name *types.NamespacedName) *metav1.PartialObjectMetadata
- type CollectorOption
- func WithExternalSource(src source.Source) CollectorOption
- func WithOwnerSources(sources map[string]chan<- event.GenericEvent) CollectorOption
- func WithPodMatchingFields(podMatchingFields func(metadata *metav1.ObjectMeta) client.ListOption) CollectorOption
- func WithSubscribersChan(sChan subscriber.SubsChan) CollectorOption
- type EndpointsDispatcher
- type EndpointslicesDispatcher
- type ObjectMetaCollector
- type PodCollector
- type ServiceCollector
- func (r *ServiceCollector) GetName() string
- func (r *ServiceCollector) ObjFieldsHandler(logger logr.Logger, evt *events.Resource, svc *corev1.Service) error
- func (r *ServiceCollector) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error)
- func (r *ServiceCollector) SetupWithManager(mgr ctrl.Manager) error
- func (r *ServiceCollector) Start(ctx context.Context) error
Constants ¶
This section is empty.
Variables ¶
var EndpointsliceTransformer = func(logger logr.Logger) toolscache.TransformFunc { return func(i interface{}) (interface{}, error) { ep, ok := i.(*discoveryv1.EndpointSlice) if !ok { err := fmt.Errorf("unable to convert object to %T", discoveryv1.EndpointSlice{}) logger.Error(err, "transformer", "kind", resource.EndpointSlice) return nil, err } ep.Ports = nil filterOutMetaFields(&ep.ObjectMeta) return ep, nil } }
EndpointsliceTransformer transforms the endpointslice objects received from the api-server before adding them to the cache.
var PartialObjectTransformer = func(logger logr.Logger) toolscache.TransformFunc { return func(i interface{}) (interface{}, error) { meta, ok := i.(*metav1.PartialObjectMetadata) if !ok { err := fmt.Errorf("unable to convert object to %T", metav1.PartialObjectMetadata{}) logger.Error(err, "transformer", "kind", "PartialObjectMetadata") return nil, err } filterOutMetaFields(&meta.ObjectMeta) return meta, nil } }
PartialObjectTransformer PodTransformer transforms the metadata objects received from the api-server before adding them to the cache.
var PodTransformer = func(logger logr.Logger) toolscache.TransformFunc { return func(i interface{}) (interface{}, error) { pod, ok := i.(*corev1.Pod) if !ok { err := fmt.Errorf("unable to convert object to %T", corev1.Pod{}) logger.Error(err, "transformer", "kind", resource.Pod) return nil, err } podIP := pod.Status.PodIP pod.Status = corev1.PodStatus{PodIP: podIP} nodeName := pod.Spec.NodeName pod.Spec = corev1.PodSpec{NodeName: nodeName} filterOutMetaFields(&pod.ObjectMeta) return pod, nil } }
PodTransformer transforms the pod objects received from the api-server before adding them to the cache.
var ServiceTransformer = func(logger logr.Logger) toolscache.TransformFunc { return func(i interface{}) (interface{}, error) { svc, ok := i.(*corev1.Service) if !ok { err := fmt.Errorf("unable to convert object to %T", corev1.Service{}) logger.Error(err, "transformer", "kind", resource.Service) return nil, err } selector := svc.Spec.Selector svc.Spec = corev1.ServiceSpec{Selector: selector} svc.Status = corev1.ServiceStatus{} filterOutMetaFields(&svc.ObjectMeta) return svc, nil } }
ServiceTransformer transforms the service objects received from the api-server before adding them to the cache.
Functions ¶
func IndexPodByNode ¶
func IndexPodByNode(ctx context.Context, fi client.FieldIndexer) error
IndexPodByNode adds an indexer for bots base on the NodeName where it has been scheduled.
func IndexPodByPrefixName ¶
func IndexPodByPrefixName(ctx context.Context, fi client.FieldIndexer) error
IndexPodByPrefixName adds an indexer for pods based on the pods prefix name.
func NewPartialObjectMetadata ¶
func NewPartialObjectMetadata(kind string, name *types.NamespacedName) *metav1.PartialObjectMetadata
NewPartialObjectMetadata returns a partial object metadata for a limited set of resources. It is used as a helper when triggering reconciles or instantiating a collector for a given resource.
Types ¶
type CollectorOption ¶
type CollectorOption func(opt *collectorOptions)
CollectorOption function used to set options when creating a new meta collector.
func WithExternalSource ¶
func WithExternalSource(src source.Source) CollectorOption
WithExternalSource configure external sources that could trigger the reconcile loop of the collector.
func WithOwnerSources ¶
func WithOwnerSources(sources map[string]chan<- event.GenericEvent) CollectorOption
WithOwnerSources a map holding channels used to trigger owner's reconciles.
func WithPodMatchingFields ¶
func WithPodMatchingFields(podMatchingFields func(metadata *metav1.ObjectMeta) client.ListOption) CollectorOption
WithPodMatchingFields configures the field selector used in the list operations.
func WithSubscribersChan ¶
func WithSubscribersChan(sChan subscriber.SubsChan) CollectorOption
WithSubscribersChan configures the subscriber channel.
type EndpointsDispatcher ¶
type EndpointsDispatcher struct { client.Client // For each endpoint we save the pods' names that belong to it. Pods map[string]map[string]struct{} PodCollectorSource chan<- event.GenericEvent ServiceCollectorSource chan<- event.GenericEvent Name string }
EndpointsDispatcher each time an endpoint changes it triggers a reconcile for the pods and services to which it relates.
func (*EndpointsDispatcher) Reconcile ¶
Reconcile if a new pod has been added/removed it sends an event (triggers) to the pod collector. The same is done for the Service to which the endpoint belongs.
func (*EndpointsDispatcher) SetupWithManager ¶
func (r *EndpointsDispatcher) SetupWithManager(mgr ctrl.Manager) error
SetupWithManager sets up the controller with the Manager.
type EndpointslicesDispatcher ¶
type EndpointslicesDispatcher struct { client.Client // For each endpoint we save the pods' names that belong to it. Pods map[string]map[string]struct{} PodCollectorSource chan<- event.GenericEvent ServiceCollectorSource chan<- event.GenericEvent ServicesName map[string]string Name string }
EndpointslicesDispatcher each time an endpoint changes it triggers a reconcile for the pods and services to which it relates.
func (*EndpointslicesDispatcher) Reconcile ¶
func (r *EndpointslicesDispatcher) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error)
Reconcile if a new pod has been added/removed it sends an event (triggers) to the pod collector. The same is done for the Service to which the endpoint belongs.
func (*EndpointslicesDispatcher) SetupWithManager ¶
func (r *EndpointslicesDispatcher) SetupWithManager(mgr ctrl.Manager) error
SetupWithManager sets up the controller with the Manager.
type ObjectMetaCollector ¶
ObjectMetaCollector collects resources' metadata, puts them in a local cache and generates appropriate events when such resources change over time.
func NewObjectMetaCollector ¶
func NewObjectMetaCollector(cl client.Client, queue broker.Queue, cache *events.Cache, res *metav1.PartialObjectMetadata, name string, opt ...CollectorOption) *ObjectMetaCollector
NewObjectMetaCollector returns a new meta collector for a given resource kind.
func (*ObjectMetaCollector) GetName ¶
func (r *ObjectMetaCollector) GetName() string
GetName returns the name of the collector.
func (*ObjectMetaCollector) Reconcile ¶
Reconcile generates events to be sent to nodes when changes are detected for the watched resources.
func (*ObjectMetaCollector) SetupWithManager ¶
func (r *ObjectMetaCollector) SetupWithManager(mgr ctrl.Manager) error
SetupWithManager sets up the controller with the Manager.
type PodCollector ¶
PodCollector collects pods' metadata, puts them in a local cache and generates appropriate events when such resources change over time.
func NewPodCollector ¶
func NewPodCollector(cl client.Client, queue broker.Queue, cache *events.Cache, name string, opt ...CollectorOption) *PodCollector
NewPodCollector returns a new pod collector.
func (*PodCollector) Reconcile ¶
Reconcile generates events to be sent to nodes when changes are detected for the watched resources.
func (*PodCollector) SetupWithManager ¶
func (pc *PodCollector) SetupWithManager(mgr ctrl.Manager) error
SetupWithManager sets up the controller with the Manager.
type ServiceCollector ¶
ServiceCollector collects services' metadata, puts them in a local cache and generates appropriate events when such resources change over time.
func NewServiceCollector ¶
func NewServiceCollector(cl client.Client, queue broker.Queue, cache *events.Cache, name string, opt ...CollectorOption) *ServiceCollector
NewServiceCollector returns a new service collector.
func (*ServiceCollector) GetName ¶
func (r *ServiceCollector) GetName() string
GetName returns the name of the collector.
func (*ServiceCollector) ObjFieldsHandler ¶
func (r *ServiceCollector) ObjFieldsHandler(logger logr.Logger, evt *events.Resource, svc *corev1.Service) error
ObjFieldsHandler populates the evt from the object.
func (*ServiceCollector) Reconcile ¶
Reconcile generates events to be sent to nodes when changes are detected for the watched resources.
func (*ServiceCollector) SetupWithManager ¶
func (r *ServiceCollector) SetupWithManager(mgr ctrl.Manager) error
SetupWithManager sets up the controller with the Manager.