controller

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2023 License: MPL-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InstallDriver

func InstallDriver(ctx context.Context, conf *config.Config) error

InstallDriver installs necessary drivers based on user configuration.

func NewDriverFactory added in v0.6.0

func NewDriverFactory(conf *config.Config, watcher templates.Watcher) (*driverFactory, error)

NewDriverFactory configures a new driver factory

Types

type ConditionMonitor added in v0.6.0

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

ConditionMonitor monitors the the conditions for all of the tasks and is responsible for triggering a task to execute. It uses the task manager to inform of starting / stopping task monitoring as well as executing a task

func NewConditionMonitor added in v0.6.0

func NewConditionMonitor(tm *TasksManager, w templates.Watcher) *ConditionMonitor

NewConditionMonitor configures a new condition monitor

func (*ConditionMonitor) Run added in v0.6.0

func (cm *ConditionMonitor) Run(ctx context.Context) error

Run runs a continuous loop which monitors the Consul catalog. On changes, Run uses the TasksManager to execute tasks to update network infrastructure.

The blocking call runs the main Consul monitoring loop, which identifies triggers for dynamic tasks. Scheduled tasks use their own go routine to trigger on schedule.

func (*ConditionMonitor) WatchDep added in v0.6.0

func (cm *ConditionMonitor) WatchDep(ctx context.Context) error

WatchDep is a helper method to start watching dependencies to allow templates to render. It will run until the caller cancels the context.

type Controller

type Controller interface {
	// Init initializes elements needed by controller. Returns a map of
	// taskname to driver
	Init(ctx context.Context) error

	// Run runs the controller by monitoring Consul and triggering the driver as needed
	Run(ctx context.Context) error

	// Stop stops underlying clients and connections
	Stop()
}

Controller describes the interface for monitoring Consul for relevant changes and triggering the driver to update network infrastructure.

type Daemon added in v0.6.0

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

Daemon is the controller to run CTS as a daemon. It executes the tasks once (once-mode) and then runs the task in long-running mode. It also starts daemon-only features such as the API server

func NewDaemon added in v0.6.0

func NewDaemon(conf *config.Config) (*Daemon, error)

NewDaemon configures and initializes a new Daemon controller

func (*Daemon) EnableTaskRanNotify added in v0.6.0

func (ctrl *Daemon) EnableTaskRanNotify() <-chan string

func (*Daemon) Init added in v0.6.0

func (ctrl *Daemon) Init(ctx context.Context) error

Init initializes the controller before it can be run. Ensures that driver is initializes, works are created for each task.

func (*Daemon) Once added in v0.6.0

func (ctrl *Daemon) Once(ctx context.Context) error

Once runs the tasks once. Intended to only be called by Run()

func (*Daemon) Run added in v0.6.0

func (ctrl *Daemon) Run(ctx context.Context) error

func (*Daemon) Stop added in v0.6.0

func (ctrl *Daemon) Stop()

type Inspect added in v0.6.0

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

Inspect is the controller to run in inspect mode

func NewInspect added in v0.6.0

func NewInspect(conf *config.Config) (*Inspect, error)

NewInspect configures and initializes a new inspect controller

func (*Inspect) Init added in v0.6.0

func (ctrl *Inspect) Init(ctx context.Context) error

Init initializes the controller before it can be run

func (*Inspect) Run added in v0.6.0

func (ctrl *Inspect) Run(ctx context.Context) error

func (*Inspect) Stop added in v0.6.0

func (ctrl *Inspect) Stop()

type Once added in v0.6.0

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

Once is the controller to run in once mode

func NewOnce added in v0.6.0

func NewOnce(conf *config.Config) (*Once, error)

NewOnce configures and initializes a new Once controller

func (*Once) Init added in v0.6.0

func (ctrl *Once) Init(ctx context.Context) error

Init initializes the controller before it can be run.

func (*Once) Run added in v0.6.0

func (ctrl *Once) Run(ctx context.Context) error

func (*Once) Stop added in v0.6.0

func (ctrl *Once) Stop()

type TasksManager added in v0.6.0

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

TasksManager manages the CRUD operations and execution of tasks

func NewTasksManager added in v0.6.0

func NewTasksManager(conf *config.Config, state state.Store, watcher templates.Watcher) (*TasksManager, error)

NewTasksManager configures a new tasks manager

func (*TasksManager) Config added in v0.6.0

func (tm *TasksManager) Config() config.Config

Config returns the config from the TasksManager's state store

func (*TasksManager) EnableTaskDeletedNotify added in v0.6.0

func (tm *TasksManager) EnableTaskDeletedNotify() <-chan string

EnableTaskDeletedNotify is a helper for enabling notifications when a task has finished deleting. Callers of this method must consume from deletedTaskNotify channel to prevent the buffered channel from filling and causing a dead lock. EnableTaskDeletedNotify is typically used for testing.

func (*TasksManager) EnableTaskRanNotify added in v0.6.0

func (tm *TasksManager) EnableTaskRanNotify() <-chan string

EnableTaskRanNotify is a helper for enabling notifications when a task has finished executing after being triggered. Callers of this method must consume from ranTaskNotify channel to prevent the buffered channel from filling and causing a dead lock. EnableTaskRanNotify is typically used for testing.

func (*TasksManager) Events added in v0.6.0

func (tm *TasksManager) Events(_ context.Context, taskName string) (map[string][]event.Event, error)

Events takes as an argument a task name and returns the associated event list map from the TasksManager's state store

func (*TasksManager) Init added in v0.6.0

func (tm *TasksManager) Init(ctx context.Context) error

Init initializes a tasks manager

func (*TasksManager) Task added in v0.6.0

func (tm *TasksManager) Task(_ context.Context, taskName string) (config.TaskConfig, error)

Task takes as an argument a task name and returns the associated TaskConfig object from the TasksManager's state store

func (TasksManager) TaskByTemplate added in v0.6.0

func (tm TasksManager) TaskByTemplate(tmplID string) (string, bool)

TaskByTemplate returns the name of the task associated with a template id. If no task is associated with the template id, returns false.

func (*TasksManager) TaskCreate added in v0.6.0

func (tm *TasksManager) TaskCreate(ctx context.Context, taskConfig config.TaskConfig) (config.TaskConfig, error)

TaskCreate creates a new task and adds it to the managed tasks Note: This will not run the task after creation, see TaskCreateAndRun for this behavior

func (*TasksManager) TaskCreateAndRun added in v0.6.0

func (tm *TasksManager) TaskCreateAndRun(ctx context.Context, taskConfig config.TaskConfig) (config.TaskConfig, error)

TaskCreateAndRun creates a new task and then runs it. If successful it then adds the task to the managed tasks.

func (*TasksManager) TaskCreateAndRunAllowFail added in v0.7.0

func (tm *TasksManager) TaskCreateAndRunAllowFail(ctx context.Context, taskConfig config.TaskConfig)

TaskCreateAndRunAllowFail creates, runs, and adds a new task. It expects that this task is highly unlikely to error because it has previously been created and run before. Therefore it allows failure and does not handle error beyond logging

This method is used when we do not want the caller to error and exit when creating, running, and adding a new task.

func (*TasksManager) TaskDelete added in v0.6.0

func (tm *TasksManager) TaskDelete(_ context.Context, name string) error

TaskDelete marks an existing task that has been added to CTS for deletion then asynchronously deletes the task.

func (*TasksManager) TaskInspect added in v0.6.0

func (tm *TasksManager) TaskInspect(ctx context.Context, taskConfig config.TaskConfig) (bool, string, string, error)

TaskInspect creates and inspects a temporary task that is not added to the drivers list.

func (*TasksManager) TaskRunNow added in v0.6.0

func (tm *TasksManager) TaskRunNow(ctx context.Context, taskName string) error

TaskRunNow forces an existing task to run with a retry. It assumes that the task has already been created through TaskCreate or TaskCreateAndRun. It runs a task by attempting to render the template and applying the task as necessary.

An event is stored:

  1. whenever a task errors while executing
  2. when a dynamic task successfully executes
  3. when a scheduled task successfully executes (regardless of if there were dependency changes)

Note on #2: no event is stored when a dynamic task renders but does not apply. This can occur because driver.RenderTemplate() may need to be called multiple times before a template is ready to be applied.

func (*TasksManager) TaskUpdate added in v0.6.0

func (tm *TasksManager) TaskUpdate(ctx context.Context, updateConf config.TaskConfig, runOp string) (bool, string, string, error)

TaskUpdate patches a managed task with the provided configuration. If runOp is set to runtimeNow it will immediately run before completing the update, otherwise it will perform the update without running. Note: Currently only changes to the enabled state of the task are supported

func (*TasksManager) Tasks added in v0.6.0

Tasks returns all tasks which exist in the TaskManager's state store

func (TasksManager) WatchCreatedScheduleTasks added in v0.6.0

func (tm TasksManager) WatchCreatedScheduleTasks() <-chan string

WatchCreatedScheduleTasks returns a channel to inform any watcher that a new scheduled task has been created and added to CTS.

func (TasksManager) WatchDeletedScheduleTask added in v0.6.0

func (tm TasksManager) WatchDeletedScheduleTask() <-chan string

WatchDeletedScheduleTask returns a channel to inform any watcher that a new scheduled task has been deleted and removed from CTS.

Jump to

Keyboard shortcuts

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