diff --git a/pkg/cmd/server/start/config_test.go b/pkg/cmd/server/start/config_test.go index 78da0589d722..6aa60e7934c8 100644 --- a/pkg/cmd/server/start/config_test.go +++ b/pkg/cmd/server/start/config_test.go @@ -1,6 +1,7 @@ package start import ( + "strings" "testing" "github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd" @@ -8,6 +9,46 @@ import ( "github.com/openshift/origin/pkg/cmd/util" ) +func TestMasterURLNoPathAllowed(t *testing.T) { + masterArgs := NewDefaultMasterArgs() + masterArgs.MasterAddr.Set("http://example.com:9012/") + err := masterArgs.Validate() + + if err == nil || !strings.Contains(err.Error(), "may not include a path") { + t.Errorf("expected %v, got %v", "may not include a path", err) + } +} + +func TestMasterPublicURLNoPathAllowed(t *testing.T) { + masterArgs := NewDefaultMasterArgs() + masterArgs.MasterPublicAddr.Set("http://example.com:9012/") + err := masterArgs.Validate() + + if err == nil || !strings.Contains(err.Error(), "may not include a path") { + t.Errorf("expected %v, got %v", "may not include a path", err) + } +} + +func TestKubePublicURLNoPathAllowed(t *testing.T) { + masterArgs := NewDefaultMasterArgs() + masterArgs.KubernetesPublicAddr.Set("http://example.com:9012/") + err := masterArgs.Validate() + + if err == nil || !strings.Contains(err.Error(), "may not include a path") { + t.Errorf("expected %v, got %v", "may not include a path", err) + } +} + +func TestKubeURLNoPathAllowed(t *testing.T) { + masterArgs := NewDefaultMasterArgs() + masterArgs.KubeConnectionArgs.KubernetesAddr.Set("http://example.com:9012/") + err := masterArgs.Validate() + + if err == nil || !strings.Contains(err.Error(), "may not include a path") { + t.Errorf("expected %v, got %v", "may not include a path", err) + } +} + func TestMasterPublicAddressDefaulting(t *testing.T) { expected := "http://example.com:9012" diff --git a/pkg/cmd/server/start/master_args.go b/pkg/cmd/server/start/master_args.go index abf54c64857a..7f6161e70db2 100644 --- a/pkg/cmd/server/start/master_args.go +++ b/pkg/cmd/server/start/master_args.go @@ -251,6 +251,35 @@ func (args MasterArgs) BuildSerializeableKubeMasterConfig() (*configapi.Kubernet return config, nil } +func (args MasterArgs) Validate() error { + masterAddr, err := args.GetMasterAddress() + if addr, err := masterAddr, err; err != nil { + return err + } else if len(addr.Path) != 0 { + return fmt.Errorf("master url may not include a path: '%v'", addr.Path) + } + + if addr, err := args.GetMasterPublicAddress(); err != nil { + return err + } else if len(addr.Path) != 0 { + return fmt.Errorf("master public url may not include a path: '%v'", addr.Path) + } + + if addr, err := args.KubeConnectionArgs.GetKubernetesAddress(masterAddr); err != nil { + return err + } else if len(addr.Path) != 0 { + return fmt.Errorf("kubernetes url may not include a path: '%v'", addr.Path) + } + + if addr, err := args.GetKubernetesPublicAddress(); err != nil { + return err + } else if len(addr.Path) != 0 { + return fmt.Errorf("kubernetes public url may not include a path: '%v'", addr.Path) + } + + return nil +} + // GetServerCertHostnames returns the set of hostnames that any serving certificate for master needs to be valid for. func (args MasterArgs) GetServerCertHostnames() (util.StringSet, error) { masterAddr, err := args.GetMasterAddress() diff --git a/pkg/cmd/server/start/start_allinone.go b/pkg/cmd/server/start/start_allinone.go index ebc3c041b0de..9bae9d43418d 100644 --- a/pkg/cmd/server/start/start_allinone.go +++ b/pkg/cmd/server/start/start_allinone.go @@ -144,6 +144,10 @@ func (o AllInOneOptions) Validate(args []string) error { } } + if err := o.MasterArgs.Validate(); err != nil { + return err + } + return nil } diff --git a/pkg/cmd/server/start/start_master.go b/pkg/cmd/server/start/start_master.go index e70d7486311f..dc60f8012da9 100644 --- a/pkg/cmd/server/start/start_master.go +++ b/pkg/cmd/server/start/start_master.go @@ -122,6 +122,10 @@ func (o MasterOptions) Validate(args []string) error { } } + if err := o.MasterArgs.Validate(); err != nil { + return err + } + return nil }