hook

package
v1.0.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2021 License: Apache-2.0 Imports: 31 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertFloatForBinding

func ConvertFloatForBinding(value interface{}, bindingName string) (*float64, error)

func MergeArrays

func MergeArrays(a1 []string, a2 []string) []string

MergeArrays returns merged array with unique elements. Preserve elements order.

func NewHookManager

func NewHookManager() *hookManager

Types

type CommonHook

type CommonHook interface {
	Name() string
}

type Hook

type Hook struct {
	Name   string // The unique name like '002-prometheus-hooks/startup_hook'.
	Path   string // The absolute path to the executable file.
	Config *HookConfig

	HookController controller.HookController

	TmpDir string
}

func NewHook

func NewHook(name, path string) *Hook

func (*Hook) GetConfig

func (h *Hook) GetConfig() *HookConfig

func (*Hook) GetConfigDescription

func (h *Hook) GetConfigDescription() string

func (*Hook) GetHookController

func (h *Hook) GetHookController() controller.HookController

func (*Hook) Run

func (h *Hook) Run(bindingType BindingType, context []BindingContext, logLabels map[string]string) (*HookResult, error)

func (*Hook) SafeName

func (h *Hook) SafeName() string

func (*Hook) WithConfig

func (h *Hook) WithConfig(configOutput []byte) (hook *Hook, err error)

func (*Hook) WithHookController

func (h *Hook) WithHookController(hookController controller.HookController)

func (*Hook) WithTmpDir

func (h *Hook) WithTmpDir(dir string)

type HookConfig

type HookConfig struct {
	// effective version of config
	Version string

	// versioned raw config values
	V0 *HookConfigV0
	V1 *HookConfigV1

	// effective config values
	OnStartup            *OnStartupConfig
	Schedules            []ScheduleConfig
	OnKubernetesEvents   []OnKubernetesEventConfig
	KubernetesValidating []ValidatingConfig
}

HookConfig is a structure with versioned hook configuration

func (*HookConfig) Bindings

func (c *HookConfig) Bindings() []BindingType

func (*HookConfig) CheckIncludeSnapshots

func (c *HookConfig) CheckIncludeSnapshots(includes ...string) error

CheckIncludeSnapshots check if all includes has corresponding kubernetes binding. Rules:

- binding name should exists,

- binding name should not be repeated.

func (*HookConfig) CheckOnKubernetesEventV0

func (c *HookConfig) CheckOnKubernetesEventV0(kubeCfg OnKubernetesEventConfigV0, rootPath string) error

func (*HookConfig) CheckOnKubernetesEventV1

func (c *HookConfig) CheckOnKubernetesEventV1(kubeCfg OnKubernetesEventConfigV1, rootPath string) (allErr error)

func (*HookConfig) CheckScheduleV0

func (c *HookConfig) CheckScheduleV0(schV0 ScheduleConfigV0) error

func (*HookConfig) CheckScheduleV1

func (c *HookConfig) CheckScheduleV1(schV1 ScheduleConfigV1) (allErr error)

func (*HookConfig) CheckValidatingV1

func (c *HookConfig) CheckValidatingV1(cfgV1 KubernetesValidatingConfigV1) (allErr error)

func (*HookConfig) ConvertAndCheck

func (c *HookConfig) ConvertAndCheck(data []byte) error

func (*HookConfig) ConvertAndCheckV0

func (c *HookConfig) ConvertAndCheckV0() (err error)

ConvertAndCheckV0 fills non-versioned structures and run inter-field checks not covered by OpenAPI schemas.

func (*HookConfig) ConvertAndCheckV1

func (c *HookConfig) ConvertAndCheckV1() (err error)

ConvertAndCheckV0 fills non-versioned structures and run inter-field checks not covered by OpenAPI schemas.

func (*HookConfig) ConvertOnStartup

func (c *HookConfig) ConvertOnStartup(value interface{}) (*OnStartupConfig, error)

func (*HookConfig) ConvertScheduleV0

func (c *HookConfig) ConvertScheduleV0(schV0 ScheduleConfigV0) (ScheduleConfig, error)

func (*HookConfig) ConvertScheduleV1

func (c *HookConfig) ConvertScheduleV1(schV1 ScheduleConfigV1) (ScheduleConfig, error)

func (*HookConfig) ConvertValidatingV1

func (c *HookConfig) ConvertValidatingV1(cfgV1 KubernetesValidatingConfigV1) (ValidatingConfig, error)

func (*HookConfig) HasBinding

func (c *HookConfig) HasBinding(binding BindingType) bool

func (*HookConfig) LoadAndValidate

func (c *HookConfig) LoadAndValidate(data []byte) error

LoadAndValidate loads config from bytes and validate it. Returns multierror.

func (*HookConfig) MonitorConfigId

func (c *HookConfig) MonitorConfigId() string

TODO uuid is not a good choice here. Make it more readable.

func (*HookConfig) MonitorDebugName

func (c *HookConfig) MonitorDebugName(configName string, configIndex int) string

func (*HookConfig) ScheduleId

func (c *HookConfig) ScheduleId() string

TODO uuid is not a good choice here. Make it more readable.

type HookConfigV0

type HookConfigV0 struct {
	OnStartup         interface{}                 `json:"onStartup"`
	Schedule          []ScheduleConfigV0          `json:"schedule"`
	OnKubernetesEvent []OnKubernetesEventConfigV0 `json:"onKubernetesEvent"`
}

type HookConfigV1

type HookConfigV1 struct {
	ConfigVersion        string                         `json:"configVersion"`
	OnStartup            interface{}                    `json:"onStartup"`
	Schedule             []ScheduleConfigV1             `json:"schedule"`
	OnKubernetesEvent    []OnKubernetesEventConfigV1    `json:"kubernetes"`
	KubernetesValidating []KubernetesValidatingConfigV1 `json:"kubernetesValidating"`
}

type HookManager

type HookManager interface {
	Init() error
	Run()
	WithDirectories(workingDir string, tempDir string)
	WithKubeEventManager(kube_events_manager.KubeEventsManager)
	WithScheduleManager(schedule_manager.ScheduleManager)
	WithWebhookManager(*validating_webhook.WebhookManager)
	WorkingDir() string
	TempDir() string
	GetHook(name string) *Hook
	GetHookNames() []string
	GetHooksInOrder(bindingType BindingType) ([]string, error)
	HandleKubeEvent(kubeEvent KubeEvent, createTaskFn func(*Hook, controller.BindingExecutionInfo))
	HandleScheduleEvent(crontab string, createTaskFn func(*Hook, controller.BindingExecutionInfo))
	HandleValidatingEvent(event ValidatingEvent, createTaskFn func(*Hook, controller.BindingExecutionInfo))
}

type HookResult

type HookResult struct {
	Usage              *executor.CmdUsage
	Metrics            []operation.MetricOperation
	ValidatingResponse *ValidatingResponse
}

type KubeFieldSelectorV1

type KubeFieldSelectorV1 FieldSelector

type KubeNameSelectorV1

type KubeNameSelectorV1 NameSelector

type KubeNamespaceSelectorV0

type KubeNamespaceSelectorV0 struct {
	MatchNames []string `json:"matchNames"`
	Any        bool     `json:"any"`
}

type KubeNamespaceSelectorV1

type KubeNamespaceSelectorV1 NamespaceSelector

type KubernetesValidatingConfigV1

type KubernetesValidatingConfigV1 struct {
	Name                 string                   `json:"name,omitempty"`
	IncludeSnapshotsFrom []string                 `json:"includeSnapshotsFrom,omitempty"`
	Group                string                   `json:"group,omitempty"`
	Rules                []v1.RuleWithOperations  `json:"rules,omitempty"`
	FailurePolicy        *v1.FailurePolicyType    `json:"failurePolicy"`
	LabelSelector        *metav1.LabelSelector    `json:"labelSelector,omitempty"`
	Namespace            *KubeNamespaceSelectorV1 `json:"namespace,omitempty"`
	SideEffects          *v1.SideEffectClass      `json:"sideEffects"`
	TimeoutSeconds       *int32                   `json:"timeoutSeconds,omitempty"`
}

version 1 of kubernetes event configuration

type OnKubernetesEventConfigV0

type OnKubernetesEventConfigV0 struct {
	Name              string                   `json:"name,omitempty"`
	EventTypes        []string                 `json:"event,omitempty"`
	Kind              string                   `json:"kind,omitempty"`
	Selector          *metav1.LabelSelector    `json:"selector,omitempty"`
	ObjectName        string                   `json:"objectName,omitempty"`
	NamespaceSelector *KubeNamespaceSelectorV0 `json:"namespaceSelector,omitempty"`
	JqFilter          string                   `json:"jqFilter,omitempty"`
	AllowFailure      bool                     `json:"allowFailure,omitempty"`
}

Legacy version of kubernetes event configuration

type OnKubernetesEventConfigV1

type OnKubernetesEventConfigV1 struct {
	Name                         string                   `json:"name,omitempty"`
	WatchEventTypes              []WatchEventType         `json:"watchEvent,omitempty"`
	ExecuteHookOnEvents          []WatchEventType         `json:"executeHookOnEvent,omitempty"`
	ExecuteHookOnSynchronization string                   `json:"executeHookOnSynchronization,omitempty"`
	WaitForSynchronization       string                   `json:"waitForSynchronization,omitempty"`
	KeepFullObjectsInMemory      string                   `json:"keepFullObjectsInMemory,omitempty"`
	Mode                         KubeEventMode            `json:"mode,omitempty"`
	ApiVersion                   string                   `json:"apiVersion,omitempty"`
	Kind                         string                   `json:"kind,omitempty"`
	NameSelector                 *KubeNameSelectorV1      `json:"nameSelector,omitempty"`
	LabelSelector                *metav1.LabelSelector    `json:"labelSelector,omitempty"`
	FieldSelector                *KubeFieldSelectorV1     `json:"fieldSelector,omitempty"`
	Namespace                    *KubeNamespaceSelectorV1 `json:"namespace,omitempty"`
	JqFilter                     string                   `json:"jqFilter,omitempty"`
	AllowFailure                 bool                     `json:"allowFailure,omitempty"`
	ResynchronizationPeriod      string                   `json:"resynchronizationPeriod,omitempty"`
	IncludeSnapshotsFrom         []string                 `json:"includeSnapshotsFrom,omitempty"`
	Queue                        string                   `json:"queue,omitempty"`
	Group                        string                   `json:"group,omitempty"`
}

version 1 of kubernetes event configuration

type ScheduleConfigV0

type ScheduleConfigV0 struct {
	Name         string `json:"name"`
	Crontab      string `json:"crontab"`
	AllowFailure bool   `json:"allowFailure"`
}

Schedule configuration

type ScheduleConfigV1

type ScheduleConfigV1 struct {
	Name                 string   `json:"name"`
	Crontab              string   `json:"crontab"`
	AllowFailure         bool     `json:"allowFailure"`
	IncludeSnapshotsFrom []string `json:"includeSnapshotsFrom"`
	Queue                string   `json:"queue"`
	Group                string   `json:"group,omitempty"`
}

Schedule configuration

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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