go_hook

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2025 License: Apache-2.0 Imports: 16 Imported by: 105

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(b bool) *bool

Bool returns a pointer to a bool.

func BoolDeref

func BoolDeref(ptr *bool, def bool) bool

BoolDeref dereferences the bool ptr and returns it if not nil, or else returns def.

Types

type BindingAction

type BindingAction struct {
	Name       string // binding name
	Action     string // Disable / UpdateKind
	Kind       string
	ApiVersion string
}

type FilterFunc

type FilterFunc func(*unstructured.Unstructured) (FilterResult, error)

type FilterResult

type FilterResult interface{}

type GoHook

type GoHook interface {
	Config() *HookConfig
	Run(input *HookInput) error
}

type HookBindingContext

type HookBindingContext struct {
	// Type of binding context: [Event, Synchronization, Group, Schedule]
	Type string
	// Binding is a related binding name.
	Binding string
	// Snapshots contain all objects for all bindings.
	Snapshots map[string][]types.ObjectAndFilterResult
}

type HookConfig

type HookConfig struct {
	Schedule   []ScheduleConfig
	Kubernetes []KubernetesConfig
	// OnStartup runs hook on module/global startup
	// Attention! During the startup you don't have snapshots available
	// use native KubeClient to fetch resources
	OnStartup         *OrderedConfig
	OnBeforeHelm      *OrderedConfig
	OnAfterHelm       *OrderedConfig
	OnAfterDeleteHelm *OrderedConfig
	OnBeforeAll       *OrderedConfig
	OnAfterAll        *OrderedConfig
	AllowFailure      bool
	Queue             string
	Settings          *HookConfigSettings
	Logger            *log.Logger
}

type HookConfigLoader added in v1.6.0

type HookConfigLoader interface {
	GetConfigForModule(moduleKind string) (*config.HookConfig, error)
	GetOnStartup() *float64
	GetBeforeAll() *float64
	GetAfterAll() *float64
	GetAfterDeleteHelm() *float64
}

type HookConfigSettings

type HookConfigSettings struct {
	ExecutionMinInterval time.Duration
	ExecutionBurst       int

	// EnableSchedulesOnStartup
	// set to true, if you need to run 'Schedule' hooks without waiting addon-operator readiness
	EnableSchedulesOnStartup bool
}

type HookInput

type HookInput struct {
	Snapshots        Snapshots
	Values           PatchableValuesCollector
	ConfigValues     PatchableValuesCollector
	MetricsCollector MetricsCollector
	PatchCollector   PatchCollector
	Logger           Logger
	BindingActions   *[]BindingAction
}

type HookMetadata

type HookMetadata struct {
	Name           string
	Path           string
	Global         bool
	EmbeddedModule bool
	ModuleName     string
}

type KubernetesConfig

type KubernetesConfig struct {
	// Name is a key in snapshots map.
	Name string
	// ApiVersion of objects. "v1" is used if not set.
	ApiVersion string
	// Kind of objects.
	Kind string
	// NameSelector used to subscribe on object by its name.
	NameSelector *types.NameSelector
	// NamespaceSelector used to subscribe on objects in namespaces.
	NamespaceSelector *types.NamespaceSelector
	// LabelSelector used to subscribe on objects by matching their labels.
	LabelSelector *v1.LabelSelector
	// FieldSelector used to subscribe on objects by matching specific fields (the list of fields is narrow, see shell-operator documentation).
	FieldSelector *types.FieldSelector
	// ExecuteHookOnEvents is true by default. Set to false if only snapshot update is needed.
	ExecuteHookOnEvents *bool
	// ExecuteHookOnSynchronization is true by default. Set to false if only snapshot update is needed.
	ExecuteHookOnSynchronization *bool
	// WaitForSynchronization is true by default. Set to false if beforeHelm is not required this snapshot on start.
	WaitForSynchronization *bool
	// FilterFunc used to filter object content for snapshot. Addon-operator use checksum of this filtered result to ignore irrelevant events.
	FilterFunc FilterFunc
}

type Logger added in v1.6.0

type Logger interface {
	Debug(msg string, args ...any)
	DebugContext(ctx context.Context, msg string, args ...any)
	// Deprecated: use Debug instead
	Debugf(format string, args ...any)
	Error(msg string, args ...any)
	ErrorContext(ctx context.Context, msg string, args ...any)
	// Deprecated: use Error instead
	Errorf(format string, args ...any)
	Fatal(msg string, args ...any)
	// Deprecated: use Fatal instead
	Fatalf(format string, args ...any)
	Info(msg string, args ...any)
	InfoContext(ctx context.Context, msg string, args ...any)
	// Deprecated: use Info instead
	Infof(format string, args ...any)
	Log(ctx context.Context, level slog.Level, msg string, args ...any)
	LogAttrs(ctx context.Context, level slog.Level, msg string, attrs ...slog.Attr)
	// Deprecated: use Log instead
	Logf(ctx context.Context, level log.Level, format string, args ...any)
	Warn(msg string, args ...any)
	WarnContext(ctx context.Context, msg string, args ...any)
	// Deprecated: use Warn instead
	Warnf(format string, args ...any)

	Enabled(ctx context.Context, level slog.Level) bool
	With(args ...any) *log.Logger
	WithGroup(name string) *log.Logger
	Named(name string) *log.Logger
	SetLevel(level log.Level)
	SetOutput(w io.Writer)
	GetLevel() log.Level
	Handler() slog.Handler
}

type MetricsCollector

type MetricsCollector interface {
	// Inc increments the specified Counter metric
	Inc(name string, labels map[string]string, opts ...metrics.Option)
	// Add adds custom value for the specified Counter metric
	Add(name string, value float64, labels map[string]string, opts ...metrics.Option)
	// Set specifies the custom value for the Gauge metric
	Set(name string, value float64, labels map[string]string, opts ...metrics.Option)
	// Expire marks metric's group as expired
	Expire(group string)
}

MetricsCollector collects metric's records for exporting them as a batch

type OrderedConfig

type OrderedConfig struct {
	Order float64
}

type PatchCollector added in v1.6.0

type PatchCollector interface {
	sdkpkg.PatchCollector

	PatchWithMutatingFunc(fn func(*unstructured.Unstructured) (*unstructured.Unstructured, error), apiVersion string, kind string, namespace string, name string, opts ...sdkpkg.PatchCollectorOption)
}

type PatchableValues

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

func NewPatchableValues

func NewPatchableValues(values map[string]interface{}) (*PatchableValues, error)

func (*PatchableValues) ArrayCount

func (p *PatchableValues) ArrayCount(path string) (int, error)

ArrayCount counts the number of elements in a JSON array at a path

func (*PatchableValues) Exists

func (p *PatchableValues) Exists(path string) bool

Exists checks whether a path exists

func (*PatchableValues) Get

func (p *PatchableValues) Get(path string) gjson.Result

Get value from patchable. It could be null value

func (*PatchableValues) GetOk

func (p *PatchableValues) GetOk(path string) (gjson.Result, bool)

GetOk returns value and `exists` flag

func (*PatchableValues) GetPatches

func (p *PatchableValues) GetPatches() []*utils.ValuesPatchOperation

func (*PatchableValues) GetRaw

func (p *PatchableValues) GetRaw(path string) interface{}

GetRaw get empty interface

func (*PatchableValues) Remove

func (p *PatchableValues) Remove(path string)

func (*PatchableValues) Set

func (p *PatchableValues) Set(path string, value interface{})

type PatchableValuesCollector added in v1.6.0

type PatchableValuesCollector interface {
	ArrayCount(path string) (int, error)
	Exists(path string) bool
	Get(path string) gjson.Result
	GetOk(path string) (gjson.Result, bool)
	GetPatches() []*utils.ValuesPatchOperation
	GetRaw(path string) interface{}
	Remove(path string)
	Set(path string, value interface{})
}

type ScheduleConfig

type ScheduleConfig struct {
	Name string
	// Crontab is a schedule config in crontab format. (5 or 6 fields)
	Crontab string
}

type Snapshots

type Snapshots map[string][]FilterResult

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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