Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added named ports #83

Merged
merged 3 commits into from
Sep 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/executor/exec_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var (
Networks: []*structs.NetworkResource{
&structs.NetworkResource{
MBits: 50,
DynamicPorts: 1,
DynamicPorts: []string{"http"},
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion jobspec/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func TestParse(t *testing.T) {
&structs.NetworkResource{
MBits: 100,
ReservedPorts: []int{1, 2, 3},
DynamicPorts: 3,
DynamicPorts: []string{"http", "https", "admin"},
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion jobspec/test-fixtures/basic.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ job "binstore-storagelocker" {
network {
mbits = "100"
reserved_ports = [1,2,3]
dynamic_ports = 3
dynamic_ports = ["http", "https", "admin"]
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions jobspec/test-fixtures/multi-network.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ job "binstore-storagelocker" {
network {
mbits = "100"
reserved_ports = [1,2,3]
dynamic_ports = 3
dynamic_ports = ["http", "https", "admin"]
}

network {
mbits = "128"
reserved_ports = [1,2,3]
dynamic_ports = 3
dynamic_ports = ["http", "https", "admin"]
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions nomad/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func Job() *structs.Job {
Networks: []*structs.NetworkResource{
&structs.NetworkResource{
MBits: 50,
DynamicPorts: 1,
DynamicPorts: []string{"http"},
},
},
},
Expand Down Expand Up @@ -135,7 +135,7 @@ func Alloc() *structs.Allocation {
IP: "192.168.0.100",
ReservedPorts: []int{12345},
MBits: 100,
DynamicPorts: 1,
DynamicPorts: []string{"http"},
},
},
},
Expand All @@ -149,7 +149,7 @@ func Alloc() *structs.Allocation {
IP: "192.168.0.100",
ReservedPorts: []int{5000},
MBits: 50,
DynamicPorts: 1,
DynamicPorts: []string{"http"},
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion nomad/structs/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (idx *NetworkIndex) AssignNetwork(ask *NetworkResource) (out *NetworkResour
}

// Check if we need to generate any ports
for i := 0; i < ask.DynamicPorts; i++ {
for i := 0; i < len(ask.DynamicPorts); i++ {
attempts := 0
PICK:
attempts++
Expand Down
4 changes: 2 additions & 2 deletions nomad/structs/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func TestNetworkIndex_AssignNetwork(t *testing.T) {

// Ask for dynamic ports
ask = &NetworkResource{
DynamicPorts: 3,
DynamicPorts: []string{"http", "https", "admin"},
}
offer, err = idx.AssignNetwork(ask)
if err != nil {
Expand All @@ -306,7 +306,7 @@ func TestNetworkIndex_AssignNetwork(t *testing.T) {
// Ask for reserved + dynamic ports
ask = &NetworkResource{
ReservedPorts: []int{12345},
DynamicPorts: 3,
DynamicPorts: []string{"http", "https", "admin"},
}
offer, err = idx.AssignNetwork(ask)
if err != nil {
Expand Down
14 changes: 7 additions & 7 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,12 +612,12 @@ func (r *Resources) GoString() string {
// NetworkResource is used to represesent available network
// resources
type NetworkResource struct {
Device string // Name of the device
CIDR string // CIDR block of addresses
IP string // IP address
MBits int // Throughput
ReservedPorts []int `mapstructure:"reserved_ports"` // Reserved ports
DynamicPorts int `mapstructure:"dynamic_ports"` // Dynamically assigned ports
Device string // Name of the device
CIDR string // CIDR block of addresses
IP string // IP address
MBits int // Throughput
ReservedPorts []int `mapstructure:"reserved_ports"` // Reserved ports
DynamicPorts []string `mapstructure:"dynamic_ports"` // Dynamically assigned ports
}

// Copy returns a deep copy of the network resource
Expand All @@ -638,7 +638,7 @@ func (n *NetworkResource) Add(delta *NetworkResource) {
n.ReservedPorts = append(n.ReservedPorts, delta.ReservedPorts...)
}
n.MBits += delta.MBits
n.DynamicPorts += delta.DynamicPorts
n.DynamicPorts = append(n.DynamicPorts, delta.DynamicPorts...)
}

func (n *NetworkResource) GoString() string {
Expand Down
6 changes: 3 additions & 3 deletions nomad/structs/structs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,15 @@ func TestResource_Add_Network(t *testing.T) {
Networks: []*NetworkResource{
&NetworkResource{
MBits: 50,
DynamicPorts: 2,
DynamicPorts: []string{"http", "https"},
},
},
}
r3 := &Resources{
Networks: []*NetworkResource{
&NetworkResource{
MBits: 25,
DynamicPorts: 1,
DynamicPorts: []string{"admin"},
},
},
}
Expand All @@ -256,7 +256,7 @@ func TestResource_Add_Network(t *testing.T) {
Networks: []*NetworkResource{
&NetworkResource{
MBits: 75,
DynamicPorts: 3,
DynamicPorts: []string{"http", "https", "admin"},
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion scheduler/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func TestTasksUpdated(t *testing.T) {
}

j6 := mock.Job()
j6.TaskGroups[0].Tasks[0].Resources.Networks[0].DynamicPorts = 3
j6.TaskGroups[0].Tasks[0].Resources.Networks[0].DynamicPorts = []string{"http", "https", "admin"}
if !tasksUpdated(j1.TaskGroups[0], j6.TaskGroups[0]) {
t.Fatalf("bad")
}
Expand Down
13 changes: 9 additions & 4 deletions website/source/docs/jobspec/index.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ job "my-service" {
memory = 128
network {
mbits = 100
dynamic_ports = 1
dynamic_ports = [
"http",
"https",
]
}
}
}
Expand Down Expand Up @@ -182,9 +185,11 @@ The `resources` object supports the following keys:

The `network` object supports teh following keys:

* `dynamic_ports` - The number of dynamic ports. These are
ports that are assigned at task scheduling type, and require
the task to be able to bind dynamically. Defaults to 0.
* `dynamic_ports` - List of strings (`^[a-z0-9_]+$`), called labels. Each label
will be associated with a dynamic port when the task starts. Port allocation
will be passed to the task as an environment variable like `NOMAD_PORT_{{ .Label }}`
(upper-cased). Some Drivers may infer additional semantics from the label. See
[Docker](/docs/drivers/docker.html) for an example.

* `mbits` - The number of MBits in bandwidth required.

Expand Down