-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
job: add native service discovery job constraint mutator.
- Loading branch information
Showing
4 changed files
with
385 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
package nomad | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/nomad/nomad/structs" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_jobImpliedConstraints_Mutate(t *testing.T) { | ||
t.Parallel() | ||
|
||
testCases := []struct { | ||
inputJob *structs.Job | ||
expectedOutputJob *structs.Job | ||
expectedOutputWarnings []error | ||
expectedOutputError error | ||
name string | ||
}{ | ||
{ | ||
inputJob: &structs.Job{ | ||
Name: "example", | ||
TaskGroups: []*structs.TaskGroup{ | ||
{ | ||
Name: "example-group-1", | ||
}, | ||
}, | ||
}, | ||
expectedOutputJob: &structs.Job{ | ||
Name: "example", | ||
TaskGroups: []*structs.TaskGroup{ | ||
{ | ||
Name: "example-group-1", | ||
}, | ||
}, | ||
}, | ||
expectedOutputWarnings: nil, | ||
expectedOutputError: nil, | ||
name: "no needed constraints", | ||
}, | ||
{ | ||
inputJob: &structs.Job{ | ||
Name: "example", | ||
TaskGroups: []*structs.TaskGroup{ | ||
{ | ||
Name: "example-group-1", | ||
Services: []*structs.Service{ | ||
{ | ||
Name: "example-group-service-1", | ||
Provider: structs.ServiceProviderNomad, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
expectedOutputJob: &structs.Job{ | ||
Name: "example", | ||
TaskGroups: []*structs.TaskGroup{ | ||
{ | ||
Name: "example-group-1", | ||
Services: []*structs.Service{ | ||
{ | ||
Name: "example-group-service-1", | ||
Provider: structs.ServiceProviderNomad, | ||
}, | ||
}, | ||
Constraints: []*structs.Constraint{nativeServiceDiscoveryConstraint}, | ||
}, | ||
}, | ||
}, | ||
expectedOutputWarnings: nil, | ||
expectedOutputError: nil, | ||
name: "task group nomad discovery", | ||
}, | ||
{ | ||
inputJob: &structs.Job{ | ||
Name: "example", | ||
TaskGroups: []*structs.TaskGroup{ | ||
{ | ||
Name: "example-group-1", | ||
Services: []*structs.Service{ | ||
{ | ||
Name: "example-group-service-1", | ||
Provider: structs.ServiceProviderNomad, | ||
}, | ||
}, | ||
Constraints: []*structs.Constraint{nativeServiceDiscoveryConstraint}, | ||
}, | ||
}, | ||
}, | ||
expectedOutputJob: &structs.Job{ | ||
Name: "example", | ||
TaskGroups: []*structs.TaskGroup{ | ||
{ | ||
Name: "example-group-1", | ||
Services: []*structs.Service{ | ||
{ | ||
Name: "example-group-service-1", | ||
Provider: structs.ServiceProviderNomad, | ||
}, | ||
}, | ||
Constraints: []*structs.Constraint{nativeServiceDiscoveryConstraint}, | ||
}, | ||
}, | ||
}, | ||
expectedOutputWarnings: nil, | ||
expectedOutputError: nil, | ||
name: "task group nomad discovery constraint found", | ||
}, | ||
{ | ||
inputJob: &structs.Job{ | ||
Name: "example", | ||
TaskGroups: []*structs.TaskGroup{ | ||
{ | ||
Name: "example-group-1", | ||
Services: []*structs.Service{ | ||
{ | ||
Name: "example-group-service-1", | ||
Provider: structs.ServiceProviderNomad, | ||
}, | ||
}, | ||
Constraints: []*structs.Constraint{ | ||
{ | ||
LTarget: "${node.class}", | ||
RTarget: "high-memory", | ||
Operand: "=", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
expectedOutputJob: &structs.Job{ | ||
Name: "example", | ||
TaskGroups: []*structs.TaskGroup{ | ||
{ | ||
Name: "example-group-1", | ||
Services: []*structs.Service{ | ||
{ | ||
Name: "example-group-service-1", | ||
Provider: structs.ServiceProviderNomad, | ||
}, | ||
}, | ||
Constraints: []*structs.Constraint{ | ||
{ | ||
LTarget: "${node.class}", | ||
RTarget: "high-memory", | ||
Operand: "=", | ||
}, | ||
nativeServiceDiscoveryConstraint, | ||
}, | ||
}, | ||
}, | ||
}, | ||
expectedOutputWarnings: nil, | ||
expectedOutputError: nil, | ||
name: "task group nomad discovery other constraints", | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
impl := jobImpliedConstraints{} | ||
actualJob, actualWarnings, actualError := impl.Mutate(tc.inputJob) | ||
require.Equal(t, tc.expectedOutputJob, actualJob) | ||
require.ElementsMatch(t, tc.expectedOutputWarnings, actualWarnings) | ||
require.Equal(t, tc.expectedOutputError, actualError) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.