From 967429caa590b3d13075ae52e0e0672c05b67da4 Mon Sep 17 00:00:00 2001 From: Benjamin Gilbert Date: Fri, 2 Nov 2018 14:16:45 -0400 Subject: [PATCH] platform/local: dynamically select Omaha listen port 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. --- platform/local/flight.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/platform/local/flight.go b/platform/local/flight.go index 5bf3476f0..1ac91db95 100644 --- a/platform/local/flight.go +++ b/platform/local/flight.go @@ -16,6 +16,9 @@ package local import ( + "fmt" + "sync/atomic" + "github.com/coreos/go-omaha/omaha" "github.com/coreos/mantle/lang/destructor" @@ -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) { @@ -38,6 +46,7 @@ func NewLocalFlight(opts *platform.Options, platformName platform.Name) (*LocalF lf := &LocalFlight{ BaseFlight: bf, + listenPort: listenPortBase, } lf.AddDestructor(lf.BaseFlight) @@ -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 @@ -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() }