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 enable tag override master #5774

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ba2403c
remove generated code
preetapan Apr 22, 2019
7cc409e
Switch to pre-0.9 behaviour for handling volumes
endocrimes Apr 17, 2019
04916c0
open fifo on background goroutine
Apr 16, 2019
58362da
locking and opening streams in goroutine comment
Apr 16, 2019
6efb949
client: wait for batched driver updated
Apr 19, 2019
290f099
client: avoid registering node twice right away
Apr 19, 2019
f0cca2e
client: log detected driver health state
Apr 19, 2019
0e9c3cc
clarify cryptic log line
Apr 19, 2019
9154814
loggging: Attempt to recover logmon failures
endocrimes Apr 18, 2019
efb41a9
tweak logging level for failed log line
schmichael Apr 22, 2019
60f4e11
client/metrics: modified metrics to use (updated) client copy of allo…
Apr 10, 2019
d7bd239
0.9.1 changelog
preetapan Apr 22, 2019
7ea3f38
changelog: added entry for #5540 fix, and some missing left brackets
Apr 22, 2019
c97e4c6
changelog: fixed bad markdown
Apr 23, 2019
9a8617f
Revert "changelog: fixed bad markdown"
Apr 23, 2019
652b754
Revert "changelog: added entry for #5540 fix, and some missing left b…
Apr 23, 2019
3dfced8
changelog: fixed markdown formatting
Apr 23, 2019
13e51d7
fix crash when executor parent nomad process dies
Apr 23, 2019
3f491a6
update changelog with GH-5598
Apr 23, 2019
3e17899
Generate files for 0.9.1-rc1 release
hashicorp-nomad Apr 23, 2019
0010625
Release v0.9.1-rc1
schmichael Apr 23, 2019
290ed47
Remove Nomad 0.9.1-rc1 generated files
schmichael Apr 23, 2019
1cd7a78
Merge pull request #5609 from hashicorp/b-docker-tty-logs
Apr 25, 2019
7caa796
Merge pull request #5616 from hashicorp/b-retry-logmon-start-errs-2
Apr 26, 2019
4f52b1c
update changelog for GH-5609 and GH-5616
Apr 26, 2019
4b2bdbd
Generate files for 0.9.1 release
hashicorp-nomad Apr 29, 2019
23c4597
Release v0.9.1
schmichael Apr 29, 2019
04ac30e
added support for consul EnableTagOverride #2057
bogdanalbei May 31, 2019
df31ef7
fixed test #2057
bogdanalbei Jun 3, 2019
75191a4
Merge branch 'consul_enable_tag_override' of github.com:bogdanalbei/n…
bogdanalbei Jun 3, 2019
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
17 changes: 9 additions & 8 deletions api/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,14 +364,15 @@ type ServiceCheck struct {

// The Service model represents a Consul service definition
type Service struct {
Id string
Name string
Tags []string
CanaryTags []string `mapstructure:"canary_tags"`
PortLabel string `mapstructure:"port"`
AddressMode string `mapstructure:"address_mode"`
Checks []ServiceCheck
CheckRestart *CheckRestart `mapstructure:"check_restart"`
Id string
Name string
Tags []string
CanaryTags []string `mapstructure:"canary_tags"`
PortLabel string `mapstructure:"port"`
AddressMode string `mapstructure:"address_mode"`
Checks []ServiceCheck
CheckRestart *CheckRestart `mapstructure:"check_restart"`
EnableTagOverride bool
}

func (s *Service) Canonicalize(t *Task, tg *TaskGroup, job *Job) {
Expand Down
1 change: 1 addition & 0 deletions command/agent/consul/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,7 @@ func (c *ServiceClient) serviceRegs(ops *operations, service *structs.Service, t
Meta: map[string]string{
"external-source": "nomad",
},
EnableTagOverride: service.EnableTagOverride,
}
ops.regServices = append(ops.regServices, serviceReg)

Expand Down
30 changes: 30 additions & 0 deletions command/agent/consul/unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,36 @@ func TestConsul_CanaryTags_NoTags(t *testing.T) {
require.Len(ctx.FakeConsul.services, 0)
}

// TestConsul_EnableTagOverrideEnabled asserts EnableTagOverride is set when EnableTagOverride=true
func TestConsul_EnableTagOverrideEnabled(t *testing.T) {
t.Parallel()
require := require.New(t)
ctx := setupFake(t)

ctx.Task.Services[0].EnableTagOverride = true

require.NoError(ctx.ServiceClient.RegisterTask(ctx.Task))
require.NoError(ctx.syncOnce())
require.Len(ctx.FakeConsul.services, 1)
for _, service := range ctx.FakeConsul.services {
require.Equal(true, service.EnableTagOverride)
}
}

// TestConsul_EnableTagOverrideIsDisabledByDefault asserts EnableTagOverride is disabled by default
func TestConsul_EnableTagOverrideIsDisabledByDefault(t *testing.T) {
t.Parallel()
require := require.New(t)
ctx := setupFake(t)

require.NoError(ctx.ServiceClient.RegisterTask(ctx.Task))
require.NoError(ctx.syncOnce())
require.Len(ctx.FakeConsul.services, 1)
for _, service := range ctx.FakeConsul.services {
require.Equal(false, service.EnableTagOverride)
}
}

// TestConsul_PeriodicSync asserts that Nomad periodically reconciles with
// Consul.
func TestConsul_PeriodicSync(t *testing.T) {
Expand Down
11 changes: 6 additions & 5 deletions command/agent/job_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -763,11 +763,12 @@ func ApiTaskToStructsTask(apiTask *api.Task, structsTask *structs.Task) {
structsTask.Services = make([]*structs.Service, l)
for i, service := range apiTask.Services {
structsTask.Services[i] = &structs.Service{
Name: service.Name,
PortLabel: service.PortLabel,
Tags: service.Tags,
CanaryTags: service.CanaryTags,
AddressMode: service.AddressMode,
Name: service.Name,
PortLabel: service.PortLabel,
Tags: service.Tags,
CanaryTags: service.CanaryTags,
AddressMode: service.AddressMode,
EnableTagOverride: service.EnableTagOverride,
}

if l := len(service.Checks); l != 0 {
Expand Down
10 changes: 10 additions & 0 deletions command/agent/job_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1398,6 +1398,11 @@ func TestJobs_ApiJobToStructsJob(t *testing.T) {
},
},
},
{
Id: "id_serviceB",
Name: "serviceB",
EnableTagOverride: true,
},
},
Resources: &api.Resources{
CPU: helper.IntToPtr(100),
Expand Down Expand Up @@ -1698,6 +1703,11 @@ func TestJobs_ApiJobToStructsJob(t *testing.T) {
},
},
},
{
Name: "serviceB",
EnableTagOverride: true,
AddressMode: "auto",
},
},
Resources: &structs.Resources{
CPU: 100,
Expand Down
30 changes: 30 additions & 0 deletions nomad/structs/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3949,6 +3949,12 @@ func TestTaskDiff(t *testing.T) {
Type: DiffTypeAdded,
Name: "Service",
Fields: []*FieldDiff{
{
Type: DiffTypeAdded,
Name: "EnableTagOverride",
Old: "",
New: "false",
},
{
Type: DiffTypeAdded,
Name: "Name",
Expand All @@ -3967,6 +3973,12 @@ func TestTaskDiff(t *testing.T) {
Type: DiffTypeDeleted,
Name: "Service",
Fields: []*FieldDiff{
{
Type: DiffTypeDeleted,
Name: "EnableTagOverride",
Old: "false",
New: "",
},
{
Type: DiffTypeDeleted,
Name: "Name",
Expand Down Expand Up @@ -4016,6 +4028,12 @@ func TestTaskDiff(t *testing.T) {
Name: "AddressMode",
New: "driver",
},
{
Type: DiffTypeNone,
Name: "EnableTagOverride",
Old: "false",
New: "false",
},
{
Type: DiffTypeNone,
Name: "Name",
Expand Down Expand Up @@ -4113,6 +4131,12 @@ func TestTaskDiff(t *testing.T) {
Type: DiffTypeNone,
Name: "AddressMode",
},
{
Type: DiffTypeNone,
Name: "EnableTagOverride",
Old: "false",
New: "false",
},
{
Type: DiffTypeNone,
Name: "Name",
Expand Down Expand Up @@ -4447,6 +4471,12 @@ func TestTaskDiff(t *testing.T) {
Old: "",
New: "",
},
{
Type: DiffTypeNone,
Name: "EnableTagOverride",
Old: "false",
New: "false",
},
{
Type: DiffTypeNone,
Name: "Name",
Expand Down
7 changes: 4 additions & 3 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5113,9 +5113,10 @@ type Service struct {
// this service.
AddressMode string

Tags []string // List of tags for the service
CanaryTags []string // List of tags for the service when it is a canary
Checks []*ServiceCheck // List of checks associated with the service
Tags []string // List of tags for the service
CanaryTags []string // List of tags for the service when it is a canary
Checks []*ServiceCheck // List of checks associated with the service
EnableTagOverride bool // Allow external agents to change the tags for a service
}

func (s *Service) Copy() *Service {
Expand Down