Skip to content

Commit

Permalink
Merge pull request #15735 from elizabeth-dev/fix/wait-cli-command
Browse files Browse the repository at this point in the history
fix: service CLI command not honoring --wait arg
  • Loading branch information
medyagh committed Feb 10, 2023
2 parents 3a9c9a8 + 3f9c7f3 commit 5c0c9e8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
5 changes: 0 additions & 5 deletions pkg/minikube/service/service.go
Expand Up @@ -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 {
Expand Down
43 changes: 41 additions & 2 deletions pkg/minikube/service/service_test.go
Expand Up @@ -25,6 +25,7 @@ import (
"strings"
"testing"
"text/template"
"time"

"github.com/docker/machine/libmachine"
"github.com/docker/machine/libmachine/host"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
Expand Down

0 comments on commit 5c0c9e8

Please sign in to comment.