Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consul template manager #1783

Merged
merged 6 commits into from
Oct 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
446 changes: 446 additions & 0 deletions client/consul_template.go

Large diffs are not rendered by default.

699 changes: 699 additions & 0 deletions client/consul_template_test.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion jobspec/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ func parseTemplates(result *[]*structs.Template, list *ast.ObjectList) error {
"destination",
"data",
"change_mode",
"restart_signal",
"change_signal",
"splay",
"once",
}
Expand Down
22 changes: 10 additions & 12 deletions jobspec/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,18 @@ func TestParse(t *testing.T) {
},
Templates: []*structs.Template{
{
SourcePath: "foo",
DestPath: "foo",
ChangeMode: "foo",
RestartSignal: "foo",
Splay: 10 * time.Second,
Once: true,
SourcePath: "foo",
DestPath: "foo",
ChangeMode: "foo",
ChangeSignal: "foo",
Splay: 10 * time.Second,
},
{
SourcePath: "bar",
DestPath: "bar",
ChangeMode: structs.TemplateChangeModeRestart,
RestartSignal: "",
Splay: 5 * time.Second,
Once: false,
SourcePath: "bar",
DestPath: "bar",
ChangeMode: structs.TemplateChangeModeRestart,
ChangeSignal: "",
Splay: 5 * time.Second,
},
},
},
Expand Down
3 changes: 1 addition & 2 deletions jobspec/test-fixtures/basic.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,8 @@ job "binstore-storagelocker" {
source = "foo"
destination = "foo"
change_mode = "foo"
restart_signal = "foo"
change_signal = "foo"
splay = "10s"
once = true
}

template {
Expand Down
56 changes: 26 additions & 30 deletions nomad/structs/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3208,44 +3208,40 @@ func TestTaskDiff(t *testing.T) {
Old: &Task{
Templates: []*Template{
{
SourcePath: "foo",
DestPath: "bar",
EmbededTmpl: "baz",
ChangeMode: "bam",
RestartSignal: "SIGHUP",
Splay: 1,
Once: true,
SourcePath: "foo",
DestPath: "bar",
EmbeddedTmpl: "baz",
ChangeMode: "bam",
ChangeSignal: "SIGHUP",
Splay: 1,
},
{
SourcePath: "foo2",
DestPath: "bar2",
EmbededTmpl: "baz2",
ChangeMode: "bam2",
RestartSignal: "SIGHUP2",
Splay: 2,
Once: false,
SourcePath: "foo2",
DestPath: "bar2",
EmbeddedTmpl: "baz2",
ChangeMode: "bam2",
ChangeSignal: "SIGHUP2",
Splay: 2,
},
},
},
New: &Task{
Templates: []*Template{
{
SourcePath: "foo",
DestPath: "bar",
EmbededTmpl: "baz",
ChangeMode: "bam",
RestartSignal: "SIGHUP",
Splay: 1,
Once: true,
},
{
SourcePath: "foo3",
DestPath: "bar3",
EmbededTmpl: "baz3",
ChangeMode: "bam3",
RestartSignal: "SIGHUP3",
Splay: 3,
Once: true,
SourcePath: "foo",
DestPath: "bar",
EmbeddedTmpl: "baz",
ChangeMode: "bam",
ChangeSignal: "SIGHUP",
Splay: 1,
},
{
SourcePath: "foo3",
DestPath: "bar3",
EmbeddedTmpl: "baz3",
ChangeMode: "bam3",
ChangeSignal: "SIGHUP3",
Splay: 3,
},
},
},
Expand Down
20 changes: 8 additions & 12 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1753,12 +1753,12 @@ func (sc *ServiceCheck) validate() error {

switch sc.InitialStatus {
case "":
case api.HealthUnknown:
// case api.HealthUnknown: TODO: Add when Consul releases 0.7.1
case api.HealthPassing:
case api.HealthWarning:
case api.HealthCritical:
default:
return fmt.Errorf(`invalid initial check state (%s), must be one of %q, %q, %q, %q or empty`, sc.InitialStatus, api.HealthUnknown, api.HealthPassing, api.HealthWarning, api.HealthCritical)
return fmt.Errorf(`invalid initial check state (%s), must be one of %q, %q, %q, %q or empty`, sc.InitialStatus, api.HealthPassing, api.HealthWarning, api.HealthCritical)

}

Expand Down Expand Up @@ -2222,32 +2222,28 @@ type Template struct {
// DestPath is the path to where the template should be rendered
DestPath string `mapstructure:"destination"`

// EmbededTmpl store the raw template. This is useful for smaller templates
// EmbeddedTmpl store the raw template. This is useful for smaller templates
// where they are embeded in the job file rather than sent as an artificat
EmbededTmpl string `mapstructure:"data"`
EmbeddedTmpl string `mapstructure:"data"`

// ChangeMode indicates what should be done if the template is re-rendered
ChangeMode string `mapstructure:"change_mode"`

// RestartSignal is the signal that should be sent if the change mode
// ChangeSignal is the signal that should be sent if the change mode
// requires it.
RestartSignal string `mapstructure:"restart_signal"`
ChangeSignal string `mapstructure:"change_signal"`

// Splay is used to avoid coordinated restarts of processes by applying a
// random wait between 0 and the given splay value before signalling the
// application of a change
Splay time.Duration `mapstructure:"splay"`

// Once mode is used to indicate that template should be rendered only once
Once bool `mapstructure:"once"`
}

// DefaultTemplate returns a default template.
func DefaultTemplate() *Template {
return &Template{
ChangeMode: TemplateChangeModeRestart,
Splay: 5 * time.Second,
Once: false,
}
}

Expand All @@ -2264,7 +2260,7 @@ func (t *Template) Validate() error {
var mErr multierror.Error

// Verify we have something to render
if t.SourcePath == "" && t.EmbededTmpl == "" {
if t.SourcePath == "" && t.EmbeddedTmpl == "" {
multierror.Append(&mErr, fmt.Errorf("Must specify a source path or have an embeded template"))
}

Expand All @@ -2285,7 +2281,7 @@ func (t *Template) Validate() error {
switch t.ChangeMode {
case TemplateChangeModeNoop, TemplateChangeModeRestart:
case TemplateChangeModeSignal:
if t.RestartSignal == "" {
if t.ChangeSignal == "" {
multierror.Append(&mErr, fmt.Errorf("Must specify signal value when change mode is signal"))
}
default:
Expand Down
2 changes: 1 addition & 1 deletion scripts/install_consul.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -ex

CONSUL_VERSION="0.6.4"
CONSUL_VERSION="0.7.0"
CURDIR=`pwd`

echo Fetching Consul...
Expand Down
2 changes: 1 addition & 1 deletion scripts/install_vault.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -ex

VAULT_VERSION="0.6.1"
VAULT_VERSION="0.6.2"
CURDIR=`pwd`

echo Fetching Vault ${VAULT_VERSION}...
Expand Down
3 changes: 3 additions & 0 deletions vendor/github.com/burntsushi/toml/COMPATIBLE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions vendor/github.com/burntsushi/toml/COPYING

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions vendor/github.com/burntsushi/toml/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading