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
41 changes: 41 additions & 0 deletions pkg/cmd/server/start/config_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,54 @@
package start

import (
"strings"
"testing"

"github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd"
clientcmdapi "github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd/api"
"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"

Expand Down
29 changes: 29 additions & 0 deletions pkg/cmd/server/start/master_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions pkg/cmd/server/start/start_allinone.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ func (o AllInOneOptions) Validate(args []string) error {
}
}

if err := o.MasterArgs.Validate(); err != nil {
return err
}

return nil
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/cmd/server/start/start_master.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ func (o MasterOptions) Validate(args []string) error {
}
}

if err := o.MasterArgs.Validate(); err != nil {
return err
}

return nil
}

Expand Down