command: use correct port mapping syntax in examples
This commit is contained in:
parent
d21cbeb30f
commit
c9bd7e89ca
|
@ -3,7 +3,9 @@ job "example" {
|
||||||
|
|
||||||
group "cache" {
|
group "cache" {
|
||||||
network {
|
network {
|
||||||
port "db" {}
|
port "db" {
|
||||||
|
to = 6379
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
task "redis" {
|
task "redis" {
|
||||||
|
|
|
@ -151,7 +151,9 @@ job "example" {
|
||||||
# https://www.nomadproject.io/docs/job-specification/network
|
# https://www.nomadproject.io/docs/job-specification/network
|
||||||
#
|
#
|
||||||
network {
|
network {
|
||||||
port "db" {}
|
port "db" {
|
||||||
|
to = 6379
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# The "service" stanza instructs Nomad to register this task as a service
|
# The "service" stanza instructs Nomad to register this task as a service
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1095,6 +1095,9 @@ func (d *Driver) createContainerConfig(task *drivers.TaskConfig, driverConfig *T
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if len(driverConfig.PortMap) > 0 {
|
if len(driverConfig.PortMap) > 0 {
|
||||||
|
if task.Resources.Ports != nil {
|
||||||
|
return c, fmt.Errorf("'port_map' cannot map group network ports, use 'ports' instead")
|
||||||
|
}
|
||||||
return c, fmt.Errorf("Trying to map ports but no network interface is available")
|
return c, fmt.Errorf("Trying to map ports but no network interface is available")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@ package drivers
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hashicorp/nomad/helper/uuid"
|
||||||
|
"github.com/hashicorp/nomad/nomad/structs"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -32,3 +34,72 @@ func TestResourceUsageRoundTrip(t *testing.T) {
|
||||||
|
|
||||||
require.EqualValues(t, parsed, input)
|
require.EqualValues(t, parsed, input)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTaskConfigRoundTrip(t *testing.T) {
|
||||||
|
|
||||||
|
input := &TaskConfig{
|
||||||
|
ID: uuid.Generate(),
|
||||||
|
Name: "task",
|
||||||
|
JobName: "job",
|
||||||
|
TaskGroupName: "group",
|
||||||
|
Resources: &Resources{
|
||||||
|
NomadResources: &structs.AllocatedTaskResources{
|
||||||
|
Cpu: structs.AllocatedCpuResources{
|
||||||
|
CpuShares: int64(100),
|
||||||
|
},
|
||||||
|
Memory: structs.AllocatedMemoryResources{
|
||||||
|
MemoryMB: int64(300),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
LinuxResources: &LinuxResources{
|
||||||
|
MemoryLimitBytes: 300 * 1024 * 1024,
|
||||||
|
CPUShares: 100,
|
||||||
|
PercentTicks: float64(100) / float64(3200),
|
||||||
|
},
|
||||||
|
Ports: &structs.AllocatedPorts{
|
||||||
|
{
|
||||||
|
Label: "port",
|
||||||
|
Value: 23456,
|
||||||
|
To: 8080,
|
||||||
|
HostIP: "10.0.0.1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Devices: []*DeviceConfig{
|
||||||
|
{
|
||||||
|
TaskPath: "task",
|
||||||
|
HostPath: "host",
|
||||||
|
Permissions: "perms",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Mounts: []*MountConfig{
|
||||||
|
{
|
||||||
|
TaskPath: "task",
|
||||||
|
HostPath: "host",
|
||||||
|
Readonly: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Env: map[string]string{"gir": "zim"},
|
||||||
|
DeviceEnv: map[string]string{"foo": "bar"},
|
||||||
|
User: "user",
|
||||||
|
AllocDir: "allocDir",
|
||||||
|
StdoutPath: "stdout",
|
||||||
|
StderrPath: "stderr",
|
||||||
|
AllocID: uuid.Generate(),
|
||||||
|
NetworkIsolation: &NetworkIsolationSpec{
|
||||||
|
Mode: NetIsolationModeGroup,
|
||||||
|
Path: "path",
|
||||||
|
Labels: map[string]string{"net": "abc"},
|
||||||
|
},
|
||||||
|
DNS: &DNSConfig{
|
||||||
|
Servers: []string{"8.8.8.8"},
|
||||||
|
Searches: []string{".consul"},
|
||||||
|
Options: []string{"ndots:2"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
parsed := taskConfigFromProto(taskConfigToProto(input))
|
||||||
|
|
||||||
|
require.EqualValues(t, input, parsed)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue