module_manager

package
v1.0.0-beta.4 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2019 License: Apache-2.0 Imports: 23 Imported by: 4

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 (
	// All other types are deprecated. This const can be removed in future versions.
	// Module values are changed
	Changed ChangeType = "MODULE_CHANGED"
)

type CommonHook

type CommonHook struct {
	// The unique name like 'global-hooks/startup_hook' or '002-module/hooks/cleanup'.
	Name string
	// The absolute path of the executable file.
	Path string

	Bindings       []BindingType
	OrderByBinding map[BindingType]float64
	// contains filtered or unexported fields
}

func NewHook

func NewHook(name, path string, mm *MainModuleManager) *CommonHook

func (*CommonHook) GetName

func (h *CommonHook) GetName() string

func (*CommonHook) GetPath

func (h *CommonHook) GetPath() string

func (*CommonHook) SafeName

func (h *CommonHook) SafeName() string

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 {
	*CommonHook
	Config *GlobalHookConfig
}

func NewGlobalHook

func NewGlobalHook(name, path string, config *GlobalHookConfig, mm *MainModuleManager) *GlobalHook

func (*GlobalHook) PrepareTmpFilesForHookRun

func (h *GlobalHook) PrepareTmpFilesForHookRun(context []BindingContext) (tmpFiles map[string]string, err error)

PrepareTmpFilesForHookRun creates temporary files for hook and returns environment variables with paths

type GlobalHookConfig

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

type Hook

type Hook interface {
	GetName() string
	GetPath() string
	PrepareTmpFilesForHookRun(context []BindingContext) (map[string]string, error)
}

type HookConfig

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

type HookExecutor

type HookExecutor struct {
	Hook                  Hook
	Context               []BindingContext
	ConfigValuesPath      string
	ValuesPath            string
	ContextPath           string
	ConfigValuesPatchPath string
	ValuesPatchPath       string
}

func NewHookExecutor

func NewHookExecutor(h Hook, context []BindingContext) *HookExecutor

func (*HookExecutor) Run

func (e *HookExecutor) Run() (patches map[utils.ValuesPatchType]*utils.ValuesPatch, err error)

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: it calculates new arrays of enabled modules, modules that should be disabled and modules that should be purged.

This method requires that mm.enabledModulesByConfig and mm.kubeModulesConfigValues are updated.

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) 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

RunModule runs beforeHelm hook, helm upgrade --install and afterHelm or afterDeleteHelm hook

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) 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 NewModule

func NewModule(mm *MainModuleManager) *Module

func (*Module) Delete

func (m *Module) Delete() error

Delete removes helm release if it exists and runs afterDeleteHelm hooks. It is a handler for MODULE_DELETE task.

func (*Module) Run

func (m *Module) Run(onStartup bool) error

Run is a phase of module lifecycle that runs onStartup and beforeHelm hooks, helm upgrade --install command and afterHelm hook. It is a handler of task MODULE_RUN

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 {
	*CommonHook
	Module *Module
	Config *ModuleHookConfig
}

func NewModuleHook

func NewModuleHook(name, path string, config *ModuleHookConfig, mm *MainModuleManager) *ModuleHook

func (*ModuleHook) PrepareTmpFilesForHookRun

func (h *ModuleHook) PrepareTmpFilesForHookRun(context []BindingContext) (tmpFiles map[string]string, err error)

PrepareTmpFilesForHookRun creates temporary files for hook and returns environment variables with paths

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
	WithKubeConfigManager(kubeConfigManager kube_config_manager.KubeConfigManager) ModuleManager
}

type ModulesState

type ModulesState struct {
	// modules that should be run
	EnabledModules []string
	// modules that should be deleted
	ModulesToDisable []string
	// modules that should be purged
	ReleasedUnknownModules []string
}

ModulesState is a result of Discovery process, that determines which modules should be enabled, disabled or purged.

Directories

Path Synopsis
hook

Jump to

Keyboard shortcuts

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