module_manager

package
v1.0.0-beta.6 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2020 License: Apache-2.0 Imports: 35 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ValidModuleNameRe = regexp.MustCompile(`^[0-9][0-9][0-9]-(.*)$`)

Functions

func CreateEmptyWritableFile

func CreateEmptyWritableFile(filePath string) error

func GetGlobalHookConfigSchema

func GetGlobalHookConfigSchema(version string) *spec.Schema

func GetModuleHookConfigSchema

func GetModuleHookConfigSchema(version string) *spec.Schema

func NewMainModuleManager

func NewMainModuleManager() *moduleManager

NewMainModuleManager returns new MainModuleManager

Types

type AfterAllConfig

type AfterAllConfig struct {
	CommonBindingConfig
	Order float64
}

type AfterDeleteHelmConfig

type AfterDeleteHelmConfig struct {
	CommonBindingConfig
	Order float64
}

type AfterHelmConfig

type AfterHelmConfig struct {
	CommonBindingConfig
	Order float64
}

type BeforeAllConfig

type BeforeAllConfig struct {
	CommonBindingConfig
	Order float64
}

type BeforeHelmConfig

type BeforeHelmConfig struct {
	CommonBindingConfig
	Order float64
}

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 {
	hook.Hook
	// contains filtered or unexported fields
}

func (*CommonHook) GetName

func (h *CommonHook) GetName() string

func (*CommonHook) GetPath

func (h *CommonHook) GetPath() string

func (*CommonHook) WithModuleManager

func (c *CommonHook) WithModuleManager(moduleManager *moduleManager)

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.
	AmbiguousState EventType = "AMBIGUOUS_STATE"
)

type GlobalHook

type GlobalHook struct {
	*CommonHook
	Config *GlobalHookConfig
}

func NewGlobalHook

func NewGlobalHook(name, path string) *GlobalHook

func SearchGlobalHooks

func SearchGlobalHooks(hooksDir string) (hooks []*GlobalHook, err error)

SearchGlobalHooks recursively find all executables in hooksDir. Absent hooksDir is not an error.

func (*GlobalHook) GetConfigDescription

func (gh *GlobalHook) GetConfigDescription() string

func (*GlobalHook) Order

func (g *GlobalHook) Order(binding BindingType) float64

Order return float order number for bindings with order.

func (*GlobalHook) PrepareTmpFilesForHookRun

func (h *GlobalHook) PrepareTmpFilesForHookRun(bindingContext []byte) (tmpFiles map[string]string, err error)

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

func (*GlobalHook) Run

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

func (*GlobalHook) WithConfig

func (g *GlobalHook) WithConfig(configOutput []byte) (err error)

type GlobalHookConfig

type GlobalHookConfig struct {
	hook_config.HookConfig

	// versioned raw config values
	GlobalV0 *GlobalHookConfigV0
	GlobalV1 *GlobalHookConfigV0

	// effective config values
	BeforeAll *BeforeAllConfig
	AfterAll  *AfterAllConfig
}

GlobalHookConfig is a structure with versioned hook configuration

func (*GlobalHookConfig) Bindings

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

func (*GlobalHookConfig) ConvertAfterAll

func (c *GlobalHookConfig) ConvertAfterAll(value interface{}) (*AfterAllConfig, error)

func (*GlobalHookConfig) ConvertAndCheck

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

func (*GlobalHookConfig) ConvertAndCheckV0

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

func (*GlobalHookConfig) ConvertAndCheckV1

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

func (*GlobalHookConfig) ConvertBeforeAll

func (c *GlobalHookConfig) ConvertBeforeAll(value interface{}) (*BeforeAllConfig, error)

func (*GlobalHookConfig) HasBinding

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

func (*GlobalHookConfig) LoadAndValidate

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

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

type GlobalHookConfigV0

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

type Hook

type Hook interface {
	WithModuleManager(moduleManager *moduleManager)
	WithConfig(configOutput []byte) (err error)
	WithHookController(hookController controller.HookController)
	GetHookController() controller.HookController
	GetName() string
	GetPath() string
	PrepareTmpFilesForHookRun(bindingContext []byte) (map[string]string, error)
	Order(binding BindingType) float64
}

type HookExecutor

type HookExecutor struct {
	Hook                  Hook
	Context               BindingContextList
	ConfigValuesPath      string
	ValuesPath            string
	ContextPath           string
	ConfigValuesPatchPath string
	ValuesPatchPath       string
	MetricsPath           string
	LogLabels             map[string]string
}

func NewHookExecutor

func NewHookExecutor(h Hook, context BindingContextList) *HookExecutor

func (*HookExecutor) Config

func (e *HookExecutor) Config() (configOutput []byte, err error)

func (*HookExecutor) Run

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

func (*HookExecutor) WithLogLabels

func (e *HookExecutor) WithLogLabels(logLabels map[string]string)

type Module

type Module struct {
	Name string
	Path string
	// module values from modules/values.yaml file
	CommonStaticConfig *utils.ModuleConfig
	// module values from modules/<module name>/values.yaml
	StaticConfig *utils.ModuleConfig

	LastReleaseManifests []manifest.Manifest
	// contains filtered or unexported fields
}

func NewModule

func NewModule(name, path string) *Module

func SearchModules

func SearchModules(modulesDir string) (modules []*Module, err error)

func (*Module) ConfigValues

func (m *Module) ConfigValues() utils.Values

ConfigValues returns values from ConfigMap: global section and module section

func (*Module) Delete

func (m *Module) Delete(logLabels map[string]string) 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, logLabels map[string]string, afterStartupCb func() error) (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

func (*Module) ShouldRunHelmUpgrade

func (m *Module) ShouldRunHelmUpgrade(helmClient helm.HelmClient, releaseName string, checksum string, manifests []manifest.Manifest, logLabels map[string]string) (bool, error)

func (*Module) Values

func (m *Module) Values() (utils.Values, error)

values returns merged values for hooks. There is enabledModules key in global section with all enabled modules.

func (*Module) ValuesKey

func (m *Module) ValuesKey() string

func (*Module) ValuesPatches

func (m *Module) ValuesPatches() []utils.ValuesPatch

func (*Module) WithModuleManager

func (m *Module) WithModuleManager(moduleManager *moduleManager)

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

func SearchModuleHooks

func SearchModuleHooks(module *Module) (hooks []*ModuleHook, err error)

func (*ModuleHook) GetConfigDescription

func (m *ModuleHook) GetConfigDescription() string

func (*ModuleHook) Order

func (m *ModuleHook) Order(binding BindingType) float64

Order return float order number for bindings with order.

func (*ModuleHook) PrepareTmpFilesForHookRun

func (h *ModuleHook) PrepareTmpFilesForHookRun(bindingContext []byte) (tmpFiles map[string]string, err error)

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

func (*ModuleHook) Run

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

func (*ModuleHook) WithConfig

func (m *ModuleHook) WithConfig(configOutput []byte) (err error)

func (*ModuleHook) WithModule

func (m *ModuleHook) WithModule(module *Module)

type ModuleHookConfig

type ModuleHookConfig struct {
	sh_op_hook.HookConfig

	// versioned raw config values
	ModuleV0 *ModuleHookConfigV0
	ModuleV1 *ModuleHookConfigV0

	// effective config values
	BeforeHelm      *BeforeHelmConfig
	AfterHelm       *AfterHelmConfig
	AfterDeleteHelm *AfterDeleteHelmConfig
}

ModuleHookConfig is a structure with versioned hook configuration

func (*ModuleHookConfig) Bindings

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

func (*ModuleHookConfig) ConvertAfterDeleteHelm

func (c *ModuleHookConfig) ConvertAfterDeleteHelm(value interface{}) (*AfterDeleteHelmConfig, error)

func (*ModuleHookConfig) ConvertAfterHelm

func (c *ModuleHookConfig) ConvertAfterHelm(value interface{}) (*AfterHelmConfig, error)

func (*ModuleHookConfig) ConvertAndCheck

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

func (*ModuleHookConfig) ConvertAndCheckV0

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

func (*ModuleHookConfig) ConvertAndCheckV1

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

func (*ModuleHookConfig) ConvertBeforeHelm

func (c *ModuleHookConfig) ConvertBeforeHelm(value interface{}) (*BeforeHelmConfig, error)

func (*ModuleHookConfig) HasBinding

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

func (*ModuleHookConfig) LoadAndValidate

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

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

type ModuleHookConfigV0

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

type ModuleManager

type ModuleManager interface {
	Init() error
	Start()
	Ch() chan Event

	WithContext(ctx context.Context)
	WithDirectories(modulesDir string, globalHooksDir string, tempDir string) ModuleManager
	WithKubeEventManager(kube_events_manager.KubeEventsManager)
	WithScheduleManager(schedule_manager.ScheduleManager)
	WithKubeConfigManager(kubeConfigManager kube_config_manager.KubeConfigManager) ModuleManager
	WithHelmResourcesManager(manager helm_resources_manager.HelmResourcesManager)
	WithMetricStorage(storage *metrics_storage.MetricStorage)

	GetModule(name string) *Module
	GetModuleNamesInOrder() []string
	GetModuleHookNames(moduleName string) []string
	GetGlobalHook(name string) *GlobalHook
	GetModuleHook(name string) *ModuleHook
	GetGlobalHooksInOrder(bindingType BindingType) []string
	GetModuleHooksInOrder(moduleName string, bindingType BindingType) []string

	GlobalConfigValues() utils.Values
	GlobalValues() (utils.Values, error)
	GlobalValuesPatches() []utils.ValuesPatch

	DiscoverModulesState(logLabels map[string]string) (*ModulesState, error)
	DeleteModule(moduleName string, logLabels map[string]string) error
	RunModule(moduleName string, onStartup bool, logLabels map[string]string, afterStartupCb func() error) (bool, error)
	RunGlobalHook(hookName string, binding BindingType, bindingContext []BindingContext, logLabels map[string]string) (beforeChecksum string, afterChecksum string, err error)
	RunModuleHook(hookName string, binding BindingType, bindingContext []BindingContext, logLabels map[string]string) error
	Retry()

	RegisterModuleHooks(module *Module, logLabels map[string]string) error

	HandleKubeEvent(kubeEvent KubeEvent, createGlobalTaskFn func(*GlobalHook, controller.BindingExecutionInfo), createModuleTaskFn func(*Module, *ModuleHook, controller.BindingExecutionInfo))
	HandleGlobalEnableKubernetesBindings(hookName string, createTaskFn func(*GlobalHook, controller.BindingExecutionInfo)) error
	HandleModuleEnableKubernetesBindings(hookName string, createTaskFn func(*ModuleHook, controller.BindingExecutionInfo)) error
	StartModuleHooks(moduleName string)
	//EnableScheduleBindings()
	DisableModuleHooks(moduleName string)
	HandleScheduleEvent(crontab string, createGlobalTaskFn func(*GlobalHook, controller.BindingExecutionInfo), createModuleTaskFn func(*Module, *ModuleHook, controller.BindingExecutionInfo)) error
}

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
	// modules that was disabled and now are enabled
	NewlyEnabledModules []string
}

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

Jump to

Keyboard shortcuts

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