diff --git a/pkg/minikube/service/service.go b/pkg/minikube/service/service.go index d3bd18015d..6a0267fcd4 100644 --- a/pkg/minikube/service/service.go +++ b/pkg/minikube/service/service.go @@ -261,11 +261,6 @@ func WaitForService(api libmachine.API, cname string, namespace string, service interval = 1 } - err := CheckService(cname, namespace, service) - if err != nil { - return nil, &SVCNotFoundError{err} - } - chkSVC := func() error { return CheckService(cname, namespace, service) } if err := retry.Expo(chkSVC, time.Duration(interval)*time.Second, time.Duration(wait)*time.Second); err != nil { diff --git a/pkg/minikube/service/service_test.go b/pkg/minikube/service/service_test.go index 42293cb529..75ec349d31 100644 --- a/pkg/minikube/service/service_test.go +++ b/pkg/minikube/service/service_test.go @@ -25,6 +25,7 @@ import ( "strings" "testing" "text/template" + "time" "github.com/docker/machine/libmachine" "github.com/docker/machine/libmachine/host" @@ -261,7 +262,12 @@ func (s MockServiceInterface) Get(ctx context.Context, name string, _ meta.GetOp } } - return nil, nil + return nil, errors.New("Service not found") +} + +func (s MockServiceInterface) Create(ctx context.Context, service *core.Service, _ meta.CreateOptions) (*core.Service, error) { + s.ServiceList.Items = append(s.ServiceList.Items, *service) + return service, nil } func TestGetServiceListFromServicesByLabel(t *testing.T) { @@ -896,6 +902,14 @@ func TestWaitAndMaybeOpenService(t *testing.T) { expected: []string{}, err: true, }, + { + description: "correctly return serviceURLs for a delayed service", + namespace: "default", + service: "mock-dashboard-delayed", + api: defaultAPI, + https: true, + expected: []string{"http://127.0.0.1:1111"}, + }, } defer revertK8sClient(K8s) for _, test := range tests { @@ -905,8 +919,33 @@ func TestWaitAndMaybeOpenService(t *testing.T) { endpointsMap: endpointNamespaces, } + go func() { + // wait for the delayed mock service to be created + time.Sleep(2 * time.Second) + + _, _ = serviceNamespaces[test.namespace].Create(context.Background(), &core.Service{ + ObjectMeta: meta.ObjectMeta{ + Name: "mock-dashboard-delayed", + Namespace: "default", + Labels: map[string]string{"mock": "mock"}, + }, + Spec: core.ServiceSpec{ + Ports: []core.ServicePort{ + { + Name: "port1", + NodePort: int32(1111), + Port: int32(11111), + TargetPort: intstr.IntOrString{ + IntVal: int32(11111), + }, + }, + }, + }, + }, meta.CreateOptions{}) + }() + var urlList []string - urlList, err := WaitForService(test.api, "minikube", test.namespace, test.service, defaultTemplate, test.urlMode, test.https, 1, 0) + urlList, err := WaitForService(test.api, "minikube", test.namespace, test.service, defaultTemplate, test.urlMode, test.https, 5, 0) if test.err && err == nil { t.Fatalf("WaitForService expected to fail for test: %v", test) }