modules

package
v1.10.3 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2025 License: Apache-2.0 Imports: 42 Imported by: 11

Documentation

Index

Constants

View Source
const (
	LabelMaintenanceNoResourceReconciliation = "maintenance.deckhouse.io/no-resource-reconciliation"
)

Variables

View Source
var (
	ErrFileHasWrongExtension       = errors.New("file has wrong extension")
	ErrFileIsNotBatchHook          = errors.New("file is not batch hook")
	ErrFileNoExecutablePermissions = errors.New("no executable permissions, chmod +x is required to run this hook")
)
View Source
var ErrModuleIsNotHelm = errors.New("module is not a helm")
View Source
var ErrReleaseIsUnmanaged = errors.New("release is unmanaged")

Functions

func IsFileBatchHook added in v1.6.0

func IsFileBatchHook(moduleName, path string, f os.FileInfo) error

func RecursiveGetBatchHookExecutablePaths added in v1.6.0

func RecursiveGetBatchHookExecutablePaths(moduleName, dir string, logger *log.Logger, excludedDirs ...string) ([]string, error)

Types

type BasicModule

type BasicModule struct {
	// required
	Name string
	// required
	Order uint32
	// required
	Path string
	// contains filtered or unexported fields
}

BasicModule is a basic representation of the Module, which addon-operator works with any Module has the next parameters:

  • name of the module
  • order of the module execution
  • path of the module on a filesystem
  • values storage - config and calculated values for the module
  • hooks of the module
  • current module state

func NewBasicModule

func NewBasicModule(name, path string, order uint32, staticValues utils.Values, configBytes, valuesBytes []byte, opts ...ModuleOption) (*BasicModule, error)

TODO: add options WithLogger NewBasicModule creates new BasicModule staticValues - are values from modules/values.yaml and /modules/<module-name>/values.yaml, they could not be changed during the runtime

func (*BasicModule) ApplyNewSchemaStorage added in v1.4.0

func (bm *BasicModule) ApplyNewSchemaStorage(schema *validation.SchemaStorage) error

ApplyNewSchemaStorage updates schema storage of the basic module

func (*BasicModule) AssembleEnvironmentForModule added in v1.6.0

func (bm *BasicModule) AssembleEnvironmentForModule(targetEnvironment environmentmanager.Environment) error

func (*BasicModule) CRDExist added in v1.5.0

func (bm *BasicModule) CRDExist() bool

func (*BasicModule) DeregisterHooks

func (bm *BasicModule) DeregisterHooks()

DeregisterHooks clean up all module hooks

func (*BasicModule) DisassembleEnvironmentForModule added in v1.6.0

func (bm *BasicModule) DisassembleEnvironmentForModule() error

func (*BasicModule) GenerateNewConfigValues

func (bm *BasicModule) GenerateNewConfigValues(kubeConfigValues utils.Values, validate bool) (utils.Values, error)

func (*BasicModule) GetCRDFilesPaths added in v1.5.0

func (bm *BasicModule) GetCRDFilesPaths() []string

func (*BasicModule) GetConfigValues

func (bm *BasicModule) GetConfigValues(withPrefix bool) utils.Values

func (*BasicModule) GetCritical added in v1.10.0

func (bm *BasicModule) GetCritical() bool

func (*BasicModule) GetEnabledScriptResult added in v1.3.10

func (bm *BasicModule) GetEnabledScriptResult() *bool

GetEnabledScriptResult returns a bool pointer to the enabled script results

func (*BasicModule) GetHookByName

func (bm *BasicModule) GetHookByName(name string) *hooks.ModuleHook

GetHookByName returns hook by its name

func (*BasicModule) GetHookErrorsSummary added in v1.3.10

func (bm *BasicModule) GetHookErrorsSummary() string

GetHookErrorsSummary get hooks errors summary report

func (*BasicModule) GetHooks

func (bm *BasicModule) GetHooks(bt ...sh_op_types.BindingType) []*hooks.ModuleHook

GetHooks returns module hooks, they could be filtered by BindingType optionally

func (*BasicModule) GetLastHookError

func (bm *BasicModule) GetLastHookError() error

GetLastHookError get error of the last executed hook

func (*BasicModule) GetMaintenanceState added in v1.6.2

func (bm *BasicModule) GetMaintenanceState() MaintenanceState

func (*BasicModule) GetModuleError

func (bm *BasicModule) GetModuleError() error

func (*BasicModule) GetName

func (bm *BasicModule) GetName() string

GetName returns the module name

func (*BasicModule) GetOrder

func (bm *BasicModule) GetOrder() uint32

GetOrder returns the module order

func (*BasicModule) GetPath

func (bm *BasicModule) GetPath() string

GetPath returns the module path on a filesystem

func (*BasicModule) GetPhase

func (bm *BasicModule) GetPhase() ModuleRunPhase

GetPhase ...

func (*BasicModule) GetSchemaStorage added in v1.3.13

func (bm *BasicModule) GetSchemaStorage() *validation.SchemaStorage

GetSchemaStorage returns current schema storage of the basic module

func (*BasicModule) GetValues

func (bm *BasicModule) GetValues(withPrefix bool) utils.Values

func (*BasicModule) GetValuesPatches

func (bm *BasicModule) GetValuesPatches() []utils.ValuesPatch

GetValuesPatches returns patches for debug output

func (*BasicModule) GetValuesStorage added in v1.3.13

func (bm *BasicModule) GetValuesStorage() *ValuesStorage

func (*BasicModule) HasKubernetesHooks

func (bm *BasicModule) HasKubernetesHooks() bool

HasKubernetesHooks is true if module has at least one kubernetes hook.

func (*BasicModule) HasReadiness added in v1.7.7

func (bm *BasicModule) HasReadiness() bool

HasReadiness returns whether the module has a readiness probe configured.

func (*BasicModule) HooksControllersReady added in v1.3.9

func (bm *BasicModule) HooksControllersReady() bool

HooksControllersReady returns controllersReady status of the hook storage

func (*BasicModule) RegisterHooks

func (bm *BasicModule) RegisterHooks(logger *log.Logger) ([]*hooks.ModuleHook, error)

RegisterHooks searches and registers all module hooks from a filesystem or GoHook Registry

func (*BasicModule) ResetState

func (bm *BasicModule) ResetState()

ResetState drops the module state

func (*BasicModule) RunEnabledScript

func (bm *BasicModule) RunEnabledScript(ctx context.Context, tmpDir string, precedingEnabledModules []string, logLabels map[string]string) (bool, error)

RunEnabledScript execute enabled script

func (*BasicModule) RunHookByName

func (bm *BasicModule) RunHookByName(ctx context.Context, hookName string, binding sh_op_types.BindingType, bindingContext []bindingcontext.BindingContext, logLabels map[string]string) (string, string, error)

RunHookByName runs some specified hook by its name

func (*BasicModule) RunHooksByBinding

func (bm *BasicModule) RunHooksByBinding(ctx context.Context, binding sh_op_types.BindingType, logLabels map[string]string) error

RunHooksByBinding gets all hooks for binding, for each hook it creates a BindingContext, sets KubernetesSnapshots and runs the hook.

func (*BasicModule) SaveConfigValues

func (bm *BasicModule) SaveConfigValues(configV utils.Values)

func (*BasicModule) SaveHookError

func (bm *BasicModule) SaveHookError(hookName string, err error)

SaveHookError ...

func (*BasicModule) SetCritical added in v1.10.0

func (bm *BasicModule) SetCritical(value bool)

func (*BasicModule) SetError

func (bm *BasicModule) SetError(err error)

SetError ...

func (*BasicModule) SetHooksControllersReady added in v1.3.9

func (bm *BasicModule) SetHooksControllersReady()

SetHooksControllersReady sets controllersReady status of the hook storage to true

func (*BasicModule) SetMaintenanceState added in v1.6.2

func (bm *BasicModule) SetMaintenanceState(state utils.Maintenance)

func (*BasicModule) SetPhase

func (bm *BasicModule) SetPhase(phase ModuleRunPhase)

SetPhase ...

func (*BasicModule) SetStateEnabled

func (bm *BasicModule) SetStateEnabled(e bool)

SetStateEnabled ...

func (*BasicModule) SetUnmanaged added in v1.6.5

func (bm *BasicModule) SetUnmanaged()

func (*BasicModule) Synchronization

func (bm *BasicModule) Synchronization() *SynchronizationState

Synchronization xxx TODO: don't like this honestly, i think we can remake it

func (*BasicModule) SynchronizationNeeded

func (bm *BasicModule) SynchronizationNeeded() bool

SynchronizationNeeded is true if module has at least one kubernetes hook with executeHookOnSynchronization. TODO: dont skip

func (*BasicModule) Validate added in v1.3.13

func (bm *BasicModule) Validate() error

func (*BasicModule) ValidateConfigValues added in v1.3.13

func (bm *BasicModule) ValidateConfigValues() error

func (*BasicModule) ValidateValues added in v1.3.13

func (bm *BasicModule) ValidateValues() error

func (*BasicModule) WithDependencies

func (bm *BasicModule) WithDependencies(dep *hooks.HookExecutionDependencyContainer)

WithDependencies inject module dependencies

func (*BasicModule) WithLogger added in v1.6.0

func (bm *BasicModule) WithLogger(logger *log.Logger)

type EnabledPatchReport

type EnabledPatchReport struct {
	Patch utils.ValuesPatch
	Done  chan error
}

type GlobalModule

type GlobalModule struct {
	// contains filtered or unexported fields
}

GlobalModule is an ephemeral container for global hooks

func NewGlobalModule

func NewGlobalModule(hooksDir string, staticValues utils.Values, dc *hooks.HookExecutionDependencyContainer,
	configBytes, valuesBytes []byte, keepTemporaryHookFiles bool, opts ...ModuleOption,
) (*GlobalModule, error)

NewGlobalModule build ephemeral global container for global hooks and values

func (*GlobalModule) EnabledReportChannel

func (gm *GlobalModule) EnabledReportChannel() chan *EnabledPatchReport

EnabledReportChannel returns channel with dynamic modules enabling by global hooks

func (*GlobalModule) GenerateNewConfigValues

func (gm *GlobalModule) GenerateNewConfigValues(kubeConfigValues utils.Values, validate bool) (utils.Values, error)

func (*GlobalModule) GetConfigValues

func (gm *GlobalModule) GetConfigValues(withPrefix bool) utils.Values

func (*GlobalModule) GetHookByName

func (gm *GlobalModule) GetHookByName(name string) *hooks.GlobalHook

GetHookByName ...

func (*GlobalModule) GetHooks

func (gm *GlobalModule) GetHooks(bt ...sh_op_types.BindingType) []*hooks.GlobalHook

GetHooks returns module hooks, they could be filtered by BindingType optionally

func (*GlobalModule) GetName

func (gm *GlobalModule) GetName() string

GetName ...

func (*GlobalModule) GetSchemaStorage added in v1.3.13

func (gm *GlobalModule) GetSchemaStorage() *validation.SchemaStorage

func (*GlobalModule) GetValues

func (gm *GlobalModule) GetValues(withPrefix bool) utils.Values

func (*GlobalModule) GetValuesPatches

func (gm *GlobalModule) GetValuesPatches() []utils.ValuesPatch

func (*GlobalModule) RegisterHooks

func (gm *GlobalModule) RegisterHooks() ([]*hooks.GlobalHook, error)

RegisterHooks finds and registers global hooks

func (*GlobalModule) RunHookByName

func (gm *GlobalModule) RunHookByName(ctx context.Context, hookName string, binding sh_op_types.BindingType, bindingContext []bindingcontext.BindingContext, logLabels map[string]string) (string, string, error)

RunHookByName runs some specified hook by its name

func (*GlobalModule) SaveConfigValues

func (gm *GlobalModule) SaveConfigValues(configV utils.Values)

func (*GlobalModule) SetAvailableAPIVersions added in v1.5.0

func (gm *GlobalModule) SetAvailableAPIVersions(apiVersions []string)

SetAvailableAPIVersions injects GVK values, discovered during executing ModuleEnsureCRDs tasks, into .global.discovery.apiVersions values

func (*GlobalModule) SetEnabledModules added in v1.3.5

func (gm *GlobalModule) SetEnabledModules(enabledModules []string)

SetEnabledModules inject enabledModules to the global values enabledModules are injected as a patch, to recalculate on every global values change

func (*GlobalModule) WithLogger added in v1.6.0

func (gm *GlobalModule) WithLogger(logger *log.Logger)

type HelmModule

type HelmModule struct {
	// contains filtered or unexported fields
}

HelmModule representation of the module, which has Helm Chart and could be installed with the helm lib

func NewHelmModule

func NewHelmModule(bm *BasicModule, namespace string, tmpDir string, deps *HelmModuleDependencies, validator HelmValuesValidator, opts ...ModuleOption) (*HelmModule, error)

NewHelmModule build HelmModule from the Module templates and values + global values

func (*HelmModule) PrepareValuesYamlFile

func (hm *HelmModule) PrepareValuesYamlFile() (string, error)

func (*HelmModule) Render

func (hm *HelmModule) Render(namespace string, debug bool) (string, error)

func (*HelmModule) RunHelmInstall

func (hm *HelmModule) RunHelmInstall(ctx context.Context, logLabels map[string]string, state MaintenanceState) error

RunHelmInstall installs or upgrades a Helm release for the module. The `state` parameter determines the maintenance state of the release: - If `state` is `Unmanaged`, a release label check is triggered, and the Helm upgrade is skipped.

func (*HelmModule) WithLogger added in v1.6.0

func (hm *HelmModule) WithLogger(logger *log.Logger)

type HelmModuleDependencies

type HelmModuleDependencies struct {
	HelmClientFactory   *helm.ClientFactory
	HelmResourceManager HelmResourceManager
	MetricsStorage      MetricsStorage
	HelmValuesValidator HelmValuesValidator
}

type HelmResourceManager

type HelmResourceManager interface {
	GetAbsentResources(manifests []manifest.Manifest, defaultNamespace string) ([]manifest.Manifest, error)
	StartMonitor(moduleName string, manifests []manifest.Manifest, defaultNamespace string, LastReleaseStatus func(releaseName string) (revision string, status string, err error))
	HasMonitor(moduleName string) bool
}

type HelmValuesValidator

type HelmValuesValidator interface {
	ValidateModuleHelmValues(string, utils.Values) error
}

type HooksStorage

type HooksStorage struct {
	// contains filtered or unexported fields
}

HooksStorage keep module hooks in order

func (*HooksStorage) AddHook

func (hs *HooksStorage) AddHook(hk *hooks.ModuleHook)

type MaintenanceState added in v1.6.2

type MaintenanceState int
const (
	// Module runs in a normal mode
	Managed MaintenanceState = iota
	// All consequent helm runs are inhibited (heritage labels are removed and resource informer is stopped)
	Unmanaged = 1
)

type MetricsStorage

type MetricsStorage interface {
	HistogramObserve(metric string, value float64, labels map[string]string, buckets []float64)
}

type ModuleOption added in v1.6.0

type ModuleOption interface {
	Apply(optsApplier ModuleOptionApplier)
}

type ModuleOptionApplier added in v1.6.0

type ModuleOptionApplier interface {
	WithLogger(logger *log.Logger)
}

type ModuleRunPhase

type ModuleRunPhase string
const (
	// Startup - module is just enabled.
	Startup ModuleRunPhase = "Startup"
	// OnStartupDone - onStartup hooks have completed execution.
	OnStartupDone ModuleRunPhase = "OnStartupDone"
	// QueueSynchronizationTasks - synchronization tasks should be queued.
	QueueSynchronizationTasks ModuleRunPhase = "QueueSynchronizationTasks"
	// WaitForSynchronization - synchronization tasks are in queues, waiting for them to complete.
	WaitForSynchronization ModuleRunPhase = "WaitForSynchronization"
	// EnableScheduleBindings - enable schedule bindings after synchronization is complete.
	EnableScheduleBindings ModuleRunPhase = "EnableScheduleBindings"
	// CanRunHelm - module is ready to run its Helm chart.
	CanRunHelm ModuleRunPhase = "CanRunHelm"
	// HooksDisabled - module has its hooks disabled (before update or deletion).
	HooksDisabled ModuleRunPhase = "HooksDisabled"

	// WaitForReadiness - module is waiting for readiness hooks to complete.
	// This phase is used to ensure that the module is fully operational before proceeding with further actions.
	// It is typically used after the Helm chart has been applied and before the module is considered fully ready.
	WaitForReadiness ModuleRunPhase = "WaitForReadiness"

	// Ready - all phases are complete.
	// This is the final phase, which indicates that the ModuleRun task completed without errors.
	// Note: This only confirms the module's own execution succeeded, not the status of any resources it created.
	// Custom readiness checks can be implemented separately if needed.
	Ready ModuleRunPhase = "Ready"
)

type Option added in v1.6.0

type Option func(optionsApplier ModuleOptionApplier)

func WithLogger added in v1.6.0

func WithLogger(logger *log.Logger) Option

func (Option) Apply added in v1.6.0

func (opt Option) Apply(o ModuleOptionApplier)

type SynchronizationState

type SynchronizationState struct {
	// contains filtered or unexported fields
}

SynchronizationState stores state to track synchronization tasks for kubernetes bindings either for all global hooks or for module's hooks.

func NewSynchronizationState

func NewSynchronizationState() *SynchronizationState

func (*SynchronizationState) DebugDumpState

func (s *SynchronizationState) DebugDumpState(logEntry *log.Logger)

func (*SynchronizationState) DoneForBinding

func (s *SynchronizationState) DoneForBinding(id string)

func (*SynchronizationState) HasQueued

func (s *SynchronizationState) HasQueued() bool

func (*SynchronizationState) IsCompleted added in v1.5.0

func (s *SynchronizationState) IsCompleted() bool

IsCompleted returns true if all states are in done status.

func (*SynchronizationState) QueuedForBinding

func (s *SynchronizationState) QueuedForBinding(metadata TaskMetadata)

QueuedForBinding marks a Kubernetes binding as queued for synchronization

type TaskMetadata added in v1.6.0

type TaskMetadata interface {
	GetKubernetesBindingID() string
	GetHookName() string
	GetBinding() string
}

type ValuesStorage

type ValuesStorage struct {
	// contains filtered or unexported fields
}

ValuesStorage keeps Module's values in order

func NewValuesStorage

func NewValuesStorage(moduleName string, staticValues utils.Values, configBytes, valuesBytes []byte) (*ValuesStorage, error)

NewValuesStorage build a new storage for module values

staticValues - values from /modules/<module-name>/values.yaml, which couldn't be reloaded during the runtime

func (*ValuesStorage) CommitValues

func (vs *ValuesStorage) CommitValues() error

CommitValues apply all patches and create up-to-date values for module

func (*ValuesStorage) GenerateNewConfigValues

func (vs *ValuesStorage) GenerateNewConfigValues(configV utils.Values, validate bool) (utils.Values, error)

GenerateNewConfigValues generated new config values, based on static and config values. Additionally, if validate is true, it validates the resulting values set for consistency. This method always makes a copy of the result values to prevent pointers shallow copying

func (*ValuesStorage) GetConfigValues

func (vs *ValuesStorage) GetConfigValues(withPrefix bool) utils.Values

GetConfigValues returns only user defined values

func (*ValuesStorage) GetSchemaStorage added in v1.3.13

func (vs *ValuesStorage) GetSchemaStorage() *validation.SchemaStorage

func (*ValuesStorage) GetValues

func (vs *ValuesStorage) GetValues(withPrefix bool) utils.Values

GetValues return current values with applied patches withPrefix means, that values will be returned with module name prefix example:

without prefix:

```yaml
replicas: 1
foo:
  bar: hello-world
```

with prefix:

```yaml
mySuperModule:
	replicas: 1
	foo:
	  bar: hello-world
```

func (*ValuesStorage) SaveConfigValues

func (vs *ValuesStorage) SaveConfigValues(configV utils.Values)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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