module_manager

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2024 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DirectoryConfig

type DirectoryConfig struct {
	ModulesDir     string
	GlobalHooksDir string
	TempDir        string
}

DirectoryConfig configures directories for ModuleManager

type KubeConfigManager

type KubeConfigManager interface {
	SaveConfigValues(key string, values utils.Values) error
	IsModuleEnabled(moduleName string) bool
	UpdateModuleConfig(moduleName string) error
	SafeReadConfig(handler func(config *config.KubeConfig))
}

type ModuleManager

type ModuleManager struct {

	// Directories.
	ModulesDir     string
	GlobalHooksDir string
	TempDir        string
	// contains filtered or unexported fields
}

func NewModuleManager

func NewModuleManager(ctx context.Context, cfg *ModuleManagerConfig) *ModuleManager

NewModuleManager returns new MainModuleManager

func (*ModuleManager) AddEnabledModuleByConfigName

func (mm *ModuleManager) AddEnabledModuleByConfigName(name string)

func (*ModuleManager) AddEnabledModuleName

func (mm *ModuleManager) AddEnabledModuleName(name string)

func (*ModuleManager) ApplyBindingActions

func (mm *ModuleManager) ApplyBindingActions(moduleHook *hooks.ModuleHook, bindingActions []go_hook.BindingAction) error

func (*ModuleManager) AreModulesInited

func (mm *ModuleManager) AreModulesInited() bool

AreModulesInited returns true if modulemanager's moduleset has already been initialized

func (*ModuleManager) DeleteEnabledModuleByConfigName

func (mm *ModuleManager) DeleteEnabledModuleByConfigName(name string)

func (*ModuleManager) DeleteEnabledModuleName

func (mm *ModuleManager) DeleteEnabledModuleName(name string)

func (*ModuleManager) DeleteModule

func (mm *ModuleManager) DeleteModule(moduleName string, logLabels map[string]string) error

func (*ModuleManager) DisableModuleHooks

func (mm *ModuleManager) DisableModuleHooks(moduleName string)

DisableModuleHooks disables monitors/bindings of the module's hooks It's advisable to use this method only if next step is to completely disable the module (as a short-term commitment). Otherwise, as hooks are rather stateless, their confiuration may get overwritten, resulting in unexpected consequences.

func (*ModuleManager) DumpDynamicEnabled

func (mm *ModuleManager) DumpDynamicEnabled() string

func (*ModuleManager) DynamicEnabledChecksum

func (mm *ModuleManager) DynamicEnabledChecksum() string

DynamicEnabledChecksum returns checksum for dynamicEnabled map

func (*ModuleManager) EnableModuleScheduleBindings

func (mm *ModuleManager) EnableModuleScheduleBindings(moduleName string)

func (*ModuleManager) GetDependencies

func (mm *ModuleManager) GetDependencies() *ModuleManagerDependencies

GetDependencies fetch dependencies struct from ModuleManager note: not the best way but it's required in some hooks

func (*ModuleManager) GetEnabledModuleNames

func (mm *ModuleManager) GetEnabledModuleNames() []string

func (*ModuleManager) GetGlobal

func (mm *ModuleManager) GetGlobal() *modules.GlobalModule

func (*ModuleManager) GetGlobalHook

func (mm *ModuleManager) GetGlobalHook(name string) *hooks.GlobalHook

func (*ModuleManager) GetGlobalHooksInOrder

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

func (*ModuleManager) GetGlobalHooksNames

func (mm *ModuleManager) GetGlobalHooksNames() []string

func (*ModuleManager) GetKubeConfigValid

func (mm *ModuleManager) GetKubeConfigValid() bool

func (*ModuleManager) GetModule

func (mm *ModuleManager) GetModule(name string) *modules.BasicModule

func (*ModuleManager) GetModuleEventsChannel

func (mm *ModuleManager) GetModuleEventsChannel() chan events.ModuleEvent

GetModuleEventsChannel returns a channel with events that occur during module processing events channel is created only if someone is reading it

func (*ModuleManager) GetModuleNames

func (mm *ModuleManager) GetModuleNames() []string

func (*ModuleManager) GlobalSynchronizationNeeded

func (mm *ModuleManager) GlobalSynchronizationNeeded() bool

GlobalSynchronizationNeeded is true if there is at least one global kubernetes hook with executeHookOnSynchronization.

func (*ModuleManager) GlobalSynchronizationState

func (mm *ModuleManager) GlobalSynchronizationState() *modules.SynchronizationState

func (*ModuleManager) HandleGlobalEnableKubernetesBindings

func (mm *ModuleManager) HandleGlobalEnableKubernetesBindings(hookName string, createTaskFn func(*hooks.GlobalHook, controller.BindingExecutionInfo)) error

func (*ModuleManager) HandleKubeEvent

func (mm *ModuleManager) HandleKubeEvent(kubeEvent KubeEvent, createGlobalTaskFn func(*hooks.GlobalHook, controller.BindingExecutionInfo), createModuleTaskFn func(*modules.BasicModule, *hooks.ModuleHook, controller.BindingExecutionInfo))

func (*ModuleManager) HandleModuleEnableKubernetesBindings

func (mm *ModuleManager) HandleModuleEnableKubernetesBindings(moduleName string, createTaskFn func(*hooks.ModuleHook, controller.BindingExecutionInfo)) error

func (*ModuleManager) HandleNewKubeConfig

func (mm *ModuleManager) HandleNewKubeConfig(kubeConfig *config.KubeConfig) (*ModulesState, error)

HandleNewKubeConfig validates new config values with config schemas, checks which parts changed and returns state with AllEnabledModules and ModulesToReload list if only module sections are changed. It returns a nil state if new KubeConfig not changing config values or 'enabled by config' state.

This method updates 'config values' caches: - mm.enabledModulesByConfig - mm.kubeGlobalConfigValues - mm.kubeModulesConfigValues

func (*ModuleManager) HandleScheduleEvent

func (mm *ModuleManager) HandleScheduleEvent(crontab string, createGlobalTaskFn func(*hooks.GlobalHook, controller.BindingExecutionInfo), createModuleTaskFn func(*modules.BasicModule, *hooks.ModuleHook, controller.BindingExecutionInfo)) error

func (*ModuleManager) Init

func (mm *ModuleManager) Init() error

Init — initialize module manager

func (*ModuleManager) IsModuleEnabled

func (mm *ModuleManager) IsModuleEnabled(moduleName string) bool

IsModuleEnabled ...

func (*ModuleManager) LoopByBinding

func (mm *ModuleManager) LoopByBinding(binding BindingType, fn func(gh *hooks.GlobalHook, m *modules.BasicModule, mh *hooks.ModuleHook))

func (*ModuleManager) PushConvergeModulesTask

func (mm *ModuleManager) PushConvergeModulesTask(moduleName, moduleState string)

PushConvergeModulesTask pushes ConvergeModulesTask into the main queue to update all modules on a module enable/disable event

func (*ModuleManager) PushDeleteModuleTask

func (mm *ModuleManager) PushDeleteModuleTask(moduleName string)

PushDeleteModule pushes moduleDelete task for a module into the main queue

func (*ModuleManager) PushRunModuleTask

func (mm *ModuleManager) PushRunModuleTask(moduleName string, doModuleStartup bool) error

PushRunModuleTask pushes moduleRun task for a module into the main queue if there is no such a task for the module

func (*ModuleManager) RefreshEnabledState

func (mm *ModuleManager) RefreshEnabledState(logLabels map[string]string) (*ModulesState, error)

RefreshEnabledState runs enabled hooks for all 'enabled by config' modules and calculates new arrays of enabled modules. It returns ModulesState with lists of modules to disable and enable.

This method is called after beforeAll hooks to take into account possible changes to 'dynamic enabled'.

This method updates caches: - mm.enabledModules

func (*ModuleManager) RefreshStateFromHelmReleases

func (mm *ModuleManager) RefreshStateFromHelmReleases(logLabels map[string]string) (*ModulesState, error)

RefreshStateFromHelmReleases retrieves all Helm releases. It marks all unknown modules as needed to be purged. Run this method once at startup.

func (*ModuleManager) RegisterModule

func (mm *ModuleManager) RegisterModule(moduleSource, modulePath string) error

RegisterModule checks if a module already exists and reapplies(reloads) its configuration. If it's a new module - converges all modules

func (*ModuleManager) RegisterModuleHooks

func (mm *ModuleManager) RegisterModuleHooks(ml *modules.BasicModule, logLabels map[string]string) error

func (*ModuleManager) RunGlobalHook

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

func (*ModuleManager) RunModule

func (mm *ModuleManager) RunModule(moduleName string, logLabels map[string]string) (bool, error)

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

func (*ModuleManager) RunModuleHook

func (mm *ModuleManager) RunModuleHook(moduleName, hookName string, binding BindingType, bindingContext []BindingContext, logLabels map[string]string) (beforeChecksum string, afterChecksum string, err error)

func (*ModuleManager) RunModuleHooks

func (mm *ModuleManager) RunModuleHooks(m *modules.BasicModule, bt sh_op_types.BindingType, logLabels map[string]string) error

RunOnStartup is a phase of module lifecycle that runs onStartup hooks. It is a handler of task MODULE_RUN 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 (*ModuleManager) RunModuleWithNewStaticValues

func (mm *ModuleManager) RunModuleWithNewStaticValues(moduleName, moduleSource, modulePath string) error

RunModuleWithNewStaticValues updates the module's values by rebasing them from static values from modulePath directory and pushes RunModuleTask if the module is enabled

func (*ModuleManager) SendModuleEvent

func (mm *ModuleManager) SendModuleEvent(ev events.ModuleEvent)

func (*ModuleManager) SetKubeConfigValid

func (mm *ModuleManager) SetKubeConfigValid(valid bool)

func (*ModuleManager) SetKubeConfigValuesValid

func (mm *ModuleManager) SetKubeConfigValuesValid(valid bool)

func (*ModuleManager) SetModuleEventsChannel

func (mm *ModuleManager) SetModuleEventsChannel(ec chan events.ModuleEvent)

SetModuleEventsChannel sets an event channel for Module Manager

func (*ModuleManager) SetModuleLoader

func (mm *ModuleManager) SetModuleLoader(ld loader.ModuleLoader)

func (*ModuleManager) SetModulePhaseAndNotify

func (mm *ModuleManager) SetModulePhaseAndNotify(module *modules.BasicModule, phase modules.ModuleRunPhase)

func (*ModuleManager) Start

func (mm *ModuleManager) Start()

Start runs service go routine.

func (*ModuleManager) Stop

func (mm *ModuleManager) Stop()

func (*ModuleManager) UpdateModuleHookStatusAndNotify

func (mm *ModuleManager) UpdateModuleHookStatusAndNotify(module *modules.BasicModule, hookName string, err error)

func (*ModuleManager) UpdateModuleKubeConfig

func (mm *ModuleManager) UpdateModuleKubeConfig(moduleName string) error

UpdateModuleKubeConfig updates a module's kube config

func (*ModuleManager) UpdateModuleLastErrorAndNotify

func (mm *ModuleManager) UpdateModuleLastErrorAndNotify(module *modules.BasicModule, err error)

type ModuleManagerConfig

type ModuleManagerConfig struct {
	DirectoryConfig DirectoryConfig
	Dependencies    ModuleManagerDependencies
}

type ModuleManagerDependencies

type ModuleManagerDependencies struct {
	KubeObjectPatcher    *object_patch.ObjectPatcher
	KubeEventsManager    kube_events_manager.KubeEventsManager
	KubeConfigManager    KubeConfigManager
	ScheduleManager      schedule_manager.ScheduleManager
	Helm                 *helm.ClientFactory
	HelmResourcesManager helm_resources_manager.HelmResourcesManager
	MetricStorage        *metric_storage.MetricStorage
	HookMetricStorage    *metric_storage.MetricStorage
	TaskQueues           *queue.TaskQueueSet
}

ModuleManagerDependencies pass dependencies for ModuleManager

type ModulesState

type ModulesState struct {
	// All enabled modules.
	AllEnabledModules []string
	// Modules that should be deleted.
	ModulesToDisable []string
	// Modules that was disabled and now are enabled.
	ModulesToEnable []string
	// Modules changed after ConfigMap changes
	ModulesToReload []string
	// Helm releases without module directory (unknown modules).
	ModulesToPurge []string
}

ModulesState determines which modules should be enabled, disabled or reloaded.

Directories

Path Synopsis
fs
models

Jump to

Keyboard shortcuts

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