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

bugfix on get ip & port in host or user defined network mode #901

Merged
merged 1 commit into from
Aug 29, 2017
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
18 changes: 10 additions & 8 deletions mesos/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,17 @@ func (s *Scheduler) updateHandler(event *mesosproto.Event) {
task.ContainerName = cname
}

if settings := cinfos[0].NetworkSettings; settings != nil {
if net := settings.Networks; net != nil && len(net) > 0 {
for _, cfg := range net {
if cfg.IPAMConfig != nil {
task.IP = cfg.IPAMConfig.IPv4Address
} else {
task.IP = cfg.IPAddress
if task.IP == "" {
if settings := cinfos[0].NetworkSettings; settings != nil {
if net := settings.Networks; net != nil && len(net) > 0 {
for _, cfg := range net {
if cfg.IPAMConfig != nil {
task.IP = cfg.IPAMConfig.IPv4Address
} else {
task.IP = cfg.IPAddress
}
break
}
break
}
}
}
Expand Down
19 changes: 13 additions & 6 deletions mesos/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -802,13 +802,16 @@ func (s *Scheduler) launch(offers []*Offer, tasks []*Task) error {

var idx int
for _, task := range tasks {
num := len(task.cfg.PortMappings)
if idx+num > len(ports) {
return errors.New("no enough ports avaliable")
}
// port allocated only on bridge network.
if task.cfg.Network == "bridge" {
num := len(task.cfg.PortMappings)
if idx+num > len(ports) {
return errors.New("no enough ports avaliable")
}

task.cfg.Ports = ports[idx : idx+num]
idx += num
task.cfg.Ports = ports[idx : idx+num]
idx += num
}

task.AgentId = &mesosproto.AgentID{
Value: proto.String(offers[0].GetAgentId()),
Expand All @@ -834,6 +837,10 @@ func (s *Scheduler) launch(offers []*Offer, tasks []*Task) error {

dbtask.AgentId = t.AgentId.GetValue()
dbtask.IP = t.cfg.IP
if t.cfg.Network == "host" || t.cfg.Network == "bridge" {
dbtask.IP = offers[0].GetHostname()
}

dbtask.Ports = t.cfg.Ports

if err := s.db.UpdateTask(appId, dbtask); err != nil {
Expand Down
7 changes: 7 additions & 0 deletions types/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ func NewTaskConfig(spec *Version, idx int) *TaskConfig {
cfg.IP = spec.IPs[idx]
}

// port is specified on host & user network mode.
if cfg.Network != "bridge" { // none ?
for _, pm := range cfg.PortMappings {
cfg.Ports = append(cfg.Ports, uint64(pm.ContainerPort))
}
}

return cfg
}

Expand Down