diff --git a/pkg/minikube/service/service.go b/pkg/minikube/service/service.go index 710ca0ebfeb1..58a7264731b3 100644 --- a/pkg/minikube/service/service.go +++ b/pkg/minikube/service/service.go @@ -275,7 +275,7 @@ func WaitAndMaybeOpenService(api libmachine.API, namespace string, service strin chkSVC := func() error { return CheckService(namespace, service) } if err := retry.Expo(chkSVC, time.Duration(interval)*time.Second, time.Duration(wait)*time.Second); err != nil { - return errors.Wrapf(err, "Could not find finalized endpoint being pointed to by %s", service) + return errors.Wrapf(err, "Service %s was not found in %q namespace. You may select another namespace by using 'minikube service %s -n ", service, namespace, service) } serviceURL, err := GetServiceURLsForService(api, namespace, service, urlTemplate) diff --git a/pkg/minikube/service/service_test.go b/pkg/minikube/service/service_test.go index 20b9f30fc036..0d4d13fe571e 100644 --- a/pkg/minikube/service/service_test.go +++ b/pkg/minikube/service/service_test.go @@ -97,6 +97,27 @@ var serviceNamespaces = map[string]typed_core.ServiceInterface{ "default": defaultNamespaceServiceInterface, } +var serviceNamespaceOther = map[string]typed_core.ServiceInterface{ + "default": nondefaultNamespaceServiceInterface, +} + +var nondefaultNamespaceServiceInterface = &MockServiceInterface{ + ServiceList: &core.ServiceList{ + Items: []core.Service{ + { + ObjectMeta: meta.ObjectMeta{ + Name: "non-namespace-dashboard-no-ports", + Namespace: "cannot_be_found_namespace", + Labels: map[string]string{"mock": "mock"}, + }, + Spec: core.ServiceSpec{ + Ports: []core.ServicePort{}, + }, + }, + }, + }, +} + var defaultNamespaceServiceInterface = &MockServiceInterface{ ServiceList: &core.ServiceList{ Items: []core.Service{ @@ -893,3 +914,54 @@ func TestWaitAndMaybeOpenService(t *testing.T) { }) } } + +func TestWaitAndMaybeOpenServiceForNotDefaultNamspace(t *testing.T) { + defaultAPI := &tests.MockAPI{ + FakeStore: tests.FakeStore{ + Hosts: map[string]*host.Host{ + config.GetMachineName(): { + Name: config.GetMachineName(), + Driver: &tests.MockDriver{}, + }, + }, + }, + } + defaultTemplate := template.Must(template.New("svc-template").Parse("http://{{.IP}}:{{.Port}}")) + + var tests = []struct { + description string + api libmachine.API + namespace string + service string + expected []string + urlMode bool + https bool + err bool + }{ + { + description: "correctly return empty serviceURLs", + namespace: "default", + service: "non-namespace-dashboard-no-ports", + api: defaultAPI, + expected: []string{}, + err: true, + }, + } + defer revertK8sClient(K8s) + for _, test := range tests { + t.Run(test.description, func(t *testing.T) { + K8s = &MockClientGetter{ + servicesMap: serviceNamespaceOther, + endpointsMap: endpointNamespaces, + } + err := WaitAndMaybeOpenService(test.api, test.namespace, test.service, defaultTemplate, test.urlMode, test.https, 1, 0) + if test.err && err == nil { + t.Fatalf("WaitAndMaybeOpenService expected to fail for test: %v", test) + } + if !test.err && err != nil { + t.Fatalf("WaitAndMaybeOpenService not expected to fail but got err: %v", err) + } + + }) + } +} diff --git a/test.sh b/test.sh index c6173fb5b89d..c48b4a1ef055 100755 --- a/test.sh +++ b/test.sh @@ -20,7 +20,7 @@ TESTSUITE="${TESTSUITE:-all}" # if env variable not set run all the tests exitcode=0 if [[ "$TESTSUITE" = "lint" ]] || [[ "$TESTSUITE" = "all" ]] -then +then echo "= make lint =============================================================" make -s lint-ci && echo ok || ((exitcode += 4)) echo "= go mod ================================================================"