hooks

package
v1.78.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 18 Imported by: 0 modules, 0 packages

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

Run metric names of module (and application) hooks and of global hooks.

Functions

func ApplyBindingActions added in v1.78.0

func ApplyBindingActions(bindings []shtypes.OnKubernetesEventConfig, ctrl *controller.HookController, actions []gohook.BindingAction, unlocked Unlocked) error

ApplyBindingActions reconfigures a hook's dynamic Kubernetes monitors in response to the BindingActions a Go hook returns. A hook may re-point a binding at a different Kind/ApiVersion ("UpdateKind") or switch it off ("Disable") at runtime: node-manager's get_crds.go, for example, declares its instance-class binding with an empty Kind and only learns the real kind (e.g. DVPInstanceClass) once it has read the cloud-provider Secret.

Without this the monitor keeps its registration-time (empty) Kind, its snapshot stays empty, and the hook fails. Mirrors addon-operator's ModuleHook.ApplyBindingActions. A recreated monitor is unlocked, so it is added to unlocked.

func BindingType added in v1.78.0

func BindingType(contexts []bctx.BindingContext) string

BindingType is the binding type a run's contexts carry, the binding label of the hook run metrics; "" without contexts.

func ExecutionSettings added in v1.78.0

func ExecutionSettings(h ControllableHook) *shtypes.Settings

ExecutionSettings are the execution rate settings of h's config (executionMinInterval and executionBurst); nil when it sets none or its config is not a module or global hook's.

func IsReadinessHook added in v1.78.0

func IsReadinessHook(name string) bool

IsReadinessHook reports whether name is the name of a readiness hook (ReadinessHookName).

func ReadinessHookName added in v1.78.0

func ReadinessHookName(hook string) string

ReadinessHookName is the name of the readiness hook the hook binary named hook declares.

func RecordPhase added in v1.78.0

func RecordPhase(storage groupedStorage, pkg string, binding shtypes.BindingType, took time.Duration)

RecordPhase records how long the onStartup, beforeHelm or afterHelm hooks of pkg took; a hook of another binding records nothing. Without a storage it records nothing.

func RecordRun added in v1.78.0

func RecordRun(ctx context.Context, storage runStorage, names RunMetrics, labels map[string]string, contexts []bctx.BindingContext, allowFailure bool, took time.Duration, err error)

RecordRun writes a run's duration and, for a Kubernetes or schedule run (the ones addon-operator counts), its outcome: success, error, or an error its binding allows. A run ended by ctx counts no outcome: the lane stopped, the hook did not fail. Without a storage it records nothing.

func RunBinding added in v1.78.0

func RunBinding(h any, contexts []bctx.BindingContext) (string, bool)

RunBinding is the queue of the binding a run's contexts name and whether that binding allows a failure; "main" and false outside a Kubernetes or schedule binding.

func SnapshotsDump added in v1.78.0

func SnapshotsDump(bindings []shtypes.OnKubernetesEventConfig, monitors monitorGetter, unlocked Unlocked) map[string]any

SnapshotsDump returns the snapshots of the bindings whose monitors are unlocked, by binding name, in the shape of shell-operator's SnapshotsDump. A locked monitor is skipped: reading its snapshot discards the events it buffers until its synchronization unlocks it (shell-operator resourceInformer.getCachedObjects). Each monitor is read once and may be gone.

Types

type ControllableHook added in v1.77.0

type ControllableHook interface {
	GetName() string
	GetHookController() *controller.HookController
}

ControllableHook is the minimal hook view the runtime needs to enable bindings and route events: the hook's name and its controller. Both module hooks (Hook) and global hooks (GlobalHook) satisfy it, so the hook lanes start and route both kinds through this instead of a concrete hook type.

func ToControllable added in v1.77.0

func ToControllable[H ControllableHook](in []H) []ControllableHook

ToControllable adapts a slice of concrete hooks to the ControllableHook view.

type GlobalHook added in v1.76.0

type GlobalHook interface {
	GetName() string
	GetConfigVersion() string
	GetHookConfig() *addonhooks.GlobalHookConfig
	Order(binding shtypes.BindingType) float64

	InitializeHookConfig() error

	GetHookController() *controller.HookController
	WithHookController(ctrl *controller.HookController)
	WithTmpDir(tmpDir string)

	SynchronizationNeeded() bool

	Execute(ctx context.Context, version string, bctx []bctx.BindingContext, packageName string, configValues, values utils.Values, logLabels map[string]string) (*kind.HookResult, error)
}

type GlobalStorage added in v1.76.0

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

GlobalStorage provides thread-safe storage for global hooks. It maintains a single index:

  • byName: Fast lookup by hook name (O(1))
  • byBinding: Fast lookup by binding type (O(1))

Thread Safety: All methods use RWMutex for concurrent access.

func NewGlobalStorage added in v1.76.0

func NewGlobalStorage() *GlobalStorage

NewGlobalStorage creates a new empty global hook storage.

func (*GlobalStorage) Add added in v1.76.0

func (s *GlobalStorage) Add(hook GlobalHook)

Add adds a global hook to storage, indexing it by name. If a hook with the same name exists, it will be replaced.

func (*GlobalStorage) GetHookByName added in v1.76.0

func (s *GlobalStorage) GetHookByName(name string) GlobalHook

GetHookByName returns the hook with the specified name, or nil if not found.

func (*GlobalStorage) GetHooks added in v1.76.0

func (s *GlobalStorage) GetHooks() []GlobalHook

GetHooks returns all hooks in storage in arbitrary order. The returned slice is safe to use - it's a copy of internal data.

func (*GlobalStorage) GetHooksByBinding added in v1.76.0

func (s *GlobalStorage) GetHooksByBinding(binding shtypes.BindingType) []GlobalHook

GetHooksByBinding returns copied slices of all hooks for a specific binding type, sorted by order.

type Hook added in v1.76.0

type Hook interface {
	GetName() string
	GetConfigVersion() string
	GetHookConfig() *addonhooks.ModuleHookConfig
	Order(binding shtypes.BindingType) float64

	InitializeHookConfig() error

	GetHookController() *controller.HookController
	WithHookController(ctrl *controller.HookController)
	WithTmpDir(tmpDir string)

	SynchronizationNeeded() bool

	Execute(ctx context.Context, version string, bctx []bctx.BindingContext, packageName string, configValues, values utils.Values, logLabels map[string]string) (*kind.HookResult, error)
}

Hook represents a module-scoped hook that executes during a module's lifecycle. Module hooks use ModuleHookConfig and are organized by binding type for ordered execution.

type ProbeFailedError added in v1.78.0

type ProbeFailedError struct {
	Message string
}

ProbeFailedError is a readiness probe that found the package not ready. A readiness hook of an SDK that reports through the Module's IsReady condition gets it as the error of its run, so the hook lanes read every probe verdict from the run's outcome.

func (*ProbeFailedError) Error added in v1.78.0

func (e *ProbeFailedError) Error() string

type RunMetrics added in v1.78.0

type RunMetrics struct {
	Seconds       string
	Success       string
	Errors        string
	AllowedErrors string
}

RunMetrics are the names one kind of hook writes its runs under.

type Storage

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

Storage provides thread-safe storage for hooks with multiple access patterns. It maintains two indices:

  • byName: Fast lookup by hook name (O(1))
  • byBinding: Fast lookup by binding type (O(1))

Thread Safety: All methods use RWMutex for concurrent access.

func NewStorage

func NewStorage() *Storage

NewStorage creates a new empty hook storage.

func (*Storage) Add

func (s *Storage) Add(hook Hook)

Add adds a hook to storage, indexing it by name and all its bindings. If a hook with the same name exists, it will be replaced. Each binding type the hook declares will have the hook added to its list.

func (*Storage) GetHookByName

func (s *Storage) GetHookByName(name string) Hook

GetHookByName returns the hook with the specified name, or nil if not found.

func (*Storage) GetHooks

func (s *Storage) GetHooks() []Hook

GetHooks returns all hooks in storage in arbitrary order. The returned slice is safe to use - it's a copy of internal data.

func (*Storage) GetHooksByBinding

func (s *Storage) GetHooksByBinding(binding shtypes.BindingType) []Hook

GetHooksByBinding returns copied slices of all hooks for a specific binding type, sorted by order.

type Unlocked added in v1.78.0

type Unlocked map[string]struct{}

Unlocked is the set of a package's Kubernetes monitor ids whose events are unlocked: their synchronization finished, or UpdateMonitor recreated them unlocked. The owner guards it with the lock it holds around its hook controllers.

Jump to

Keyboard shortcuts

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