Documentation ¶
Index ¶
- Constants
- func RenderNotificationTemplate(templateStr string, params *Parameters) (string, error)
- type ChainError
- type CheckChain
- type CheckChainResult
- type CheckInstance
- type CheckResult
- type Checker
- type InstanceDescriptor
- type InstancesDescriptor
- type NotificationChain
- type NotificationData
- type NotificationDescriptor
- type NotificationInstance
- type Notifier
- type NotifyPeriodic
- type NotifyScheduled
- type Parameters
- type Registry
- func (r *Registry) LoadInstances(config *ucfgwrap.Config, descriptor *InstancesDescriptor) error
- func (r *Registry) NewCheckChain(config string) (CheckChain, error)
- func (r *Registry) NewNotificationChain(config string) (NotificationChain, error)
- func (r *Registry) NewTriggerChain(config string) (TriggerChain, error)
- type ScheduleDescriptor
- type Scheduler
- type SchedulingLogger
- 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 Expression string }
CheckChain represents a collection of multiple TriggerInstance that can be executed one after another.
func (*CheckChain) Execute ¶
func (chain *CheckChain) Execute(params Parameters) (CheckChainResult, 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 CheckChainResult ¶ added in v1.0.0
type CheckChainResult struct { Passed bool `json:"passed"` Info map[string]CheckResult `json:"info"` Expression string `json:"expression"` }
type CheckInstance ¶
CheckInstance represents a configured and named instance of a check plugin.
type CheckResult ¶ added in v1.0.0
type CheckResult struct { ID string `json:"id"` Passed bool `json:"passed"` Info map[string]any `json:"info"` }
func Failed ¶ added in v1.0.0
func Failed(info map[string]any) CheckResult
func Passed ¶ added in v1.0.0
func Passed(info map[string]any) CheckResult
type Checker ¶
type Checker interface { Check(params Parameters) (CheckResult, error) New(config *ucfgwrap.Config) (Checker, error) ID() string // OnTransition is invoked once evaluation the CheckChain this instance is the cause for a transition. OnTransition(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 *ucfgwrap.Config) (Notifier, error) ID() string }
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, log SchedulingLogger) bool
type NotifyScheduled ¶
Notifies when the given instant passed on an allowed weekday.
func (*NotifyScheduled) ShouldNotify ¶
func (ns *NotifyScheduled) ShouldNotify(current NotificationData, last NotificationData, log SchedulingLogger) bool
type Parameters ¶
type Parameters struct { Node *corev1.Node State string Profile string InMaintenance bool // if any profile is in-maintenance LogDetails bool // whether to log failing checks, notifications, ... 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 *ucfgwrap.Config, descriptor *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, log SchedulingLogger) bool }
Interface notification schedulers need to implement.
type SchedulingLogger ¶ added in v0.17.0
Used to log scheduling decisions.
type Trigger ¶
type Trigger interface { Trigger(params Parameters) error New(config *ucfgwrap.Config) (Trigger, error) ID() string }
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.