Skip to content

Commit

Permalink
Backport of client: fixed a problem calculating a service namespace. …
Browse files Browse the repository at this point in the history
…into release/1.3.x (#14265)

This pull request was automerged via backport-assistant
  • Loading branch information
hc-github-team-nomad-core committed Aug 23, 2022
1 parent d7f8031 commit 21d5267
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .changelog/13493.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
client: Fixed a problem calculating a services namespace
```
6 changes: 3 additions & 3 deletions nomad/structs/alloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ func (a *Allocation) ServiceProviderNamespace() string {
}
}

if len(tg.Tasks) > 0 {
if len(tg.Tasks[0].Services) > 0 {
switch tg.Tasks[0].Services[0].Provider {
for _, task := range tg.Tasks {
if len(task.Services) > 0 {
switch task.Services[0].Provider {
case ServiceProviderNomad:
return a.Job.Namespace
default:
Expand Down
28 changes: 28 additions & 0 deletions nomad/structs/alloc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,34 @@ func Test_Allocation_ServiceProviderNamespace(t *testing.T) {
expectedOutput: "platform",
name: "nomad task service",
},
{
inputAllocation: &Allocation{
Job: &Job{
Namespace: "platform",
TaskGroups: []*TaskGroup{
{
Name: "test-group",
Tasks: []*Task{
{
Name: "task1",
},
{
Name: "task2",
Services: []*Service{
{
Provider: ServiceProviderNomad,
},
},
},
},
},
},
},
TaskGroup: "test-group",
},
expectedOutput: "platform",
name: "multiple tasks with service not in first",
},
}

for _, tc := range testCases {
Expand Down

0 comments on commit 21d5267

Please sign in to comment.