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

Ignoring portDefinitions.port field, always picking task ports #127

Merged
merged 1 commit into from
Oct 5, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,11 @@ via Marathon's `portDefinitions`:
},
"portDefinitions": [
{
"port": 0,
"protocol": "tcp",
"labels": {
"consul": "my-app-custom-name"
}
},
{
"port": 0,
"protocol": "tcp",
"labels": {
"consul": "my-app-other-name",
"specific-tag": "tag"
Expand Down Expand Up @@ -286,9 +282,6 @@ though its value won't have any effect.
Tags configured in the top-level application labels will be added to all registrations. Tags configured in the port definition
labels will be added only to corresponding registrations.

You can either provide explicit port numbers or provide 0, in which case randomly assigned ports will be used. Read more
in [Marathon's documentation](https://mesosphere.github.io/marathon/docs/ports.html).

All registrations share the same `marathon-task` tag.

## Migration to version 1.x.x
Expand Down
12 changes: 1 addition & 11 deletions apps/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ type HealthCheck struct {
}

type PortDefinition struct {
Port int `json:"port"`
Labels map[string]string `json:"labels"`
}

Expand Down Expand Up @@ -151,7 +150,7 @@ func (app *App) RegistrationIntents(task *Task, nameSeparator string) []*Registr
for _, d := range definitions {
intents = append(intents, &RegistrationIntent{
Name: app.labelsToName(d.Labels, nameSeparator),
Port: d.toPort(task),
Port: task.Ports[d.Index],
Tags: append(commonTags, labelsToTags(d.Labels)...),
})
}
Expand Down Expand Up @@ -185,24 +184,15 @@ func (app *App) labelsToName(labels map[string]string, nameSeparator string) str

type indexedPortDefinition struct {
Index int
Port int
Labels map[string]string
}

func (i *indexedPortDefinition) toPort(task *Task) int {
if i.Port == 0 {
return task.Ports[i.Index]
}
return i.Port
}

func (app *App) findConsulPortDefinitions() []indexedPortDefinition {
var definitions []indexedPortDefinition
for i, d := range app.PortDefinitions {
if _, ok := d.Labels[MarathonConsulLabel]; ok {
definitions = append(definitions, indexedPortDefinition{
Index: i,
Port: d.Port,
Labels: d.Labels,
})
}
Expand Down
25 changes: 0 additions & 25 deletions apps/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,31 +298,6 @@ func TestRegistrationIntent_PickDifferentPortViaPortDefinitions(t *testing.T) {
assert.Equal(t, 5678, intent.Port)
}

func TestRegistrationIntent_PickExplicitPortViaPortDefinitions(t *testing.T) {
t.Parallel()

// given
app := &App{
ID: "app-name",
Labels: map[string]string{"consul": "true", "private": "tag"},
PortDefinitions: []PortDefinition{
{
Port: 1337,
Labels: map[string]string{"consul": "true"},
},
},
}
task := &Task{
Ports: []int{},
}

// when
intent := app.RegistrationIntents(task, "-")[0]

// then
assert.Equal(t, 1337, intent.Port)
}

func TestRegistrationIntent_MultipleIntentsViaPortDefinitionIfMultipleContainConsulLabel(t *testing.T) {
t.Parallel()

Expand Down
1 change: 0 additions & 1 deletion utils/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ func app(name string, instances int, registrationsPerInstance int, consul bool,
if registrationsPerInstance > 1 {
for i := 0; i < registrationsPerInstance; i++ {
app.PortDefinitions = append(app.PortDefinitions, apps.PortDefinition{
Port: 0,
Labels: map[string]string{"consul": ""},
})
}
Expand Down