Documentation ¶
Index ¶
- func AtomicWrite(path string, contents []byte, perms os.FileMode, backup bool) error
- type DedupManager
- type ErrChildDied
- type ErrExitable
- type RenderEvent
- type RenderInput
- type RenderResult
- type Runner
- func (r *Runner) Receive(d dep.Dependency, data interface{})
- func (r *Runner) RenderEvents() map[string]*RenderEvent
- func (r *Runner) Run() error
- func (r *Runner) Signal(s os.Signal) error
- func (r *Runner) Start()
- func (r *Runner) Stop()
- func (r *Runner) TemplateConfigMapping() map[string][]config.TemplateConfig
- func (r *Runner) TemplateRenderedCh() <-chan struct{}
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AtomicWrite ¶
AtomicWrite accepts a destination path and the template contents. It writes the template contents to a TempFile on disk, returning if any errors occur.
If the parent destination directory does not exist, it will be created automatically with permissions 0755. To use a different permission, create the directory first or use `chmod` in a Command.
If the destination path exists, all attempts will be made to preserve the existing file permissions. If those permissions cannot be read, an error is returned. If the file does not exist, it will be created automatically with permissions 0644. To use a different permission, create the destination file first or use `chmod` in a Command.
If no errors occur, the Tempfile is "renamed" (moved) to the destination path.
Types ¶
type DedupManager ¶
type DedupManager struct {
// contains filtered or unexported fields
}
DedupManager is used to de-duplicate which instance of Consul-Template is handling each template. For each template, a lock path is determined using the MD5 of the template. This path is used to elect a "leader" instance.
The leader instance operations like usual, but any time a template is rendered, any of the data required for rendering is stored in the Consul KV store under the lock path.
The follower instances depend on the leader to do the primary watching and rendering, and instead only watch the aggregated data in the KV. Followers wait for updates and re-render the template.
If a template depends on 50 views, and is running on 50 machines, that would normally require 2500 blocking queries. Using deduplication, one instance has 50 view queries, plus 50 additional queries on the lock path for a total of 100.
func NewDedupManager ¶
func NewDedupManager(config *config.DedupConfig, clients *dep.ClientSet, brain *template.Brain, templates []*template.Template) (*DedupManager, error)
NewDedupManager creates a new Dedup manager
func (*DedupManager) IsLeader ¶
func (d *DedupManager) IsLeader(tmpl *template.Template) bool
IsLeader checks if we are currently the leader instance
func (*DedupManager) Start ¶
func (d *DedupManager) Start() error
Start is used to start the de-duplication manager
func (*DedupManager) Stop ¶
func (d *DedupManager) Stop() error
Stop is used to stop the de-duplication manager
func (*DedupManager) UpdateCh ¶
func (d *DedupManager) UpdateCh() <-chan struct{}
UpdateCh returns a channel to watch for depedency updates
func (*DedupManager) UpdateDeps ¶
func (d *DedupManager) UpdateDeps(t *template.Template, deps []dep.Dependency) error
UpdateDeps is used to update the values of the dependencies for a template
type ErrChildDied ¶
type ErrChildDied struct {
// contains filtered or unexported fields
}
ErrChildDied is the error returned when the child process prematurely dies.
func NewErrChildDied ¶
func NewErrChildDied(c int) *ErrChildDied
NewErrChildDied creates a new error with the given exit code.
func (*ErrChildDied) Error ¶
func (e *ErrChildDied) Error() string
Error implements the error interface.
func (*ErrChildDied) ExitStatus ¶
func (e *ErrChildDied) ExitStatus() int
ExitStatus implements the ErrExitable interface.
type ErrExitable ¶
type ErrExitable interface {
ExitStatus() int
}
ErrExitable is an interface that defines an integer ExitStatus() function.
type RenderEvent ¶
type RenderEvent struct { // LastWouldRender marks the last time the template would have rendered. LastWouldRender time.Time // LastDidRender marks the last time the template was written to disk. LastDidRender time.Time }
RenderEvent captures the time and events that occurred for a template rendering.
type RenderInput ¶
type RenderResult ¶
func Render ¶
func Render(i *RenderInput) (*RenderResult, error)
Render atomically renders a file contents to disk, returning a result of whether it would have rendered and actually did render.
type Runner ¶
type Runner struct { // ErrCh and DoneCh are channels where errors and finish notifications occur. ErrCh chan error DoneCh chan struct{} // Env represents a custom set of environment variables to populate the // template and command runtime with. These environment variables will be // available in both the command's environment as well as the template's // environment. Env map[string]string // contains filtered or unexported fields }
Runner responsible rendering Templates and invoking Commands.
func NewRunner ¶
NewRunner accepts a slice of TemplateConfigs and returns a pointer to the new Runner and any error that occurred during creation.
func (*Runner) Receive ¶
func (r *Runner) Receive(d dep.Dependency, data interface{})
Receive accepts a Dependency and data for that dep. This data is cached on the Runner. This data is then used to determine if a Template is "renderable" (i.e. all its Dependencies have been downloaded at least once).
func (*Runner) RenderEvents ¶
func (r *Runner) RenderEvents() map[string]*RenderEvent
RenderEvents returns the render events for each template was rendered. The map is keyed by template ID.
func (*Runner) Run ¶
Run iterates over each template in this Runner and conditionally executes the template rendering and command execution.
The template is rendered atomicly. If and only if the template render completes successfully, the optional commands will be executed, if given. Please note that all templates are rendered **and then** any commands are executed.
func (*Runner) Signal ¶
Signal sends a signal to the child process, if it exists. Any errors that occur are returned.
func (*Runner) Start ¶
func (r *Runner) Start()
Start begins the polling for this runner. Any errors that occur will cause this function to push an item onto the runner's error channel and the halt execution. This function is blocking and should be called as a goroutine.
func (*Runner) Stop ¶
func (r *Runner) Stop()
Stop halts the execution of this runner and its subprocesses.
func (*Runner) TemplateConfigMapping ¶
func (r *Runner) TemplateConfigMapping() map[string][]config.TemplateConfig
TemplateConfigMapping returns a mapping between the template ID and the set of TemplateConfig represented by the template ID
func (*Runner) TemplateRenderedCh ¶
func (r *Runner) TemplateRenderedCh() <-chan struct{}
TemplateRenderedCh returns a channel that will return the path of the template when it is rendered.