diff --git a/client/taskenv/env.go b/client/taskenv/env.go index 5b42a17a7533..4b40ff68e43d 100644 --- a/client/taskenv/env.go +++ b/client/taskenv/env.go @@ -57,6 +57,9 @@ const ( // Datacenter is the environment variable for passing the datacenter in which the alloc is running. Datacenter = "NOMAD_DC" + // Namespace is the environment variable for passing the namespace in which the alloc is running. + Namespace = "NOMAD_NAMESPACE" + // Region is the environment variable for passing the region in which the alloc is running. Region = "NOMAD_REGION" @@ -303,6 +306,7 @@ type Builder struct { taskName string allocIndex int datacenter string + namespace string region string allocId string allocName string @@ -407,6 +411,9 @@ func (b *Builder) Build() *TaskEnv { if b.datacenter != "" { envMap[Datacenter] = b.datacenter } + if b.namespace != "" { + envMap[Namespace] = b.namespace + } if b.region != "" { envMap[Region] = b.region @@ -559,6 +566,7 @@ func (b *Builder) setAlloc(alloc *structs.Allocation) *Builder { b.groupName = alloc.TaskGroup b.allocIndex = int(alloc.Index()) b.jobName = alloc.Job.Name + b.namespace = alloc.Namespace // Set meta combined := alloc.Job.CombinedTaskMeta(alloc.TaskGroup, b.taskName) diff --git a/client/taskenv/env_test.go b/client/taskenv/env_test.go index 531d8f168400..1da4c1725eaf 100644 --- a/client/taskenv/env_test.go +++ b/client/taskenv/env_test.go @@ -190,6 +190,7 @@ func TestEnvironment_AsList(t *testing.T) { "NOMAD_PORT_ssh_ssh=22", "NOMAD_CPU_LIMIT=500", "NOMAD_DC=dc1", + "NOMAD_NAMESPACE=default", "NOMAD_REGION=global", "NOMAD_MEMORY_LIMIT=256", "NOMAD_META_ELB_CHECK_INTERVAL=30s", @@ -301,6 +302,7 @@ func TestEnvironment_AsList_Old(t *testing.T) { "NOMAD_PORT_ssh_ssh=22", "NOMAD_CPU_LIMIT=500", "NOMAD_DC=dc1", + "NOMAD_NAMESPACE=default", "NOMAD_REGION=global", "NOMAD_MEMORY_LIMIT=256", "NOMAD_META_ELB_CHECK_INTERVAL=30s", @@ -418,6 +420,7 @@ func TestEnvironment_AllValues(t *testing.T) { "NOMAD_PORT_ssh_ssh": "22", "NOMAD_CPU_LIMIT": "500", "NOMAD_DC": "dc1", + "NOMAD_NAMESPACE": "default", "NOMAD_REGION": "global", "NOMAD_MEMORY_LIMIT": "256", "NOMAD_META_ELB_CHECK_INTERVAL": "30s",