collectors

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2024 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Overview

Package collectors implements the collectors' logic.

Index

Constants

This section is empty.

Variables

View Source
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.

View Source
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.

View Source
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.

View Source
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

func (r *EndpointsDispatcher) 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 (*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

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

type ObjectMetaCollector struct {
	client.Client
	// contains filtered or unexported fields
}

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

func (r *ObjectMetaCollector) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error)

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.

func (*ObjectMetaCollector) Start

func (r *ObjectMetaCollector) Start(ctx context.Context) error

Start implements the runnable interface needed in order to handle the start/stop using the manager. It starts go routines needed by the collector to interact with the broker.

type PodCollector

type PodCollector struct {
	client.Client
	// contains filtered or unexported fields
}

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

func (pc *PodCollector) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error)

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.

func (*PodCollector) Start

func (pc *PodCollector) Start(ctx context.Context) error

Start implements the runnable interface needed in order to handle the start/stop using the manager. It starts go routines needed by the collector to interact with the broker.

type ServiceCollector

type ServiceCollector struct {
	client.Client
	// contains filtered or unexported fields
}

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

func (r *ServiceCollector) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error)

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.

func (*ServiceCollector) Start

func (r *ServiceCollector) Start(ctx context.Context) error

Start implements the runnable interface needed in order to handle the start/stop using the manager. It starts go routines needed by the collector to interact with the broker.

Jump to

Keyboard shortcuts

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