Skip to content
This repository has been archived by the owner on May 7, 2021. It is now read-only.

Commit

Permalink
platform/local: dynamically select Omaha listen port
Browse files Browse the repository at this point in the history
We don't validate that the port isn't already in use, but we're running
in a network namespace, so hopefully there's no contention.
  • Loading branch information
bgilbert committed Nov 5, 2018
1 parent 66c0840 commit 967429c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion platform/local/flight.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
package local

import (
"fmt"
"sync/atomic"

"github.com/coreos/go-omaha/omaha"

"github.com/coreos/mantle/lang/destructor"
Expand All @@ -25,9 +28,14 @@ import (
"github.com/coreos/mantle/system/ns"
)

const (
listenPortBase = 30000
)

type LocalFlight struct {
destructor.MultiDestructor
*platform.BaseFlight
listenPort int32
}

func NewLocalFlight(opts *platform.Options, platformName platform.Name) (*LocalFlight, error) {
Expand All @@ -38,6 +46,7 @@ func NewLocalFlight(opts *platform.Options, platformName platform.Name) (*LocalF

lf := &LocalFlight{
BaseFlight: bf,
listenPort: listenPortBase,
}
lf.AddDestructor(lf.BaseFlight)

Expand Down Expand Up @@ -94,7 +103,7 @@ func (lf *LocalFlight) NewCluster(rconf *platform.RuntimeConfig) (*LocalCluster,
lc.AddCloser(lc.NTPServer)
go lc.NTPServer.Serve()

omahaServer, err := omaha.NewTrivialServer(":34567")
omahaServer, err := omaha.NewTrivialServer(fmt.Sprintf(":%d", lf.newListenPort()))
if err != nil {
lc.Destroy()
return nil, err
Expand All @@ -108,6 +117,10 @@ func (lf *LocalFlight) NewCluster(rconf *platform.RuntimeConfig) (*LocalCluster,
return lc, nil
}

func (lf *LocalFlight) newListenPort() int {
return int(atomic.AddInt32(&lf.listenPort, 1))
}

func (lf *LocalFlight) Destroy() {
lf.MultiDestructor.Destroy()
}

0 comments on commit 967429c

Please sign in to comment.