Documentation ¶
Index ¶
- Constants
- func RenderNotificationTemplate(templateStr string, params *Parameters) (string, error)
- type ChainError
- type CheckChain
- type CheckInstance
- type Checker
- type InstanceDescriptor
- type InstancesDescriptor
- type NotificationChain
- type NotificationData
- type NotificationDescriptor
- type NotificationInstance
- type Notifier
- type NotifyPeriodic
- type NotifyScheduled
- type Parameters
- type Registry
- type ScheduleDescriptor
- type Scheduler
- type Trigger
- type TriggerChain
- type TriggerInstance
Constants ¶
const AndSeparator = "&&"
AndSeparator is a string that is used to combine two plugin instance within a config string.
const OrSeparator = "||"
OrSeparator is a string that is used to combine two plugin instance within a config string.
Variables ¶
This section is empty.
Functions ¶
func RenderNotificationTemplate ¶
func RenderNotificationTemplate(templateStr string, params *Parameters) (string, error)
Renders the given template string using the provided parameters.
Types ¶
type ChainError ¶
ChainError wraps an error that causes a PluginChain to fail.
func (*ChainError) Error ¶
func (e *ChainError) Error() string
func (*ChainError) Unwrap ¶
func (e *ChainError) Unwrap() error
type CheckChain ¶
type CheckChain struct { Plugins []CheckInstance Evaluable gval.Evaluable }
CheckChain represents a collection of multiple TriggerInstance that can be executed one after another.
func (*CheckChain) Execute ¶
func (chain *CheckChain) Execute(params Parameters) (bool, error)
Execute invokes Trigger on each TriggerInstance in the chain and aborts when a plugin returns an error. It returns true if all checks passed.
type CheckInstance ¶
CheckInstance represents a configured and named instance of a check plugin.
type Checker ¶
type Checker interface { Check(params Parameters) (bool, error) New(config *ucfg.Config) (Checker, error) // AfterEval is invoked once after evaluation the CheckChain this instance is part of. AfterEval(chainResult bool, params Parameters) error }
Checker is the interface that check plugins need to implement. Check plugins have to be idempotent, as they are invoked multiple times. A zero-initialized check plugin should not actually work as it is used to create the actual usable configured instances.
type InstanceDescriptor ¶
Specifies the configuration for a single check/trigger instance.
type InstancesDescriptor ¶
type InstancesDescriptor struct { Check []InstanceDescriptor Notify []NotificationDescriptor Trigger []InstanceDescriptor }
Specifies the configuration for instances.
type NotificationChain ¶
type NotificationChain struct {
Plugins []NotificationInstance
}
NotificationChain represents a collection of multiple NotificationInstance that can be executed one after another.
func (*NotificationChain) Execute ¶
func (chain *NotificationChain) Execute(params Parameters) error
Execute invokes Notify on each NotificationInstance in the chain and aborts when a plugin returns an error.
type NotificationData ¶
type NotificationData struct { // Technically state.NodeStateLabel, but that causes a cyclic import State string Time time.Time }
Data used to determine, whether to notify or not.
type NotificationDescriptor ¶
type NotificationDescriptor struct { Name string Type string Schedule ScheduleDescriptor `config:"schedule" validate:"required"` Config *ucfg.Config }
Specifies the configuration for a single notification instance.
type NotificationInstance ¶
NotificationInstance represents a configured and named instance of a notification plugin.
type Notifier ¶
type Notifier interface { Notify(params Parameters) error New(config *ucfg.Config) (Notifier, error) }
Notifier is the interface that notification plugins need to implement. It is recommend to make notification plugins idempotent, as the same message might be send multiple times. A zero-initialized notification plugin should not actually work as it is used to create the actual usable configured instances.
type NotifyPeriodic ¶
Notifies on state changes and after passing the interval since the last notification if not the operational state.
func (*NotifyPeriodic) ShouldNotify ¶
func (np *NotifyPeriodic) ShouldNotify(current NotificationData, last NotificationData) bool
type NotifyScheduled ¶
Notifies when the given instant passed on an allowed weekday.
func (*NotifyScheduled) ShouldNotify ¶
func (ns *NotifyScheduled) ShouldNotify(current NotificationData, last NotificationData) bool
type Parameters ¶
type Parameters struct { Node *corev1.Node State string Profile string InMaintenance bool // if any profile is in-maintenance Client client.Client Ctx context.Context Log logr.Logger Recorder record.EventRecorder LastTransition time.Time }
Parameters describes the parameters plugins get to work with.
type Registry ¶
type Registry struct { NotificationInstances map[string]NotificationInstance NotificationPlugins map[string]Notifier CheckInstances map[string]CheckInstance CheckPlugins map[string]Checker TriggerInstances map[string]TriggerInstance TriggerPlugins map[string]Trigger }
Registry is a central storage for all plugins and their instances.
func NewRegistry ¶
func NewRegistry() Registry
NewRegistry creates a new registry with non-null maps.
func (*Registry) LoadInstances ¶
func (r *Registry) LoadInstances(config *InstancesDescriptor) error
LoadInstances parses the given config and constructs plugin instances accordingly. These instances are put into the respective instances map within the registry.
func (*Registry) NewCheckChain ¶
func (r *Registry) NewCheckChain(config string) (CheckChain, error)
NewCheckChain creates a CheckChain based the given config string.
func (*Registry) NewNotificationChain ¶
func (r *Registry) NewNotificationChain(config string) (NotificationChain, error)
NewNotificationChain creates a NotificaitonChain based the given config string.
func (*Registry) NewTriggerChain ¶
func (r *Registry) NewTriggerChain(config string) (TriggerChain, error)
NewTriggerChain creates a TriggerChain based the given config string.
type ScheduleDescriptor ¶
type ScheduleDescriptor struct { Type string Config *ucfg.Config }
Specifies the configuration for a Scheduler.
type Scheduler ¶
type Scheduler interface { // Determines if a notification is required. ShouldNotify(current NotificationData, last NotificationData) bool }
Interface notification schedulers need to implement.
type Trigger ¶
type Trigger interface { Trigger(params Parameters) error New(config *ucfg.Config) (Trigger, error) }
Trigger is the interface that trigger plugins need to implement. It is recommend to make trigger plugins idempotent, as the same trigger might be invoked multiple times. A zero-initialized trigger plugin should not actually work as it is used to create the actual usable configured instances.
type TriggerChain ¶
type TriggerChain struct {
Plugins []TriggerInstance
}
TriggerChain represents a collection of multiple TriggerInstance that can be executed one after another.
func (*TriggerChain) Execute ¶
func (chain *TriggerChain) Execute(params Parameters) error
Execute invokes Trigger on each TriggerInstance in the chain and aborts when a plugin returns an error.
type TriggerInstance ¶
TriggerInstance represents a configured and named instance of a trigger plugin.