mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 10:25:42 +03:00
Use Tags when CanaryTags isn't specified
This PR fixes a bug where we weren't defaulting to `tags` when `canary_tags` was empty and adds documentation.
This commit is contained in:
@@ -626,7 +626,7 @@ func (c *ServiceClient) serviceRegs(ops *operations, service *structs.Service, t
|
||||
|
||||
// Determine whether to use tags or canary_tags
|
||||
var tags []string
|
||||
if task.Canary {
|
||||
if task.Canary && len(service.CanaryTags) > 0 {
|
||||
tags = make([]string, len(service.CanaryTags))
|
||||
copy(tags, service.CanaryTags)
|
||||
} else {
|
||||
|
||||
@@ -1369,6 +1369,39 @@ func TestConsul_CanaryTags(t *testing.T) {
|
||||
require.Len(ctx.FakeConsul.services, 0)
|
||||
}
|
||||
|
||||
// TestConsul_CanaryTags_NoTags asserts Tags are used when Canary=true and there
|
||||
// are no specified canary tags
|
||||
func TestConsul_CanaryTags_NoTags(t *testing.T) {
|
||||
t.Parallel()
|
||||
require := require.New(t)
|
||||
ctx := setupFake(t)
|
||||
|
||||
tags := []string{"tag1", "foo"}
|
||||
ctx.Task.Canary = true
|
||||
ctx.Task.Services[0].Tags = tags
|
||||
|
||||
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(tags, service.Tags)
|
||||
}
|
||||
|
||||
// Disable canary and assert tags dont change
|
||||
origTask := ctx.Task.Copy()
|
||||
ctx.Task.Canary = false
|
||||
require.NoError(ctx.ServiceClient.UpdateTask(origTask, ctx.Task))
|
||||
require.NoError(ctx.syncOnce())
|
||||
require.Len(ctx.FakeConsul.services, 1)
|
||||
for _, service := range ctx.FakeConsul.services {
|
||||
require.Equal(tags, service.Tags)
|
||||
}
|
||||
|
||||
ctx.ServiceClient.RemoveTask(ctx.Task)
|
||||
require.NoError(ctx.syncOnce())
|
||||
require.Len(ctx.FakeConsul.services, 0)
|
||||
}
|
||||
|
||||
// TestConsul_PeriodicSync asserts that Nomad periodically reconciles with
|
||||
// Consul.
|
||||
func TestConsul_PeriodicSync(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user