manager

package
v1.74.2 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	OnValuesChanged func(ctx context.Context, name string)

	NelmService       *nelm.Service
	KubeObjectPatcher *objectpatch.ObjectPatcher
	ScheduleManager   schedulemanager.ScheduleManager
	KubeEventsManager kubeeventsmanager.KubeEventsManager
}

type Manager

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

Manager manages the lifecycle of application packages.

func New

func New(conf Config, logger *log.Logger) *Manager

New creates a new package manager with the specified apps directory.

func (*Manager) ApplySettings

func (m *Manager) ApplySettings(name string, settings addonutils.Values) error

ApplySettings validates and apply setting to application

func (*Manager) BuildKubeTasks

func (m *Manager) BuildKubeTasks(ctx context.Context, kubeEvent shkubetypes.KubeEvent, builder TaskBuilder) map[string][]queue.Task

BuildKubeTasks converts a Kubernetes event into executable tasks for all matching hooks.

For each application:

  1. Find hooks that are bound to Kubernetes events
  2. Check if the hook can handle this specific event (filtering)
  3. Generate tasks for matching hooks using the provided builder

Returns a map of queue names to tasks, allowing different hooks to be routed to different queues (e.g., priority queues, sequential queues).

func (*Manager) BuildScheduleTasks

func (m *Manager) BuildScheduleTasks(ctx context.Context, crontab string, builder TaskBuilder) map[string][]queue.Task

BuildScheduleTasks converts a schedule (cron) event into executable tasks for all matching hooks.

For each application:

  1. Find hooks that are bound to schedule events
  2. Check if the hook's schedule matches the triggered crontab
  3. Generate tasks for matching hooks using the provided builder

Returns a map of queue names to tasks, allowing hooks to specify their execution queue.

func (*Manager) DisablePackage

func (m *Manager) DisablePackage(ctx context.Context, name string, keep bool) error

DisablePackage stops monitoring, uninstalls helm release and disables all hooks for a package.

Process:

  1. Stop Helm resource monitoring
  2. Uninstall Helm release
  3. Run AfterDeleteHelm hooks
  4. Disable all schedule hooks
  5. Stop all Kubernetes event monitors
  6. Remove package from manager store

func (*Manager) GetAppInfo

func (m *Manager) GetAppInfo(name string) apps.Info

func (*Manager) GetApplication

func (m *Manager) GetApplication(name string) *apps.Application

func (*Manager) GetPackageQueues

func (m *Manager) GetPackageQueues(name string) []string

GetPackageQueues collects all queues from package hooks

func (*Manager) InitializeHooks

func (m *Manager) InitializeHooks(ctx context.Context, name string) (map[string][]hookcontroller.BindingExecutionInfo, error)

InitializeHooks initializes hook controllers and returns info for sync tasks.

This must be called after LoadApplication and before StartupPackage. It performs:

  1. Creates hook controllers for each hook
  2. Initializes Kubernetes event bindings
  3. Initializes schedule bindings
  4. Enables kube hooks(starting monitoring for the resources configured in each hook's bindings)
  5. Enable schedule hooks(activating the cron schedules configured in each hook's bindings)

func (*Manager) KubeObjectPatcher

func (m *Manager) KubeObjectPatcher() *objectpatch.ObjectPatcher

KubeObjectPatcher returns the Kubernetes object patcher for applying patches from hooks.

This implements the DependencyContainer interface required by hook execution. Hooks can request object patching operations (create/update/delete K8s resources) during their execution, which are applied through this patcher.

func (*Manager) LoadPackage

func (m *Manager) LoadPackage(ctx context.Context, registry registry.Registry, namespace, name string) error

LoadPackage loads a package from filesystem and stores it in the manager. It discovers hooks, parses OpenAPI schemas, and initializes values storage.

func (*Manager) RunPackage

func (m *Manager) RunPackage(ctx context.Context, name string) error

RunPackage executes the full package run cycle: BeforeHelm → Install/Upgrade → AfterHelm.

Process:

  1. Pause Helm resource monitoring
  2. Run BeforeHelm hooks (can modify values or prepare resources)
  3. Install or upgrade Helm release
  4. Run AfterHelm hooks
  5. If values changed during AfterHelm, trigger Helm upgrade
  6. Resume Helm resource monitoring

func (*Manager) RunPackageHook

func (m *Manager) RunPackageHook(ctx context.Context, name, hook string, bctx []bindingcontext.BindingContext) error

RunPackageHook executes a specific hook by name with the provided binding context.

This is called when:

  • Kubernetes events trigger a hook (resource created/updated/deleted)
  • Schedule triggers fire (cron-like schedules)

Returns:

  • bool: true if hook modified values (may require Helm upgrade)
  • error: if hook execution fails

func (*Manager) SettingsChanged

func (m *Manager) SettingsChanged(name string, settings addonutils.Values) bool

func (*Manager) StartupPackage

func (m *Manager) StartupPackage(ctx context.Context, name string) error

StartupPackage runs OnStartup hooks for a package. This must be called after InitializeHooks and before RunPackage.

func (*Manager) UnlockKubernetesMonitors

func (m *Manager) UnlockKubernetesMonitors(name, hook string, monitors ...string)

UnlockKubernetesMonitors called after sync task is completed to unlock getting events

func (*Manager) VersionChanged

func (m *Manager) VersionChanged(name, version string) bool

type TaskBuilder

type TaskBuilder func(ctx context.Context, name, hook string, info hookcontroller.BindingExecutionInfo) (string, queue.Task)

TaskBuilder is a function that converts a hook binding execution into a queue task. It returns:

  • string: the queue name to enqueue the task into (allows routing to different queues)
  • queue.Task: the task to be executed

The builder is provided by the caller (typically the event handler) to customize task creation based on the specific execution context and requirements.

Directories

Path Synopsis
Package apps provides the Application type representing a running package instance.
Package apps provides the Application type representing a running package instance.
monitor
Package monitor provides resource monitoring for Helm releases deployed via nelm.
Package monitor provides resource monitoring for Helm releases deployed via nelm.

Jump to

Keyboard shortcuts

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