pkg

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2025 License: Apache-2.0 Imports: 19 Imported by: 22

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DependencyContainer

type DependencyContainer interface {
	GetHTTPClient(options ...HTTPOption) HTTPClient

	GetK8sClient(options ...KubernetesOption) (KubernetesClient, error)
	MustGetK8sClient(options ...KubernetesOption) KubernetesClient
	GetClientConfig() (*rest.Config, error)

	GetRegistryClient(repo string, options ...RegistryOption) (RegistryClient, error)
	MustGetRegistryClient(repo string, options ...RegistryOption) RegistryClient

	GetClock() clockwork.Clock
}

Container with external dependencies Avoid using dependencies, if you can, because of it cost

type Error

type Error struct {
	Message string
	Code    int
}

func (*Error) Error

func (e *Error) Error() string

type FieldSelector

type FieldSelector struct {
	MatchExpressions []FieldSelectorRequirement
}

type FieldSelectorRequirement

type FieldSelectorRequirement struct {
	Field    string
	Operator string
	Value    string
}

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

type HTTPOption

type HTTPOption interface {
	Apply(optsApplier HTTPOptionApplier)
}

type HTTPOptionApplier

type HTTPOptionApplier interface {
	WithTimeout(t time.Duration)
	WithInsecureSkipVerify()
	WithAdditionalCACerts(certs [][]byte)
	WithTLSServerName(name string)
}

type Hook

type Hook struct {
	Config        *HookConfig
	ReconcileFunc ReconcileFunc
}

type HookConfig

type HookConfig struct {
	Metadata   HookMetadata
	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

	AllowFailure bool
	Queue        string

	Settings *HookConfigSettings
}

func (*HookConfig) Validate

func (cfg *HookConfig) Validate() error

type HookConfigSettings

type HookConfigSettings struct {
	ExecutionMinInterval time.Duration
	ExecutionBurst       int
}

type HookInput

type HookInput struct {
	Snapshots Snapshots

	Values           OutputPatchableValuesCollector
	ConfigValues     OutputPatchableValuesCollector
	PatchCollector   OutputPatchCollector
	MetricsCollector MetricsCollector

	DC DependencyContainer

	Logger Logger
}

type HookMetadata

type HookMetadata struct {
	// Hook name
	Name string
	// Hook path
	Path string
}

type KubernetesClient

type KubernetesClient interface {
	client.Client
	Dynamic() dynamic.Interface
}

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 *NameSelector
	// NamespaceSelector used to subscribe on objects in namespaces.
	NamespaceSelector *NamespaceSelector
	// LabelSelector used to subscribe on objects by matching their labels.
	LabelSelector *metav1.LabelSelector
	// FieldSelector used to subscribe on objects by matching specific fields (the list of fields is narrow, see shell-operator documentation).
	FieldSelector *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
	// JQ filter to filter results from kubernetes objects
	JqFilter string
	// Allow to fail hook
	AllowFailure *bool

	ResynchronizationPeriod string
}

func (*KubernetesConfig) Validate

func (cfg *KubernetesConfig) Validate() error

you must test JqFilter by yourself

type KubernetesOption

type KubernetesOption interface {
	Apply(optsApplier KubernetesOptionApplier)
}

type KubernetesOptionApplier

type KubernetesOptionApplier interface {
	WithSchemeBuilder(builder runtime.SchemeBuilder)
}

type Logger

type Logger interface {
	Debug(msg string, args ...any)
	DebugContext(ctx context.Context, msg string, args ...any)

	Error(msg string, args ...any)
	ErrorContext(ctx context.Context, msg string, args ...any)

	Fatal(msg string, args ...any)

	Info(msg string, args ...any)
	InfoContext(ctx context.Context, msg 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)

	Warn(msg string, args ...any)
	WarnContext(ctx context.Context, msg 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 MetricCollectorOption

type MetricCollectorOption interface {
	Apply(op MetricCollectorOptionApplier)
}

type MetricCollectorOptionApplier

type MetricCollectorOptionApplier interface {
	WithGroup(group string)
}

type MetricsCollector

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

type NameSelector

type NameSelector struct {
	MatchNames []string
}

func (*NameSelector) Validate

func (cfg *NameSelector) Validate() error

type NamespaceSelector

type NamespaceSelector struct {
	NameSelector  *NameSelector
	LabelSelector *metav1.LabelSelector
}

func (*NamespaceSelector) Validate

func (cfg *NamespaceSelector) Validate() error

type OrderedConfig

type OrderedConfig struct {
	Order uint
}

type OutputMetricsCollector

type OutputMetricsCollector interface {
	MetricsCollector
	Outputer
}

type OutputPatchCollector

type OutputPatchCollector interface {
	// Deprecated: use PatchWithMerge instead
	PatchCollector
	Outputer
}

type OutputPatchableValuesCollector

type OutputPatchableValuesCollector interface {
	PatchableValuesCollector
	Outputer
}

type Outputer

type Outputer interface {
	WriteOutput(writer io.Writer) error
}

type PatchCollector

type PatchCollector interface {
	// object must be Unstructured, map[string]any or runtime.Object
	Create(object any)
	// object must be Unstructured, map[string]any or runtime.Object
	CreateIfNotExists(object any)
	// object must be Unstructured, map[string]any or runtime.Object
	CreateOrUpdate(object any)

	// The object exists in the key-value store until the garbage collector
	// deletes all the dependents whose ownerReference.blockOwnerDeletion=true
	// from the key-value store.  API sever will put the "foregroundDeletion"
	// finalizer on the object, and sets its deletionTimestamp.  This policy is
	// cascading, i.e., the dependents will be deleted with Foreground.
	Delete(apiVersion string, kind string, namespace string, name string)
	// Deletes the object from the key-value store, the garbage collector will
	// delete the dependents in the background.
	DeleteInBackground(apiVersion string, kind string, namespace string, name string)
	// Orphans the dependents.
	DeleteNonCascading(apiVersion string, kind string, namespace string, name string)

	// Deprecated: use PatchWithJSON instead
	JSONPatch(jsonPatch any, apiVersion string, kind string, namespace string, name string, opts ...PatchCollectorOption)
	// Deprecated: use PatchWithMerge instead
	MergePatch(mergePatch any, apiVersion string, kind string, namespace string, name string, opts ...PatchCollectorOption)
	// Deprecated: use PatchWithJQ instead
	JQFilter(jqfilter string, apiVersion string, kind string, namespace string, name string, opts ...PatchCollectorOption)

	// JSONPatch is a PatchType indicating the patch should be interpreted as a RFC6902 JSON Patch.
	// This patch format requires specifying operations, paths, and values explicitly.
	// See https://tools.ietf.org/html/rfc6902 for details.
	PatchWithJSON(jsonPatch any, apiVersion string, kind string, namespace string, name string, opts ...PatchCollectorOption)
	// MergePatch is a PatchType indicating the patch should be interpreted as a RFC7396 JSON Merge Patch.
	// This patch format replaces elements at the object level rather than requiring explicit operations.
	// See https://tools.ietf.org/html/rfc7396 for details.
	PatchWithMerge(mergePatch any, apiVersion string, kind string, namespace string, name string, opts ...PatchCollectorOption)
	// Mutate object with jq query
	PatchWithJQ(jqfilter string, apiVersion string, kind string, namespace string, name string, opts ...PatchCollectorOption)

	Operations() []PatchCollectorOperation
}

type PatchCollectorOperation

type PatchCollectorOperation interface {
	Description() string
}

There are 4 types of operations:

- createOperation to create or update object via Create and Update API calls. Unstructured, map[string]any or runtime.Object is required.

- deleteOperation to delete object via Delete API call

- patchOperation to modify object via Patch API call

- filterOperation to modify object via Get-filter-Update process

type PatchCollectorOption

type PatchCollectorOption interface {
	Apply(PatchCollectorOptionApplier)
}

type PatchCollectorOptionApplier

type PatchCollectorOptionApplier interface {
	WithSubresource(subresource string)
	WithIgnoreMissingObject(ignore bool)
	WithIgnoreHookError(update bool)
}

type PatchableValuesCollector

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) any
	Remove(path string)
	Set(path string, value any)
}

type ReconcileFunc

type ReconcileFunc func(ctx context.Context, input *HookInput) error

ReconcileFunc function which holds the main logic of the hook

type RegistryClient

type RegistryClient interface {
	Image(ctx context.Context, tag string) (v1.Image, error)
	Digest(ctx context.Context, tag string) (string, error)
	ListTags(ctx context.Context) ([]string, error)
}

type RegistryOption

type RegistryOption interface {
	Apply(optsApplier RegistryOptionApplier)
}

type RegistryOptionApplier

type RegistryOptionApplier interface {
	WithCA(ca string)
	WithInsecureSchema(insecure bool)
	WithAuth(dockerCfg string)
	WithUserAgent(ua string)
	WithTimeout(timeout time.Duration)
}

type ScheduleConfig

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

func (*ScheduleConfig) Validate

func (cfg *ScheduleConfig) Validate() error

type Snapshot

type Snapshot interface {
	UnmarshalTo(v any) error
	// returns pure form of object
	// can contains special symbols
	// to receive string values - use UnmarshalTo method
	String() string
}

type Snapshots

type Snapshots interface {
	Get(key string) []Snapshot
}

Jump to

Keyboard shortcuts

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