Commit f8aabc8b authored by Nick Ethier's avatar Nick Ethier Committed by Seth Hoenig
Browse files

command: use correct port mapping syntax in examples

parent 1c14f698
Showing with 84 additions and 6 deletions
+84 -6
......@@ -3,7 +3,9 @@ job "example" {
group "cache" {
network {
port "db" {}
port "db" {
to = 6379
}
}
task "redis" {
......
......@@ -151,7 +151,9 @@ job "example" {
# https://www.nomadproject.io/docs/job-specification/network
#
network {
port "db" {}
port "db" {
to = 6379
}
}
# The "service" stanza instructs Nomad to register this task as a service
......
This diff is collapsed.
......@@ -1095,6 +1095,9 @@ func (d *Driver) createContainerConfig(task *drivers.TaskConfig, driverConfig *T
default:
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")
}
}
......
......@@ -3,6 +3,8 @@ package drivers
import (
"testing"
"github.com/hashicorp/nomad/helper/uuid"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/stretchr/testify/require"
)
......@@ -32,3 +34,72 @@ func TestResourceUsageRoundTrip(t *testing.T) {
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)
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment