module_manager

package
v1.0.0-beta.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ContextBindingType = map[BindingType]string{
	BeforeHelm:      "beforeHelm",
	AfterHelm:       "afterHelm",
	AfterDeleteHelm: "afterDeleteHelm",
	BeforeAll:       "beforeAll",
	AfterAll:        "afterAll",
	Schedule:        "schedule",
	OnStartup:       "onStartup",
	KubeEvents:      "onKubernetesEvent",
}

ContextBindingType is a reverse index for BindingType constants to use in BINDING_CONTEXT_PATH file.

View Source
var (
	EventCh chan Event
)

Functions

func Init

func Init()

Init loads global hooks configs, searches for modules, loads values and calculates enabled modules

Types

type BindingContext

type BindingContext struct {
	Binding           string `json:"binding"`
	ResourceEvent     string `json:"resourceEvent,omitempty"`
	ResourceNamespace string `json:"resourceNamespace,omitempty"`
	ResourceKind      string `json:"resourceKind,omitempty"`
	ResourceName      string `json:"resourceName,omitempty"`
}

BindingContext is a json with additional info for schedule and onKubeEvent hooks

type BindingType

type BindingType string

BindingType is types of events that can trigger hooks.

const (
	BeforeHelm      BindingType = "BEFORE_HELM"
	AfterHelm       BindingType = "AFTER_HELM"
	AfterDeleteHelm BindingType = "AFTER_DELETE_HELM"
	BeforeAll       BindingType = "BEFORE_ALL"
	AfterAll        BindingType = "AFTER_ALL"
	Schedule        BindingType = "SCHEDULE"
	OnStartup       BindingType = "ON_STARTUP"
	KubeEvents      BindingType = "KUBE_EVENTS"
)

type ChangeType

type ChangeType string

ChangeType are types of module changes.

const (
	// Deprecated: Module becomes enabled is handled by module discovery.
	Enabled ChangeType = "MODULE_ENABLED"
	// Deprecated: Module become disabled is handled by module discovery.
	Disabled ChangeType = "MODULE_DISABLED"
	// Module values are changed
	Changed ChangeType = "MODULE_CHANGED"
	// Deprecated: Module files are no longer available is handled by module discovery.
	Purged ChangeType = "MODULE_PURGED"
)

type Event

type Event struct {
	ModulesChanges []ModuleChange
	Type           EventType
}

Event is used to send module events to the main loop.

type EventType

type EventType string

EventType are events for the main loop.

const (
	// There are modules with changed values.
	ModulesChanged EventType = "MODULES_CHANGED"
	// Global section is changed.
	GlobalChanged EventType = "GLOBAL_CHANGED"
	// Something wrong with module manager.
	AmbigousState EventType = "AMBIGOUS_STATE"
)

type GlobalHook

type GlobalHook struct {
	*Hook
	Config *GlobalHookConfig
}

type GlobalHookConfig

type GlobalHookConfig struct {
	HookConfig
	BeforeAll interface{} `json:"beforeAll"`
	AfterAll  interface{} `json:"afterAll"`
}

type Hook

type Hook struct {
	Name           string // The unique name like 'global-hooks/startup_hook or 002-module/hooks/cleanup'.
	Path           string // The absolute path to the executable file.
	Bindings       []BindingType
	OrderByBinding map[BindingType]float64
	// contains filtered or unexported fields
}

func (*Hook) SafeName

func (h *Hook) SafeName() string

type HookConfig

type HookConfig struct {
	OnStartup         interface{}                                   `json:"onStartup"`
	Schedule          []schedule_manager.ScheduleConfig             `json:"schedule"`
	OnKubernetesEvent []kube_events_manager.OnKubernetesEventConfig `json:"onKubernetesEvent"`
}

type MainModuleManager

type MainModuleManager struct {
	// Directories
	ModulesDir     string
	GlobalHooksDir string
	TempDir        string
	// contains filtered or unexported fields
}

func NewMainModuleManager

func NewMainModuleManager() *MainModuleManager

NewMainModuleManager returns new MainModuleManager

func (*MainModuleManager) DeleteModule

func (mm *MainModuleManager) DeleteModule(moduleName string) error

TODO: moduleManager.Module(modName).Delete()

func (*MainModuleManager) DiscoverModulesState

func (mm *MainModuleManager) DiscoverModulesState() (state *ModulesState, err error)

DiscoverModulesState handles DiscoverModulesState event. This method needs updated mm.enabledModulesByConfig and mm.kubeModulesConfigValues

func (*MainModuleManager) GetGlobalHook

func (mm *MainModuleManager) GetGlobalHook(name string) (*GlobalHook, error)

func (*MainModuleManager) GetGlobalHooksInOrder

func (mm *MainModuleManager) GetGlobalHooksInOrder(bindingType BindingType) []string

func (*MainModuleManager) GetModule

func (mm *MainModuleManager) GetModule(name string) (*Module, error)

TODO replace with Module and ModuleShouldExists

func (*MainModuleManager) GetModuleHook

func (mm *MainModuleManager) GetModuleHook(name string) (*ModuleHook, error)

func (*MainModuleManager) GetModuleHooksInOrder

func (mm *MainModuleManager) GetModuleHooksInOrder(moduleName string, bindingType BindingType) ([]string, error)

func (*MainModuleManager) GetModuleNamesInOrder

func (mm *MainModuleManager) GetModuleNamesInOrder() []string

func (*MainModuleManager) Init

func (mm *MainModuleManager) Init() error

Init — initialize module manager

func (*MainModuleManager) NewModule

func (mm *MainModuleManager) NewModule() *Module

func (*MainModuleManager) Retry

func (mm *MainModuleManager) Retry()

func (*MainModuleManager) Run

func (mm *MainModuleManager) Run()

Module manager loop

func (*MainModuleManager) RunGlobalHook

func (mm *MainModuleManager) RunGlobalHook(hookName string, binding BindingType, bindingContext []BindingContext) error

func (*MainModuleManager) RunModule

func (mm *MainModuleManager) RunModule(moduleName string, onStartup bool) error

func (*MainModuleManager) RunModuleHook

func (mm *MainModuleManager) RunModuleHook(hookName string, binding BindingType, bindingContext []BindingContext) error

func (*MainModuleManager) WithDirectories

func (mm *MainModuleManager) WithDirectories(modulesDir string, globalHooksDir string, tempDir string) ModuleManager

func (*MainModuleManager) WithHelmClient

func (mm *MainModuleManager) WithHelmClient(helm helm.HelmClient) ModuleManager

func (*MainModuleManager) WithKubeConfigManager

func (mm *MainModuleManager) WithKubeConfigManager(kubeConfigManager kube_config_manager.KubeConfigManager) ModuleManager

type Module

type Module struct {
	Name          string
	DirectoryName string
	Path          string
	StaticConfig  *utils.ModuleConfig
	// contains filtered or unexported fields
}

func (*Module) SafeName

func (m *Module) SafeName() string

type ModuleChange

type ModuleChange struct {
	Name       string
	ChangeType ChangeType
}

ModuleChange contains module name and type of module changes.

type ModuleHook

type ModuleHook struct {
	*Hook
	Module *Module
	Config *ModuleHookConfig
}

type ModuleHookConfig

type ModuleHookConfig struct {
	HookConfig
	BeforeHelm      interface{} `json:"beforeHelm"`
	AfterHelm       interface{} `json:"afterHelm"`
	AfterDeleteHelm interface{} `json:"afterDeleteHelm"`
}

type ModuleManager

type ModuleManager interface {
	Init() error
	Run()
	DiscoverModulesState() (*ModulesState, error)
	GetModule(name string) (*Module, error)
	GetModuleNamesInOrder() []string
	GetGlobalHook(name string) (*GlobalHook, error)
	GetModuleHook(name string) (*ModuleHook, error)
	GetGlobalHooksInOrder(bindingType BindingType) []string
	GetModuleHooksInOrder(moduleName string, bindingType BindingType) ([]string, error)
	DeleteModule(moduleName string) error
	RunModule(moduleName string, onStartup bool) error
	RunGlobalHook(hookName string, binding BindingType, bindingContext []BindingContext) error
	RunModuleHook(hookName string, binding BindingType, bindingContext []BindingContext) error
	Retry()
	WithDirectories(modulesDir string, globalHooksDir string, tempDir string) ModuleManager
	WithHelmClient(helm helm.HelmClient) ModuleManager
	WithKubeConfigManager(kubeConfigManager kube_config_manager.KubeConfigManager) ModuleManager
}

type ModulesState

type ModulesState struct {
	EnabledModules         []string
	ModulesToDisable       []string
	ReleasedUnknownModules []string
}

All modules are in the right order to run/disable/purge

Directories

Path Synopsis
hook

Jump to

Keyboard shortcuts

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