Documentation
¶
Index ¶
- func CreateRateLimiter(cfg *config.HookConfig) *rate.Limiter
- func ValidateMetricOperation(op MetricOperation) error
- func ValidateOperations(ops []MetricOperation) error
- type FileSystemHookDiscovery
- type Hook
- func (h *Hook) GetConfig() *config.HookConfig
- func (h *Hook) GetConfigDescription() string
- func (h *Hook) LoadConfig(configOutput []byte) (*Hook, error)
- func (h *Hook) RateLimitWait(ctx context.Context) error
- func (h *Hook) Run(ctx context.Context, _ htypes.BindingType, context []bctx.BindingContext, ...) (*Result, error)
- func (h *Hook) SafeName() string
- func (h *Hook) WithHookController(hookController *controller.HookController)
- func (h *Hook) WithTmpDir(dir string)
- type HookDiscovery
- type HookEnv
- type HookManager
- type IOProvider
- type Manager
- func (hm *Manager) CreateTasksFromKubeEvent(kubeEvent kemtypes.KubeEvent, ...) []task.Task
- func (hm *Manager) DetectAdmissionEventType(event admission.Event) htypes.BindingType
- func (hm *Manager) FindConversionChain(crdName string, rule conversion.Rule) []conversion.Rule
- func (hm *Manager) GetHook(name string) *Hook
- func (hm *Manager) GetHookNames() []string
- func (hm *Manager) GetHooksInOrder(bindingType htypes.BindingType) ([]string, error)
- func (hm *Manager) HandleAdmissionEvent(ctx context.Context, event admission.Event, ...)
- func (hm *Manager) HandleConversionEvent(ctx context.Context, crdName string, request *v1.ConversionRequest, ...)
- func (hm *Manager) HandleCreateTasksFromScheduleEvent(crontab string, ...) []task.Task
- func (hm *Manager) Init() error
- func (hm *Manager) TempDir() string
- func (hm *Manager) UpdateConversionChains() error
- func (hm *Manager) WorkingDir() string
- type ManagerConfig
- type MetricOperation
- type ResponseParser
- type Result
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.
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 (*Hook) GetConfig ¶
func (h *Hook) GetConfig() *config.HookConfig
func (*Hook) GetConfigDescription ¶
func (*Hook) WithHookController ¶
func (h *Hook) WithHookController(hookController *controller.HookController)
func (*Hook) WithTmpDir ¶
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.
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) GetHookNames ¶ added in v1.4.12
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
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) UpdateConversionChains ¶ added in v1.4.12
func (*Manager) WorkingDir ¶ added in v1.4.12
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
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.