Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion manager/controlapi/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,10 @@ func (s *Server) CreateService(ctx context.Context, request *api.CreateServiceRe
})
switch err {
case store.ErrNameConflict:
return nil, status.Errorf(codes.AlreadyExists, "service %s already exists", request.Spec.Annotations.Name)
// Enhance the name-confict error to include the service name. The original
// `ErrNameConflict` error-message is included for backward-compatibility
// with older consumers of the API performing string-matching.
return nil, status.Errorf(codes.AlreadyExists, "%s: service %s already exists", err.Error(), request.Spec.Annotations.Name)
case nil:
return &api.CreateServiceResponse{Service: service}, nil
default:
Expand Down
4 changes: 4 additions & 0 deletions manager/controlapi/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,10 @@ func TestCreateService(t *testing.T) {
r, err = ts.Client.CreateService(context.Background(), &api.CreateServiceRequest{Spec: spec})
assert.Error(t, err)
assert.Equal(t, codes.AlreadyExists, testutils.ErrorCode(err))

// Make sure the error contains "name conflicts with an existing object" for
// backward-compatibility with older clients doing string-matching...
assert.Contains(t, err.Error(), "name conflicts with an existing object")
}

func TestSecretValidation(t *testing.T) {
Expand Down