Better error message for services with no NodePort
parent
2e70975634
commit
892a116dc3
pkg/minikube/cluster
|
@ -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) {
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue