Skip to content

Commit

Permalink
api: add service block provider parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrasell committed Mar 4, 2022
1 parent 4a25718 commit 5e1e85c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/jobs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,7 @@ func TestJobs_Canonicalize(t *testing.T) {
PortLabel: "db",
AddressMode: "auto",
OnUpdate: "require_healthy",
Provider: "consul",
Checks: []ServiceCheck{
{
Name: "alive",
Expand Down
14 changes: 14 additions & 0 deletions api/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,21 @@ type Service struct {
CanaryMeta map[string]string `hcl:"canary_meta,block"`
TaskName string `mapstructure:"task" hcl:"task,optional"`
OnUpdate string `mapstructure:"on_update" hcl:"on_update,optional"`

// Provider defines which backend system provides the service registration
// mechanism for this service. This supports either structs.ProviderConsul
// or structs.ProviderNomad and defaults for the former.
Provider string `hcl:"provider,optional"`
}

const (
OnUpdateRequireHealthy = "require_healthy"
OnUpdateIgnoreWarn = "ignore_warnings"
OnUpdateIgnore = "ignore"

// ServiceProviderConsul is the default provider for services when no
// parameter is set.
ServiceProviderConsul = "consul"
)

// Canonicalize the Service by ensuring its name and address mode are set. Task
Expand All @@ -145,6 +154,11 @@ func (s *Service) Canonicalize(t *Task, tg *TaskGroup, job *Job) {
s.OnUpdate = OnUpdateRequireHealthy
}

// Default the service provider.
if s.Provider == "" {
s.Provider = ServiceProviderConsul
}

s.Connect.Canonicalize()

// Canonicalize CheckRestart on Checks and merge Service.CheckRestart
Expand Down
1 change: 1 addition & 0 deletions api/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func TestService_Canonicalize(t *testing.T) {
require.Equal(t, fmt.Sprintf("%s-%s-%s", *j.Name, *tg.Name, task.Name), s.Name)
require.Equal(t, "auto", s.AddressMode)
require.Equal(t, OnUpdateRequireHealthy, s.OnUpdate)
require.Equal(t, ServiceProviderConsul, s.Provider)
}

func TestServiceCheck_Canonicalize(t *testing.T) {
Expand Down

0 comments on commit 5e1e85c

Please sign in to comment.