events

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package events provides the events generated by the collectors.

Index

Constants

View Source
const (
	// Create possible type for an event.
	Create = "Create"
	// Update possible type for an event.
	Update = "Update"
	// Delete possible type for an event.
	Delete = "Delete"
)

Variables

This section is empty.

Functions

func ManagingOwner

func ManagingOwner(owners []v1.OwnerReference) *v1.OwnerReference

ManagingOwner returns the controller owner of the resource if present.

Types

type Cache

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

Cache for resources items. For each resource that is sent to at least a subscriber it is saved in a cache. The cache is useful for this scenarios:

  1. each time a new subscriber arrives the cache is used to trigger the respective collector for the cached resources. This way the subscriber receives all the existing resources.
  2. When a resource is deleted we need to know the subscribers that need a Delete event. The cache provides the sayed subscribers.
  3. When a resource is updated the cache knows the subscribers that need an Update event.

func NewCache

func NewCache() *Cache

NewCache creates a new Cache.

func (*Cache) Add

func (gc *Cache) Add(key string, value *CacheEntry)

Add adds a new item to the cache if it does not exist.

func (*Cache) Delete

func (gc *Cache) Delete(key string)

Delete deletes an item from the cache.

func (*Cache) Get

func (gc *Cache) Get(key string) (*CacheEntry, bool)

Get returns an item from the cache using the provided key.

func (*Cache) Has

func (gc *Cache) Has(key string) bool

Has returns true if a key is present.

func (*Cache) Update

func (gc *Cache) Update(key string, value *CacheEntry)

Update updates an item in the cache.

type CacheEntry

type CacheEntry struct {
	Hash uint64
	UID  types.UID
	Refs fields.References
	Subs fields.Subscribers
}

CacheEntry items that can be saved in the cache.

type Event

type Event struct {
	*metadata.Event
	Subs fields.Subscribers
}

Event generated for watched kubernetes resources.

func (*Event) GRPCMessage

func (ge *Event) GRPCMessage() *metadata.Event

GRPCMessage returns the grpc message ready to be sent over the grpc connection.

func (*Event) ResourceKind

func (ge *Event) ResourceKind() string

ResourceKind returns the Kind of the resource for which the event has been crafted.

func (*Event) String

func (ge *Event) String() string

String returns the event in string format.

func (*Event) Subscribers

func (ge *Event) Subscribers() fields.Subscribers

Subscribers returns the destination nodes.

func (*Event) Type

func (ge *Event) Type() string

Type returns the event type.

type Interface

type Interface interface {
	Subscribers() fields.Subscribers
	String() string
	Type() string
	ResourceKind() string
	GRPCMessage() *metadata.Event
}

Interface must be satisfied by events generated for each supported k8s resource. Evens are generated by the collectors and sent to the message broker which is in charge to deliver them to all subscribers that have an interest for those events.

type Resource

type Resource struct {
	Kind   string
	UID    string
	Meta   string
	Spec   string
	Status string
	// Only used when storing metadata for pods.
	ResourceReferences fields.References
	// contains filtered or unexported fields
}

Resource event that holds metadata fields for k8s resources.

func NewResource

func NewResource(kind, uid string) *Resource

NewResource returns a new Resource.

func (*Resource) AddReferencesForKind

func (g *Resource) AddReferencesForKind(kind string, refs []fields.Reference)

AddReferencesForKind adds references for a given Kind in the pod event.

func (*Resource) GenerateSubscribers

func (g *Resource) GenerateSubscribers(subs fields.Subscribers) fields.Subscribers

GenerateSubscribers populates the subscribers to which the events need to be sent, starting from the given subscribers. The starting point are the cached subscribers to which we already know that we have sent at least a "Create" event. From the cached subscribers and the passed ones it generates the subscribers to which we need to send an event and saves them in the appropriate field, i.e. Resource.createdFor, Resource.updatedFor and Resource.deletedFor. At the same time the Resource.nodes field is updated based on the new added or deleted nodes.

func (*Resource) GetMetadata

func (g *Resource) GetMetadata() string

GetMetadata returns the metadata field.

func (*Resource) GetResourceReferences

func (g *Resource) GetResourceReferences() fields.References

GetResourceReferences returns refs.

func (*Resource) GetSpec

func (g *Resource) GetSpec() string

GetSpec returns the Spec field.

func (*Resource) GetStatus

func (g *Resource) GetStatus() string

GetStatus returns the Status field.

func (*Resource) GetSubscribers

func (g *Resource) GetSubscribers() fields.Subscribers

GetSubscribers returns the nodes.

func (*Resource) SetMeta

func (g *Resource) SetMeta(meta string)

SetMeta sets the Meta field if different from the existing one. It also sets to true the "updated" internal variable.

func (*Resource) SetSpec

func (g *Resource) SetSpec(spec string)

SetSpec sets the Spec field if different from the existing one. It also sets to true the "updated" internal variable.

func (*Resource) SetStatus

func (g *Resource) SetStatus(status string)

SetStatus sets the Status field if different from the existing one. It also sets to true the "updated" internal variable.

func (*Resource) SetSubscribers

func (g *Resource) SetSubscribers(subs fields.Subscribers)

SetSubscribers populates the nodes to which send the event.

func (*Resource) SetUpdate

func (g *Resource) SetUpdate(update bool)

SetUpdate sets the update flag for the resource.

func (*Resource) ToEvents

func (g *Resource) ToEvents() []Interface

ToEvents returns a slice containing Interface based on the internal state of the Resource.

Jump to

Keyboard shortcuts

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