Skip to content

Commit c7ddd74

Browse files
committed
fixup! chore: consistent error
Signed-off-by: Oleksii Kurinnyi <[email protected]>
1 parent dc0a395 commit c7ddd74

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

controllers/controller/devworkspacerouting/solvers/common.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package solvers
1717

1818
import (
1919
"context"
20-
"fmt"
2120

2221
controllerv1alpha1 "github.com/devfile/devworkspace-operator/apis/controller/v1alpha1"
2322
"github.com/devfile/devworkspace-operator/pkg/common"
@@ -62,7 +61,7 @@ func GetDiscoverableServicesForEndpoints(endpoints map[string]controllerv1alpha1
6261
} else {
6362
if existingService.Labels[constants.DevWorkspaceIDLabel] != meta.DevWorkspaceId {
6463
return nil, &ServiceConflictError{
65-
Reason: fmt.Sprintf("discoverable endpoint %s conflicts with existing service", endpoint.Name),
64+
EndpointName: endpoint.Name,
6665
}
6766
}
6867
}

controllers/controller/devworkspacerouting/solvers/errors.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package solvers
1717

1818
import (
1919
"errors"
20+
"fmt"
2021
"time"
2122
)
2223

@@ -27,15 +28,15 @@ var _ error = (*ServiceConflictError)(nil)
2728
// ServiceConflictError is returned when a discoverable endpoint has a name that is already in use by
2829
// another DevWorkspace's service.
2930
type ServiceConflictError struct {
30-
Reason string
31+
EndpointName string
32+
WorkspaceName string
3133
}
3234

3335
func (e *ServiceConflictError) Error() string {
34-
reason := "<no reason given>"
35-
if len(e.Reason) > 0 {
36-
reason = e.Reason
36+
if (e.WorkspaceName == "") {
37+
return fmt.Sprintf("discoverable endpoint '%s' is already in use by another workspace", e.EndpointName)
3738
}
38-
return "workspace routing has a service conflict: " + reason
39+
return fmt.Sprintf("discoverable endpoint '%s' is already in use by workspace '%s'", e.EndpointName, e.WorkspaceName)
3940
}
4041

4142
// RoutingNotSupported is used by the solvers when they supported the routingclass of the workspace they've been asked to route

webhook/workspace/handler/validate.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ func (h *WebhookHandler) validateEndpoints(ctx context.Context, workspace *dwv2.
124124
for _, endpoint := range component.Container.Endpoints {
125125
if discoverableEndpoints[endpoint.Name] {
126126
return &solvers.ServiceConflictError{
127-
Reason: fmt.Sprintf("discoverable endpoint '%s' is already in use by workspace '%s'", endpoint.Name, otherWorkspace.Name),
127+
EndpointName: endpoint.Name,
128+
WorkspaceName: otherWorkspace.Name,
128129
}
129130
}
130131
}

0 commit comments

Comments
 (0)