hook

package
v1.17.5 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: Apache-2.0 Imports: 36 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateRateLimiter

func CreateRateLimiter(cfg *config.HookConfig) *rate.Limiter

func ValidateMetricOperation added in v1.11.0

func ValidateMetricOperation(op MetricOperation) error

func ValidateOperations added in v1.11.0

func ValidateOperations(ops []MetricOperation) error

Types

type FileSystemHookDiscovery added in v1.16.2

type FileSystemHookDiscovery struct{}

FileSystemHookDiscovery discovers hooks by recursively scanning workingDir for executable files.

func (FileSystemHookDiscovery) Discover added in v1.16.2

func (FileSystemHookDiscovery) Discover(workingDir string) ([]string, error)

type Hook

type Hook struct {
	Name   string // The unique name like '002-prometheus-hooks/startup_hook'.
	Path   string // The absolute path to the executable file.
	Config *config.HookConfig

	HookController *controller.HookController
	RateLimiter    *rate.Limiter

	TmpDir                 string
	KeepTemporaryHookFiles bool

	LogProxyHookJSON    bool
	LogProxyHookJSONKey string

	Logger *log.Logger
	// contains filtered or unexported fields
}

func NewHook

func NewHook(name, path string, keepTemporaryHookFiles bool, logProxyHookJSON bool, logProxyHookJSONKey string, logger *log.Logger) *Hook

func (*Hook) GetConfig

func (h *Hook) GetConfig() *config.HookConfig

func (*Hook) GetConfigDescription

func (h *Hook) GetConfigDescription() string

func (*Hook) LoadConfig

func (h *Hook) LoadConfig(configOutput []byte) (*Hook, error)

func (*Hook) RateLimitWait

func (h *Hook) RateLimitWait(ctx context.Context) error

func (*Hook) Run

func (h *Hook) Run(ctx context.Context, _ htypes.BindingType, context []bctx.BindingContext, logLabels map[string]string) (*Result, error)

func (*Hook) SafeName

func (h *Hook) SafeName() string

func (*Hook) WithHookController

func (h *Hook) WithHookController(hookController *controller.HookController)

func (*Hook) WithTmpDir

func (h *Hook) WithTmpDir(dir string)

type HookDiscovery added in v1.16.2

type HookDiscovery interface {
	// Discover returns a sorted list of absolute paths to hook executables.
	Discover(workingDir string) ([]string, error)
}

HookDiscovery discovers hook executables to be loaded by the Manager. The default implementation scans the filesystem; tests and alternative runtimes can supply their own.

type HookEnv added in v1.16.1

type HookEnv struct {
	ContextPath         string
	MetricsPath         string
	AdmissionPath       string
	ConversionPath      string
	KubernetesPatchPath string
}

HookEnv holds the temporary file paths created for a single hook execution. The file paths are passed to the hook subprocess via environment variables.

func (*HookEnv) Envs added in v1.16.1

func (e *HookEnv) Envs() []string

Envs returns the environment variable pairs that expose the file paths to the hook subprocess. Returns nil when ContextPath is empty.

type HookManager

type HookManager interface {
	Init() error
	GetHook(name string) *Hook
	GetHookNames() []string
	GetHooksInOrder(bindingType htypes.BindingType) ([]string, error)
	CreateTasksFromKubeEvent(kubeEvent kemtypes.KubeEvent, createTaskFn func(*Hook, controller.BindingExecutionInfo) task.Task) []task.Task
	HandleCreateTasksFromScheduleEvent(crontab string, createTaskFn func(*Hook, controller.BindingExecutionInfo) task.Task) []task.Task
	HandleAdmissionEvent(ctx context.Context, event admission.Event, createTaskFn func(*Hook, controller.BindingExecutionInfo))
	DetectAdmissionEventType(event admission.Event) htypes.BindingType
	HandleConversionEvent(ctx context.Context, crdName string, request *v1.ConversionRequest, rule conversion.Rule, createTaskFn func(*Hook, controller.BindingExecutionInfo))
	FindConversionChain(crdName string, rule conversion.Rule) []conversion.Rule
}

HookManager is the interface for the hook manager used by the operator. It allows substituting test doubles in unit tests.

type IOProvider added in v1.16.1

type IOProvider interface {
	Prepare(versionedCtx bctx.BindingContextList) (*HookEnv, error)
	Cleanup(env *HookEnv)
}

IOProvider prepares temporary files before hook execution and cleans them up after. The default implementation (hookIOProvider) writes to the OS temp directory. Tests may supply a different implementation backed by t.TempDir() or in-memory buffers.

type Manager added in v1.4.12

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

func NewHookManager

func NewHookManager(config *ManagerConfig) *Manager

func (*Manager) CreateTasksFromKubeEvent added in v1.7.0

func (hm *Manager) CreateTasksFromKubeEvent(kubeEvent kemtypes.KubeEvent, createTaskFn func(*Hook, controller.BindingExecutionInfo) task.Task) []task.Task

func (*Manager) DetectAdmissionEventType added in v1.4.12

func (hm *Manager) DetectAdmissionEventType(event admission.Event) htypes.BindingType

func (*Manager) FindConversionChain added in v1.4.12

func (hm *Manager) FindConversionChain(crdName string, rule conversion.Rule) []conversion.Rule

func (*Manager) GetHook added in v1.4.12

func (hm *Manager) GetHook(name string) *Hook

func (*Manager) GetHookNames added in v1.4.12

func (hm *Manager) GetHookNames() []string

GetHookNames returns a snapshot copy of registered hook names. A copy is returned so callers can iterate without holding the lock and without observing concurrent mutations from Init().

func (*Manager) GetHooksInOrder added in v1.4.12

func (hm *Manager) GetHooksInOrder(bindingType htypes.BindingType) ([]string, error)

func (*Manager) HandleAdmissionEvent added in v1.4.12

func (hm *Manager) HandleAdmissionEvent(ctx context.Context, event admission.Event, createTaskFn func(*Hook, controller.BindingExecutionInfo))

func (*Manager) HandleConversionEvent added in v1.4.12

func (hm *Manager) HandleConversionEvent(ctx context.Context, crdName string, request *v1.ConversionRequest, rule conversion.Rule, createTaskFn func(*Hook, controller.BindingExecutionInfo))

HandleConversionEvent receives a crdName and calculates a sequence of hooks to run.

func (*Manager) HandleCreateTasksFromScheduleEvent added in v1.7.0

func (hm *Manager) HandleCreateTasksFromScheduleEvent(crontab string, createTaskFn func(*Hook, controller.BindingExecutionInfo) task.Task) []task.Task

func (*Manager) Init added in v1.4.12

func (hm *Manager) Init() error

Init finds executables in WorkingDir, execute them with --config argument and add them into indices.

Indices are built into local maps first and only swapped into the Manager under indexMu, so concurrent readers (queue workers, event handlers) never observe a half-built state.

func (*Manager) TempDir added in v1.4.12

func (hm *Manager) TempDir() string

func (*Manager) UpdateConversionChains added in v1.4.12

func (hm *Manager) UpdateConversionChains() error

func (*Manager) WorkingDir added in v1.4.12

func (hm *Manager) WorkingDir() string

type ManagerConfig added in v1.4.12

type ManagerConfig struct {
	WorkingDir               string
	TempDir                  string
	KubeEventsManager        kubeeventsmanager.KubeEventsManager
	ScheduleManager          schedulemanager.ScheduleManager
	AdmissionWebhookManager  *admission.WebhookManager
	ConversionWebhookManager *conversion.WebhookManager

	// HookDiscovery overrides the default filesystem-based hook discovery.
	// When nil, FileSystemHookDiscovery is used.
	HookDiscovery HookDiscovery

	KeepTemporaryHookFiles bool
	LogProxyHookJSON       bool
	LogProxyHookJSONKey    string

	Logger *log.Logger
}

ManagerConfig sets configuration for Manager

type MetricOperation added in v1.11.0

type MetricOperation struct {
	Name string `json:"name"`
	// Deprecated: use Value + Action="add" instead. Add only works for parsing from file
	Add *float64 `json:"add,omitempty"` // shortcut for action=add value=num
	// Deprecated: use Value + Action="set" instead. Set only works for parsing from file
	Set     *float64          `json:"set,omitempty"` // shortcut for action=set value=num
	Value   *float64          `json:"value,omitempty"`
	Buckets []float64         `json:"buckets,omitempty"`
	Labels  map[string]string `json:"labels"`
	Group   string            `json:"group,omitempty"`
	Action  string            `json:"action,omitempty"`
}

func MetricOperationsFromBytes added in v1.11.0

func MetricOperationsFromBytes(data []byte, defaultGroup string) ([]MetricOperation, error)

func MetricOperationsFromFile added in v1.11.0

func MetricOperationsFromFile(filePath, defaultGroup string) ([]MetricOperation, error)

func MetricOperationsFromReader added in v1.11.0

func MetricOperationsFromReader(r io.Reader, defaultGroup string) ([]MetricOperation, error)

func (MetricOperation) String added in v1.11.0

func (m MetricOperation) String() string

type ResponseParser added in v1.16.1

type ResponseParser interface {
	ParseResult(hookName string, env *HookEnv, result *Result) error
}

ResponseParser reads the hook output files and populates a Result. The default implementation (hookResponseParser) reads from the real filesystem. Tests may supply a stub that returns pre-canned values without touching disk.

type Result added in v1.4.12

type Result struct {
	Usage                *executor.CmdUsage
	Metrics              []operation.MetricOperation
	ConversionResponse   *conversion.Response
	AdmissionResponse    *admission.Response
	KubernetesPatchBytes []byte
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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