From a393ea79e8ab437ac2698623b848222b47b938ba Mon Sep 17 00:00:00 2001 From: Preetha Appan <460133+preetapan@users.noreply.github.com> Date: Wed, 7 Aug 2019 18:43:36 -0500 Subject: [PATCH] Add field "kind" to task for use in connect tasks --- api/tasks.go | 1 + command/agent/job_endpoint.go | 1 + jobspec/parse.go | 1 + jobspec/parse_test.go | 1 + jobspec/test-fixtures/basic.hcl | 1 + nomad/structs/structs.go | 4 ++++ 6 files changed, 9 insertions(+) diff --git a/api/tasks.go b/api/tasks.go index f401922e9..f12f761e7 100644 --- a/api/tasks.go +++ b/api/tasks.go @@ -583,6 +583,7 @@ type Task struct { Leader bool ShutdownDelay time.Duration `mapstructure:"shutdown_delay"` KillSignal string `mapstructure:"kill_signal"` + Kind string } func (t *Task) Canonicalize(tg *TaskGroup, job *Job) { diff --git a/command/agent/job_endpoint.go b/command/agent/job_endpoint.go index 362395f66..d05083bb9 100644 --- a/command/agent/job_endpoint.go +++ b/command/agent/job_endpoint.go @@ -784,6 +784,7 @@ func ApiTaskToStructsTask(apiTask *api.Task, structsTask *structs.Task) { structsTask.KillTimeout = *apiTask.KillTimeout structsTask.ShutdownDelay = apiTask.ShutdownDelay structsTask.KillSignal = apiTask.KillSignal + structsTask.Kind = apiTask.Kind structsTask.Constraints = ApiConstraintsToStructs(apiTask.Constraints) structsTask.Affinities = ApiAffinitiesToStructs(apiTask.Affinities) diff --git a/jobspec/parse.go b/jobspec/parse.go index f8d4aa341..3c6ce4329 100644 --- a/jobspec/parse.go +++ b/jobspec/parse.go @@ -892,6 +892,7 @@ func parseTasks(jobName string, taskGroupName string, result *[]*api.Task, list "user", "vault", "kill_signal", + "kind", } if err := helper.CheckHCLKeys(listVal, valid); err != nil { return multierror.Prefix(err, fmt.Sprintf("'%s' ->", n)) diff --git a/jobspec/parse_test.go b/jobspec/parse_test.go index 164da424b..0f10e7fd0 100644 --- a/jobspec/parse_test.go +++ b/jobspec/parse_test.go @@ -178,6 +178,7 @@ func TestParse(t *testing.T) { Name: "binstore", Driver: "docker", User: "bob", + Kind: "connect-proxy:test", Config: map[string]interface{}{ "image": "hashicorp/binstore", "labels": []map[string]interface{}{ diff --git a/jobspec/test-fixtures/basic.hcl b/jobspec/test-fixtures/basic.hcl index 8c0f0aaca..535895a68 100644 --- a/jobspec/test-fixtures/basic.hcl +++ b/jobspec/test-fixtures/basic.hcl @@ -126,6 +126,7 @@ job "binstore-storagelocker" { driver = "docker" user = "bob" leader = true + kind = "connect-proxy:test" affinity { attribute = "${meta.foo}" diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 0576028bd..c663703aa 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -5142,6 +5142,10 @@ type Task struct { // KillSignal is the kill signal to use for the task. This is an optional // specification and defaults to SIGINT KillSignal string + + // Used internally to manage tasks according to their Kind. Initial use case + // is for Consul Connect + Kind string } func (t *Task) Copy() *Task {