shell_operator

package
v1.0.12 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2022 License: Apache-2.0 Imports: 33 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultMainKubeClientMetricLabels = map[string]string{"component": "main"}
View Source
var DefaultObjectPatcherKubeClientMetricLabels = map[string]string{"component": "object_patcher"}
View Source
var WaitQueuesTimeout = time.Second * 10

Functions

func AssembleCommonOperator added in v1.0.11

func AssembleCommonOperator(op *ShellOperator) (err error)

AssembleCommonOperator instantiate common dependencies. These dependencies may be used for shell-operator derivatives, like addon-operator.

func AssembleShellOperator added in v1.0.11

func AssembleShellOperator(op *ShellOperator, hooksDir string, tempDir string, debugServer *debug.Server, runtimeConfig *config.Config) (err error)

AssembleShellOperator uses settings in app package to create all dependencies needed for the full-fledged ShellOperator.

- check directories - start debug server - initialize dependencies:

  • metric storage
  • kubernetes client config
  • empty set of task queues
  • hook manager
  • kubernetes events manager
  • schedule manager

func DefaultDebugServer added in v1.0.11

func DefaultDebugServer() *debug.Server

func DefaultHookMetricStorage added in v1.0.11

func DefaultHookMetricStorage(ctx context.Context) *metric_storage.MetricStorage

DefaultHookMetricStorage creates MetricStorage object with new registry to scrape hook metrics on separate port.

func DefaultIfEmpty added in v1.0.11

func DefaultIfEmpty(m map[string]string, def map[string]string) map[string]string

func DefaultMainKubeClient added in v1.0.11

func DefaultMainKubeClient(metricStorage *metric_storage.MetricStorage, metricLabels map[string]string) klient.Client

DefaultMainKubeClient creates a Kubernetes client for hooks. No timeout specified, because timeout will reset connections for Watchers.

func DefaultMetricStorage added in v1.0.11

func DefaultMetricStorage(ctx context.Context) *metric_storage.MetricStorage

func DefaultObjectPatcherKubeClient added in v1.0.11

func DefaultObjectPatcherKubeClient(metricStorage *metric_storage.MetricStorage, metricLabels map[string]string) klient.Client

DefaultObjectPatcherKubeClient initializes a Kubernetes client for ObjectPatcher. Timeout is specified here.

func EnsureTempDirectory added in v1.0.11

func EnsureTempDirectory(inDir string) (string, error)

func InitDefaultDebugServer added in v1.0.11

func InitDefaultDebugServer() (*debug.Server, error)

func InitDefaultMainKubeClient added in v1.0.11

func InitDefaultMainKubeClient(metricStorage *metric_storage.MetricStorage) (klient.Client, error)

func InitDefaultObjectPatcher added in v1.0.11

func InitDefaultObjectPatcher(metricStorage *metric_storage.MetricStorage) (*object_patch.ObjectPatcher, error)

func RegisterCommonMetrics

func RegisterCommonMetrics(metricStorage *metric_storage.MetricStorage)

func RegisterDebugConfigRoutes added in v1.0.11

func RegisterDebugConfigRoutes(dbgSrv *debug.Server, runtimeConfig *config.Config)

RegisterDebugConfigRoutes registers routes to manage runtime configuration.

func RegisterDebugHookRoutes added in v1.0.11

func RegisterDebugHookRoutes(dbgSrv *debug.Server, op *ShellOperator)

func RegisterDebugQueueRoutes added in v1.0.11

func RegisterDebugQueueRoutes(dbgSrv *debug.Server, op *ShellOperator)

func RegisterDefaultRoutes added in v1.0.11

func RegisterDefaultRoutes(op *ShellOperator)

func RegisterHookMetrics

func RegisterHookMetrics(metricStorage *metric_storage.MetricStorage)

Shell-operator specific metrics for HookManager

func RegisterKubeEventsManagerMetrics

func RegisterKubeEventsManagerMetrics(metricStorage *metric_storage.MetricStorage, labels map[string]string)

metrics for kube_event_manager

func RegisterShellOperatorMetrics

func RegisterShellOperatorMetrics(metricStorage *metric_storage.MetricStorage)

RegisterShellOperatorMetrics register all metrics needed for the ShellOperator.

func RegisterTaskQueueMetrics

func RegisterTaskQueueMetrics(metricStorage *metric_storage.MetricStorage)

func RequireExistingDirectory added in v1.0.11

func RequireExistingDirectory(inDir string) (dir string, err error)

func SetupEventManagers added in v1.0.11

func SetupEventManagers(op *ShellOperator)

SetupEventManagers instantiate queues and managers for schedule and Kubernetes events.

func SetupHookManagers added in v1.0.11

func SetupHookManagers(op *ShellOperator, hooksDir string, tempDir string)

SetupHookManagers instantiates different hook managers.

func SetupHookMetricStorageAndServer added in v1.0.11

func SetupHookMetricStorageAndServer(ctx context.Context) (*metric_storage.MetricStorage, error)

func StartHttpServer added in v1.0.11

func StartHttpServer(ip string, port string, mux *http.ServeMux) error

Types

type CombineResult

type CombineResult struct {
	BindingContexts []BindingContext
	MonitorIDs      []string
}

func CombineBindingContextForHook added in v1.0.11

func CombineBindingContextForHook(tqs *queue.TaskQueueSet, q *queue.TaskQueue, t task.Task, stopCombineFn func(tsk task.Task) bool) *CombineResult

CombineBindingContextForHook combines binding contexts from a sequence of task with similar hook name and task type into array of binding context and delete excess tasks from queue.

Also, sequences of binding contexts with similar group are compacted in one binding context.

If input task has no metadata, result will be nil. Metadata should implement HookNameAccessor, BindingContextAccessor and MonitorIDAccessor interfaces. DEV WARNING! Do not use HookMetadataAccessor here. Use only *Accessor interfaces because this method is used from addon-operator.

type ManagerEventsHandler

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

func NewManagerEventsHandler

func NewManagerEventsHandler() *ManagerEventsHandler

func (*ManagerEventsHandler) Start

func (m *ManagerEventsHandler) Start()

func (*ManagerEventsHandler) Stop

func (m *ManagerEventsHandler) Stop()

func (*ManagerEventsHandler) WithContext

func (m *ManagerEventsHandler) WithContext(ctx context.Context)

func (*ManagerEventsHandler) WithKubeEventHandler

func (m *ManagerEventsHandler) WithKubeEventHandler(fn func(kubeEvent KubeEvent) []task.Task)

func (*ManagerEventsHandler) WithKubeEventsManager

func (m *ManagerEventsHandler) WithKubeEventsManager(mgr kube_events_manager.KubeEventsManager)

func (*ManagerEventsHandler) WithScheduleEventHandler

func (m *ManagerEventsHandler) WithScheduleEventHandler(fn func(crontab string) []task.Task)

func (*ManagerEventsHandler) WithScheduleManager

func (m *ManagerEventsHandler) WithScheduleManager(mgr schedule_manager.ScheduleManager)

func (*ManagerEventsHandler) WithTaskQueueSet

func (m *ManagerEventsHandler) WithTaskQueueSet(tqs *queue.TaskQueueSet)

type ShellOperator

type ShellOperator struct {
	MetricStorage *metric_storage.MetricStorage
	// separate metric storage for hook metrics if separate listen port is configured
	HookMetricStorage *metric_storage.MetricStorage
	KubeClient        klient.Client
	ObjectPatcher     *object_patch.ObjectPatcher

	ScheduleManager   schedule_manager.ScheduleManager
	KubeEventsManager kube_events_manager.KubeEventsManager

	TaskQueues *queue.TaskQueueSet

	ManagerEventsHandler *ManagerEventsHandler

	HookManager hook.HookManager

	ValidatingWebhookManager *validating.WebhookManager
	ConversionWebhookManager *conversion.WebhookManager
	// contains filtered or unexported fields
}

func Init added in v1.0.11

func Init() (*ShellOperator, error)

Init initialize logging, ensures directories and creates a ShellOperator instance with all dependencies.

func NewShellOperator

func NewShellOperator() *ShellOperator

func (*ShellOperator) BootstrapMainQueue added in v1.0.11

func (op *ShellOperator) BootstrapMainQueue(tqs *queue.TaskQueueSet)

BootstrapMainQueue adds tasks to run hooks with OnStartup bindings and tasks to enable kubernetes bindings.

func (*ShellOperator) CombineBindingContextForHook

func (op *ShellOperator) CombineBindingContextForHook(q *queue.TaskQueue, t task.Task, stopCombineFn func(tsk task.Task) bool) *CombineResult

CombineBindingContextForHook combines binding contexts from a sequence of task with similar hook name and task type into array of binding context and delete excess tasks from queue.

Also, sequences of binding contexts with similar group are compacted in one binding context.

If input task has no metadata, result will be nil. Metadata should implement HookNameAccessor, BindingContextAccessor and MonitorIDAccessor interfaces. DEV WARNING! Do not use HookMetadataAccessor here. Use only *Accessor interfaces because this method is used from addon-operator.

func (*ShellOperator) ConversionEventHandler

func (op *ShellOperator) ConversionEventHandler(event conversion.Event) (*conversion.Response, error)

ConversionEventHandler is called when Kubernetes requests a conversion.

func (*ShellOperator) HandleRunHook

func (op *ShellOperator) HandleRunHook(t task.Task, taskHook *hook.Hook, hookMeta HookMetadata, taskLogEntry *log.Entry, hookLogLabels map[string]string, metricLabels map[string]string) error

func (*ShellOperator) InitAndStartHookQueues

func (op *ShellOperator) InitAndStartHookQueues()

InitAndStartHookQueues create all queues defined in hooks

func (*ShellOperator) InitConversionWebhookManager

func (op *ShellOperator) InitConversionWebhookManager() (err error)

InitConversionWebhookManager creates and starts a conversion webhook manager.

func (*ShellOperator) InitHookManager

func (op *ShellOperator) InitHookManager() (err error)

InitHookManager load hooks from HooksDir and defines event handlers that emit tasks.

func (*ShellOperator) InitValidatingWebhookManager

func (op *ShellOperator) InitValidatingWebhookManager() (err error)

InitValidatingWebhookManager adds kubernetesValidating hooks to a WebhookManager and set a validating event handler.

func (*ShellOperator) RunMetrics

func (op *ShellOperator) RunMetrics()

func (*ShellOperator) Shutdown

func (op *ShellOperator) Shutdown()

Shutdown pause kubernetes events handling and stop queues. Wait for queues to stop.

func (*ShellOperator) Start

func (op *ShellOperator) Start()

Start

func (*ShellOperator) Stop

func (op *ShellOperator) Stop()

func (*ShellOperator) TaskHandleEnableKubernetesBindings

func (op *ShellOperator) TaskHandleEnableKubernetesBindings(t task.Task) queue.TaskResult

TaskHandleEnableKubernetesBindings creates task for each Kubernetes binding in the hook and queues them.

func (*ShellOperator) TaskHandleHookRun

func (op *ShellOperator) TaskHandleHookRun(t task.Task) queue.TaskResult

TODO use Context to pass labels and a queue name

func (*ShellOperator) TaskHandler

func (op *ShellOperator) TaskHandler(t task.Task) queue.TaskResult

TaskHandler

func (*ShellOperator) WithContext

func (op *ShellOperator) WithContext(ctx context.Context) *ShellOperator

func (*ShellOperator) WithKubernetesClient

func (op *ShellOperator) WithKubernetesClient(klient klient.Client)

func (*ShellOperator) WithMetricStorage

func (op *ShellOperator) WithMetricStorage(metricStorage *metric_storage.MetricStorage)

Jump to

Keyboard shortcuts

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