Better error message for services with no NodePort

pull/299/head
Jimmi Dyson 2016-07-08 18:46:35 +01:00
parent 2e70975634
commit 892a116dc3
No known key found for this signature in database
GPG Key ID: 978CD4AF4C1E87F5
2 changed files with 19 additions and 1 deletions
pkg/minikube/cluster

View File

@ -424,7 +424,14 @@ func getServicePortFromServiceGetter(services serviceGetter, service string) (in
if err != nil {
return 0, fmt.Errorf("Error getting %s service: %s", service, err)
}
return int(svc.Spec.Ports[0].NodePort), nil
nodePort := 0
if len(svc.Spec.Ports) > 0 {
nodePort = int(svc.Spec.Ports[0].NodePort)
}
if nodePort == 0 {
return 0, fmt.Errorf("Service %s does not have a node port. To have one assigned automatically, the service type must be NodePort or LoadBalancer, but this service is of type %s.", service, svc.Spec.Type)
}
return nodePort, nil
}
func getKubernetesServicesWithNamespace(namespace string) (serviceGetter, error) {

View File

@ -464,6 +464,17 @@ func TestGetDashboardURL(t *testing.T) {
}
func TestGetServiceURLWithoutNodePort(t *testing.T) {
mockServiceGetter := NewMockServiceGetter()
mockDashboardService := api.Service{}
mockServiceGetter.services["mock-service"] = mockDashboardService
_, err := getServicePortFromServiceGetter(mockServiceGetter, "mock-service")
if err == nil {
t.Fatalf("Expected error getting service with no node port")
}
}
func TestUpdate(t *testing.T) {
s, _ := tests.NewSSHServer()
port, err := s.Start()