Documentation
¶
Index ¶
- Variables
- func ApplyJqFilter(jqFilter string, obj *unstructured.Unstructured) (*ObjectAndFilterResult, error)
- func FormatFieldSelector(selector *FieldSelector) (string, error)
- func FormatLabelSelector(selector *metav1.LabelSelector) (string, error)
- func ResourceId(obj *unstructured.Unstructured) string
- type KubeEventsManager
- type Monitor
- type MonitorConfig
- func (c *MonitorConfig) AddFieldSelectorRequirement(field string, op string, value string)
- func (c *MonitorConfig) IsAnyNamespace() bool
- func (c *MonitorConfig) Names() []string
- func (c *MonitorConfig) Namespaces() (nsNames []string)
- func (c *MonitorConfig) WithEventTypes(types []WatchEventType) *MonitorConfig
- func (c *MonitorConfig) WithFieldSelector(fieldSel *FieldSelector)
- func (c *MonitorConfig) WithLabelSelector(labelSel *metav1.LabelSelector)
- func (c *MonitorConfig) WithMode(mode KubeEventMode)
- func (c *MonitorConfig) WithNameSelector(nSel *NameSelector)
- func (c *MonitorConfig) WithNamespaceSelector(nsSel *NamespaceSelector)
- type NamespaceInformer
- type ResourceInformer
Constants ¶
This section is empty.
Variables ¶
var NewKubeEventsManager = func() *kubeEventsManager { em := &kubeEventsManager{ Monitors: make(map[string]Monitor), KubeEventCh: make(chan KubeEvent, 1), } return em }
NewKubeEventsManager returns an implementation of KubeEventsManager.
var NewMonitor = func() Monitor { return &monitor{ ResourceInformers: make([]ResourceInformer, 0), VaryingInformers: make(map[string][]ResourceInformer), cancelForNs: make(map[string]context.CancelFunc), staticNamespaces: make(map[string]bool), } }
var NewNamespaceInformer = func(monitor *MonitorConfig) NamespaceInformer { informer := &namespaceInformer{ Monitor: monitor, ExistedObjects: make(map[string]bool), } return informer }
var NewResourceInformer = func(monitor *MonitorConfig) ResourceInformer { informer := &resourceInformer{ Monitor: monitor, CachedObjects: make(map[string]*ObjectAndFilterResult), cacheLock: sync.RWMutex{}, } return informer }
return cache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { nsObj := obj.(*v1.Namespace) log.Debugf("NamespaceInformer: Added ns/%s", nsObj.Name) addFn(nsObj.Name) }, DeleteFunc: func(obj interface{}) { if staleObj, stale := obj.(cache.DeletedFinalStateUnknown); stale { obj = staleObj.Obj } nsObj := obj.(*v1.Namespace) log.Debugf("NamespaceInformer: Deleted ns/%s", nsObj.Name) delFn(nsObj.Name) }, } }
Functions ¶
func ApplyJqFilter ¶
func ApplyJqFilter(jqFilter string, obj *unstructured.Unstructured) (*ObjectAndFilterResult, error)
ApplyJqFilter filter object json representation with jq expression, calculate checksum over result and return ObjectAndFilterResult. If jqFilter is empty, no filter is required and checksum is calculated over full json representation of the object.
func FormatFieldSelector ¶
func FormatLabelSelector ¶
func FormatLabelSelector(selector *metav1.LabelSelector) (string, error)
func ResourceId ¶
func ResourceId(obj *unstructured.Unstructured) string
Types ¶
type KubeEventsManager ¶
type KubeEventsManager interface {
WithContext(ctx context.Context)
WithKubeClient(client kube.KubernetesClient)
AddMonitor(monitorConfig *MonitorConfig) (*KubeEvent, error)
HasMonitor(monitorId string) bool
GetMonitor(monitorId string) Monitor
StartMonitor(monitorId string)
Start()
StopMonitor(configId string) error
Ch() chan KubeEvent
}
type Monitor ¶
type Monitor interface {
WithKubeClient(client kube.KubernetesClient)
WithConfig(config *MonitorConfig)
WithKubeEventCb(eventCb func(KubeEvent))
CreateInformers() error
Start(context.Context)
Stop()
GetExistedObjects() []ObjectAndFilterResult
GetConfig() *MonitorConfig
}
type MonitorConfig ¶
type MonitorConfig struct {
Metadata struct {
MonitorId string
DebugName string
LogLabels map[string]string
}
EventTypes []WatchEventType
ApiVersion string
Kind string
NameSelector *NameSelector
NamespaceSelector *NamespaceSelector
LabelSelector *metav1.LabelSelector
FieldSelector *FieldSelector
JqFilter string
LogEntry *log.Entry
Mode KubeEventMode
}
KubeEventMonitorConfig is a config that suits the latest version of OnKubernetesEventConfig.
func (*MonitorConfig) AddFieldSelectorRequirement ¶
func (c *MonitorConfig) AddFieldSelectorRequirement(field string, op string, value string)
func (*MonitorConfig) IsAnyNamespace ¶
func (c *MonitorConfig) IsAnyNamespace() bool
func (*MonitorConfig) Names ¶
func (c *MonitorConfig) Names() []string
Names returns names of monitored objects if nameSelector.matchNames is defined in config.
func (*MonitorConfig) Namespaces ¶
func (c *MonitorConfig) Namespaces() (nsNames []string)
Namespaces returns names of namespaces if namescpace.nameSelector is defined in config.
If no namespace specified or no namespace.nameSelector or length of namespace.nameSeletor.matchNames is 0 then empty string is returned to monitor all namespaces.
If namespace.labelSelector is specified, then return empty array.
func (*MonitorConfig) WithEventTypes ¶
func (c *MonitorConfig) WithEventTypes(types []WatchEventType) *MonitorConfig
func (*MonitorConfig) WithFieldSelector ¶
func (c *MonitorConfig) WithFieldSelector(fieldSel *FieldSelector)
WithFieldSelector copies input FieldSelector into monitor.FieldSelector
func (*MonitorConfig) WithLabelSelector ¶
func (c *MonitorConfig) WithLabelSelector(labelSel *metav1.LabelSelector)
WithLabelSelector copies input LabelSelector into monitor.LabelSelector
func (*MonitorConfig) WithMode ¶
func (c *MonitorConfig) WithMode(mode KubeEventMode)
func (*MonitorConfig) WithNameSelector ¶
func (c *MonitorConfig) WithNameSelector(nSel *NameSelector)
WithNamespaceSelector copies input NamespaceSelector into monitor.NamespaceSelector
func (*MonitorConfig) WithNamespaceSelector ¶
func (c *MonitorConfig) WithNamespaceSelector(nsSel *NamespaceSelector)
WithNamespaceSelector copies input NamespaceSelector into monitor.NamespaceSelector
type NamespaceInformer ¶
type NamespaceInformer interface {
WithKubeClient(client kube.KubernetesClient)
GetExistedObjects() map[string]bool
Run(stopCh <-chan struct{})
Stop()
}
type ResourceInformer ¶
type ResourceInformer interface {
WithKubeClient(client kube.KubernetesClient)
WithNamespace(string)
WithName(string)
WithKubeEventCb(eventCb func(KubeEvent))
GetExistedObjects() []ObjectAndFilterResult
Run(stopCh <-chan struct{})
Stop()
}
ResourceInformer is a kube informer for particular onKubernetesEvent