Skip to content

Commit

Permalink
Improve ErrNoService to describe the name of missing service
Browse files Browse the repository at this point in the history
  • Loading branch information
wpjunior committed Jul 23, 2024
1 parent 9eecf81 commit f057a0c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions kubernetes/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@ var (
)

// ErrNoService indicates that the app has no service running
type ErrNoService struct{ App string }
type ErrNoService struct {
App string
Service string
}

func (e ErrNoService) Error() string {
return fmt.Sprintf("no service found for app %q", e.App)
return fmt.Sprintf("service %q is not found for app %q", e.Service, e.App)
}

// BaseService has the base functionality needed by router.Service implementations
Expand Down Expand Up @@ -154,7 +157,7 @@ func (k *BaseService) getWebService(ctx context.Context, appName string, target
svc, err := client.CoreV1().Services(target.Namespace).Get(ctx, target.Service, metav1.GetOptions{})
if err != nil {
if k8sErrors.IsNotFound(err) {
return nil, ErrNoService{App: appName}
return nil, ErrNoService{App: appName, Service: target.Service}
}
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestGetWebService(t *testing.T) {
}

_, err := svc.getWebService(ctx, "test", router.BackendTarget{Service: "test-not-found", Namespace: svc.Namespace})
assert.Equal(t, ErrNoService{App: "test"}, err)
assert.Equal(t, ErrNoService{App: "test", Service: "test-not-found"}, err)

svc1 := v1.Service{ObjectMeta: metav1.ObjectMeta{
Name: "test-single",
Expand Down

0 comments on commit f057a0c

Please sign in to comment.