Skip to content
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
12 changes: 12 additions & 0 deletions pkg/cmd/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ type Config struct {
// addresses for external clients
MasterPublicAddr flagtypes.Addr
KubernetesPublicAddr flagtypes.Addr
// addresses for asset server
AssetBindAddr flagtypes.Addr
AssetPublicAddr flagtypes.Addr

ImageFormat string
LatestReleaseImages bool
Expand Down Expand Up @@ -90,6 +93,8 @@ func NewDefaultConfig() *Config {
PortalNet: flagtypes.DefaultIPNet("172.30.17.0/24"),
MasterPublicAddr: flagtypes.Addr{Value: "localhost:8443", DefaultScheme: "https", DefaultPort: 8443, AllowPrefix: true}.Default(),
KubernetesPublicAddr: flagtypes.Addr{Value: "localhost:8443", DefaultScheme: "https", DefaultPort: 8443, AllowPrefix: true}.Default(),
AssetPublicAddr: flagtypes.Addr{Value: "localhost:8444", DefaultScheme: "https", DefaultPort: 8444, AllowPrefix: true}.Default(),
AssetBindAddr: flagtypes.Addr{Value: "0.0.0.0:8444", DefaultScheme: "https", DefaultPort: 8444, AllowPrefix: true}.Default(),

ImageTemplate: variable.NewDefaultImageTemplate(),

Expand Down Expand Up @@ -211,7 +216,11 @@ func (cfg Config) GetKubernetesPublicAddress() (*url.URL, error) {
}

func (cfg Config) GetAssetPublicAddress() (*url.URL, error) {
if cfg.AssetPublicAddr.Provided {
return cfg.AssetPublicAddr.URL, nil
}
// Derive the asset public address by incrementing the master public address port by 1
// TODO: derive the scheme/port from the asset bind scheme/port once that is settable via the command line
t, err := cfg.GetMasterPublicAddress()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the default port for the assetPublicAddr should be assetBindAddr port. That would allow it to do match defaulting for masterPublicAddr (directly specified, masterAddr if specified, bindAddr).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if I was exposing the asset stuff via flags, I'd agree... maybe I'll just add that

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if I was exposing the asset stuff via flags, I'd agree... maybe I'll just add that

may as well, it's easy to unit test :)

if err != nil {
return nil, err
Expand All @@ -223,6 +232,9 @@ func (cfg Config) GetAssetPublicAddress() (*url.URL, error) {
}

func (cfg Config) GetAssetBindAddress() string {
if cfg.AssetBindAddr.Provided {
return cfg.AssetBindAddr.URL.Host
}
// Derive the asset bind address by incrementing the master bind address port by 1
return net.JoinHostPort(cfg.BindAddr.Host, strconv.Itoa(cfg.BindAddr.Port+1))
}
Expand Down
60 changes: 60 additions & 0 deletions pkg/cmd/server/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,66 @@ func TestMasterPublicAddressExplicit(t *testing.T) {
}
}

func TestAssetPublicAddressDefaulting(t *testing.T) {
master := "http://example.com:9011"
expected := "http://example.com:9012"

cfg := NewDefaultConfig()
cfg.MasterAddr.Set(master)

actual, err := cfg.GetAssetPublicAddress()
if err != nil {
t.Errorf("unexpected error: %v", err)
}
if expected != actual.String() {
t.Errorf("expected %v, got %v", expected, actual)
}
}

func TestAssetPublicAddressExplicit(t *testing.T) {
master := "http://example.com:9011"
expected := "https://example.com:9014"

cfg := NewDefaultConfig()
cfg.MasterAddr.Set(master)
cfg.AssetPublicAddr.Set(expected)

actual, err := cfg.GetAssetPublicAddress()
if err != nil {
t.Errorf("unexpected error: %v", err)
}
if expected != actual.String() {
t.Errorf("expected %v, got %v", expected, actual)
}
}

func TestAssetBindAddressDefaulting(t *testing.T) {
bind := "1.2.3.4:9011"
expected := "1.2.3.4:9012"

cfg := NewDefaultConfig()
cfg.BindAddr.Set(bind)

actual := cfg.GetAssetBindAddress()
if expected != actual {
t.Errorf("expected %v, got %v", expected, actual)
}
}

func TestAssetBindAddressExplicit(t *testing.T) {
bind := "1.2.3.4:9011"
expected := "2.3.4.5:1234"

cfg := NewDefaultConfig()
cfg.BindAddr.Set(bind)
cfg.AssetBindAddr.Set(expected)

actual := cfg.GetAssetBindAddress()
if expected != actual {
t.Errorf("expected %v, got %v", expected, actual)
}
}

func TestKubernetesPublicAddressDefaultToKubernetesAddress(t *testing.T) {
expected := "http://example.com:9012"

Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/server/origin/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ func namespacingFilter(handler http.Handler, contextMapper kapi.RequestContextMa

ctx = kapi.WithNamespace(ctx, namespace)
contextMapper.Update(req, ctx)
glog.V(2).Infof("set namespace on context to %v", requestInfo.Namespace)
glog.V(4).Infof("set namespace on context to %v", requestInfo.Namespace)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/util/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func WaitForSuccessfulDial(https bool, network, address string, timeout, interva
conn, err = dialer.Dial(network, address)
}
if err != nil {
glog.V(4).Infof("Got error %#v, trying again: %#v\n", err, address)
glog.V(5).Infof("Got error %#v, trying again: %#v\n", err, address)
time.Sleep(interval)
continue
}
Expand Down
8 changes: 6 additions & 2 deletions test/integration/test_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ func StartTestServer(args ...string) (start.Config, error) {

masterAddr := httptest.NewUnstartedServer(nil).Listener.Addr().String()
fmt.Printf("masterAddr: %#v\n", masterAddr)

startConfig.MasterAddr.Set(masterAddr)
startConfig.BindAddr.Set(masterAddr)
startConfig.EtcdAddr.Set(getEtcdURL())

assetAddr := httptest.NewUnstartedServer(nil).Listener.Addr().String()
fmt.Printf("assetAddr: %#v\n", assetAddr)
startConfig.AssetBindAddr.Set(assetAddr)
startConfig.AssetPublicAddr.Set(assetAddr)

startConfig.Complete(args)

var startError error
Expand All @@ -54,7 +58,7 @@ func StartTestServer(args ...string) (start.Config, error) {
}()

// wait for the server to come up: 35 seconds
if err := cmdutil.WaitForSuccessfulDial(true, "tcp", masterAddr, 100*time.Millisecond, 100*time.Millisecond, 175); err != nil {
if err := cmdutil.WaitForSuccessfulDial(true, "tcp", masterAddr, 100*time.Millisecond, 1*time.Second, 35); err != nil {
return *startConfig, err
}

Expand Down