command: remove task network usage from init examples
This commit is contained in:
parent
9471892df4
commit
d21cbeb30f
|
@ -3,9 +3,7 @@ job "example" {
|
|||
|
||||
group "cache" {
|
||||
network {
|
||||
port "db" {
|
||||
to = 6379
|
||||
}
|
||||
port "db" {}
|
||||
}
|
||||
|
||||
task "redis" {
|
||||
|
|
|
@ -151,9 +151,7 @@ job "example" {
|
|||
# https://www.nomadproject.io/docs/job-specification/network
|
||||
#
|
||||
network {
|
||||
port "db" {
|
||||
to = 6379
|
||||
}
|
||||
port "db" {}
|
||||
}
|
||||
|
||||
# The "service" stanza instructs Nomad to register this task as a service
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -357,6 +357,19 @@ func testJob() *Job {
|
|||
Delay: 5 * time.Second,
|
||||
DelayFunction: "constant",
|
||||
},
|
||||
Networks: []*NetworkResource{
|
||||
{
|
||||
DynamicPorts: []Port{
|
||||
{Label: "http"},
|
||||
},
|
||||
},
|
||||
},
|
||||
Services: []*Service{
|
||||
{
|
||||
Name: "${TASK}-frontend",
|
||||
PortLabel: "http",
|
||||
},
|
||||
},
|
||||
Tasks: []*Task{
|
||||
{
|
||||
Name: "web",
|
||||
|
@ -372,21 +385,9 @@ func testJob() *Job {
|
|||
GetterSource: "http://foo.com",
|
||||
},
|
||||
},
|
||||
Services: []*Service{
|
||||
{
|
||||
Name: "${TASK}-frontend",
|
||||
PortLabel: "http",
|
||||
},
|
||||
},
|
||||
Resources: &Resources{
|
||||
CPU: 500,
|
||||
MemoryMB: 256,
|
||||
Networks: []*NetworkResource{
|
||||
{
|
||||
MBits: 50,
|
||||
DynamicPorts: []Port{{Label: "http"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
LogConfig: &LogConfig{
|
||||
MaxFiles: 10,
|
||||
|
|
|
@ -89,18 +89,16 @@ func TestServiceSched_JobRegister(t *testing.T) {
|
|||
// Ensure different ports were used.
|
||||
used := make(map[int]map[string]struct{})
|
||||
for _, alloc := range out {
|
||||
for _, resource := range alloc.TaskResources {
|
||||
for _, port := range resource.Networks[0].DynamicPorts {
|
||||
nodeMap, ok := used[port.Value]
|
||||
if !ok {
|
||||
nodeMap = make(map[string]struct{})
|
||||
used[port.Value] = nodeMap
|
||||
}
|
||||
if _, ok := nodeMap[alloc.NodeID]; ok {
|
||||
t.Fatalf("Port collision on node %q %v", alloc.NodeID, port.Value)
|
||||
}
|
||||
nodeMap[alloc.NodeID] = struct{}{}
|
||||
for _, port := range alloc.AllocatedResources.Shared.Ports {
|
||||
nodeMap, ok := used[port.Value]
|
||||
if !ok {
|
||||
nodeMap = make(map[string]struct{})
|
||||
used[port.Value] = nodeMap
|
||||
}
|
||||
if _, ok := nodeMap[alloc.NodeID]; ok {
|
||||
t.Fatalf("Port collision on node %q %v", alloc.NodeID, port.Value)
|
||||
}
|
||||
nodeMap[alloc.NodeID] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5230,20 +5228,20 @@ func TestServiceSched_Preemption(t *testing.T) {
|
|||
// Create a couple of jobs and schedule them
|
||||
job1 := mock.Job()
|
||||
job1.TaskGroups[0].Count = 1
|
||||
job1.TaskGroups[0].Networks = nil
|
||||
job1.Priority = 30
|
||||
r1 := job1.TaskGroups[0].Tasks[0].Resources
|
||||
r1.CPU = 500
|
||||
r1.MemoryMB = 1024
|
||||
r1.Networks = nil
|
||||
require.NoError(h.State.UpsertJob(structs.MsgTypeTestSetup, h.NextIndex(), job1))
|
||||
|
||||
job2 := mock.Job()
|
||||
job2.TaskGroups[0].Count = 1
|
||||
job2.TaskGroups[0].Networks = nil
|
||||
job2.Priority = 50
|
||||
r2 := job2.TaskGroups[0].Tasks[0].Resources
|
||||
r2.CPU = 350
|
||||
r2.MemoryMB = 512
|
||||
r2.Networks = nil
|
||||
require.NoError(h.State.UpsertJob(structs.MsgTypeTestSetup, h.NextIndex(), job2))
|
||||
|
||||
// Create a mock evaluation to register the jobs
|
||||
|
@ -5294,10 +5292,10 @@ func TestServiceSched_Preemption(t *testing.T) {
|
|||
job3 := mock.Job()
|
||||
job3.Priority = 100
|
||||
job3.TaskGroups[0].Count = 1
|
||||
job3.TaskGroups[0].Networks = nil
|
||||
r3 := job3.TaskGroups[0].Tasks[0].Resources
|
||||
r3.CPU = 900
|
||||
r3.MemoryMB = 1700
|
||||
r3.Networks = nil
|
||||
require.NoError(h.State.UpsertJob(structs.MsgTypeTestSetup, h.NextIndex(), job3))
|
||||
|
||||
// Create a mock evaluation to register the job
|
||||
|
|
|
@ -599,7 +599,7 @@ func TestTasksUpdated(t *testing.T) {
|
|||
require.True(t, tasksUpdated(j1, j5, name))
|
||||
|
||||
j6 := mock.Job()
|
||||
j6.TaskGroups[0].Tasks[0].Resources.Networks[0].DynamicPorts = []structs.Port{
|
||||
j6.TaskGroups[0].Networks[0].DynamicPorts = []structs.Port{
|
||||
{Label: "http", Value: 0},
|
||||
{Label: "https", Value: 0},
|
||||
{Label: "admin", Value: 0},
|
||||
|
@ -646,16 +646,12 @@ func TestTasksUpdated(t *testing.T) {
|
|||
}
|
||||
require.True(t, tasksUpdated(j11d1, j11d2, name))
|
||||
|
||||
j12 := mock.Job()
|
||||
j12.TaskGroups[0].Tasks[0].Resources.Networks[0].MBits = 100
|
||||
require.True(t, tasksUpdated(j1, j12, name))
|
||||
|
||||
j13 := mock.Job()
|
||||
j13.TaskGroups[0].Tasks[0].Resources.Networks[0].DynamicPorts[0].Label = "foobar"
|
||||
j13.TaskGroups[0].Networks[0].DynamicPorts[0].Label = "foobar"
|
||||
require.True(t, tasksUpdated(j1, j13, name))
|
||||
|
||||
j14 := mock.Job()
|
||||
j14.TaskGroups[0].Tasks[0].Resources.Networks[0].ReservedPorts = []structs.Port{{Label: "foo", Value: 1312}}
|
||||
j14.TaskGroups[0].Networks[0].ReservedPorts = []structs.Port{{Label: "foo", Value: 1312}}
|
||||
require.True(t, tasksUpdated(j1, j14, name))
|
||||
|
||||
j15 := mock.Job()
|
||||
|
@ -678,12 +674,8 @@ func TestTasksUpdated(t *testing.T) {
|
|||
|
||||
// Change network mode
|
||||
j19 := mock.Job()
|
||||
j19.TaskGroups[0].Networks = j19.TaskGroups[0].Tasks[0].Resources.Networks
|
||||
j19.TaskGroups[0].Tasks[0].Resources.Networks = nil
|
||||
|
||||
j20 := mock.Job()
|
||||
j20.TaskGroups[0].Networks = j20.TaskGroups[0].Tasks[0].Resources.Networks
|
||||
j20.TaskGroups[0].Tasks[0].Resources.Networks = nil
|
||||
|
||||
require.False(t, tasksUpdated(j19, j20, name))
|
||||
|
||||
|
|
Loading…
Reference in New Issue