Version: v0.12.3 Latest Latest

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

Go to latest
Published: Apr 3, 2022 License: MIT Imports: 36 Imported by: 0




This section is empty.


View Source
var ErrEmptySrc = fmt.Errorf("empty src template")

ErrEmptySrc is returned if an emty src template is passed to NewResource


func RegisterCustomJsFilters added in v0.10.0

func RegisterCustomJsFilters(folder string) error

RegisterCustomJsFilters loads all filters from the given directory. It returns an error if any.


type Backend

type Backend struct {

	// Name is the name of the backend for example etcd or consul.
	// The name is attached to the logs.
	Name string

	// Onetime - render the config file and quit.
	Onetime bool

	// Enable/Disable watch support.
	Watch bool

	// Watch only these keys
	WatchKeys []string

	// The key-path prefix.
	Prefix string

	// The backend polling interval. Can be used as a reconciliation loop for watch or standalone.
	Interval int

	// The backend keys that the template requires to be rendered correctly.
	Keys []string
	// contains filtered or unexported fields

Backend is the representation of a template backend like etcd or consul

type BackendConnector

type BackendConnector interface {
	Connect() (Backend, error)
	GetBackend() *Backend

A BackendConnector - Every backend implements this interface.

If Connect is called a new connection to the underlaying kv-store will be established.

Connect should also set the name and the StoreClient of the Backend. The other values of Backend will be loaded from the configuration file.

type ExecConfig

type ExecConfig struct {
	// Command is the command to execute.	// Backtick parsing is supported:
	//   ./foo `echo $SHELL`
	Command string `json:"command"`

	// ReloadSignal is the Signal that is sended to the subpocess if we want to reload it.
	// If no signal is specified the child process will be killed (gracefully) and started again.
	ReloadSignal string `toml:"reload_signal" json:"reload_signal"`

	// KillSignal defines the signal sent to the child process when remco is gracefully shutting down.
	// The application needs to exit before the kill_timeout, it will be terminated otherwise (like kill -9).
	// The default value is “SIGTERM”.
	KillSignal string `toml:"kill_signal" json:"kill_signal"`

	// KillTimeout - the maximum amount of time in seconds to wait for the child process to gracefully terminate.
	KillTimeout int `toml:"kill_timeout" json:"kill_timeout"`

	// A random splay to wait before killing the command.
	// May be useful in large clusters to prevent all child processes to reload at the same time when configuration changes occur.
	Splay int `json:"splay"`

ExecConfig represents the configuration values for the exec mode.

type Executor

type Executor struct {
	// contains filtered or unexported fields

An Executor controls a subprocess. It can control the whole process lifecycle and can reload and stop the process gracefully or send other signals to the child process using channels.

func NewExecutor

func NewExecutor(execCommand, reloadSignal, killSignal string, killTimeout, splay int, logger hclog.Logger) Executor

NewExecutor creates a new Executor.

func (*Executor) Reload

func (e *Executor) Reload() error

Reload reloads the child process. If a reloadSignal is provided it will send this signal to the child. The child process will be killed and restarted otherwise.

func (*Executor) SignalChild

func (e *Executor) SignalChild(s os.Signal) error

SignalChild forwards the os.Signal to the child process.

func (*Executor) SpawnChild

func (e *Executor) SpawnChild() error

SpawnChild parses e.execCommand and starts the child process accordingly. Backtick parsing is supported:

./foo `echo $SHELL`

only call this once !

func (*Executor) StopChild

func (e *Executor) StopChild()

StopChild stops the child process.

It blocks until the child quits or the killTimeout is reached. The child will be killed if it takes longer than killTimeout to stop it.

func (*Executor) Wait

func (e *Executor) Wait(ctx context.Context) bool

Wait waits for the child to stop. Returns true if the command stops unexpectedly and false if the context is canceled.

Wait ignores reloads.

type Renderer

type Renderer struct {
	Src       string `json:"src"`
	Dst       string `json:"dst"`
	MkDirs    bool   `toml:"make_directories"`
	Mode      string `json:"mode"`
	UID       int    `json:"uid"`
	GID       int    `json:"gid"`
	ReloadCmd string `toml:"reload_cmd" json:"reload_cmd"`
	CheckCmd  string `toml:"check_cmd" json:"check_cmd"`

	ReapLock *sync.RWMutex
	// contains filtered or unexported fields

Renderer contains all data needed for the template processing

type Resource

type Resource struct {

	// SignalChan is a channel to send os.Signal's to all child processes.
	SignalChan chan os.Signal

	// Failed is true if we run Monitor() in exec mode and the child process exits unexpectedly.
	// If the monitor context is canceled as usual Failed is false.
	// Failed is used to restart the Resource on failure.
	Failed bool

	// Set to true if this resource has backends only using "Onetime=true" flag to
	// exit on failure if the resource has some templating error
	OnetimeOnly bool
	// contains filtered or unexported fields

Resource is the representation of a parsed template resource.

func NewResource

func NewResource(backends []Backend, sources []*Renderer, name string, exec Executor, startCmd, reloadCmd string) (*Resource, error)

NewResource creates a Resource.

func NewResourceFromResourceConfig

func NewResourceFromResourceConfig(ctx context.Context, reapLock *sync.RWMutex, r ResourceConfig) (*Resource, error)

NewResourceFromResourceConfig creates a new resource from the given ResourceConfig.

func (*Resource) Close

func (t *Resource) Close()

Close closes the connection to all underlying backends.

func (*Resource) Monitor

func (t *Resource) Monitor(ctx context.Context)

Monitor will start to monitor all given Backends for changes. It accepts a ctx.Context for cancelation. It will process all given templates on changes.

type ResourceConfig

type ResourceConfig struct {
	Exec      ExecConfig
	StartCmd  string
	ReloadCmd string

	// Template is the configuration for all template options.
	// You can configure as much template-destination pairs as you like.
	Template []*Renderer

	// Name gives the Resource a name.
	// This name is added to the logs to distinguish between different resources.
	Name string

	// Connectors is a list of BackendConnectors.
	// The Resource will establish a connection to all of these.
	Connectors []BackendConnector

ResourceConfig is a configuration struct to create a new resource.


Path Synopsis

Jump to

Keyboard shortcuts

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