Skip to content

Commit 9de6b51

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

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

controllers/controller/devworkspacerouting/devworkspacerouting_controller.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,10 @@ func (r *DevWorkspaceRoutingReconciler) Reconcile(ctx context.Context, req ctrl.
126126
}
127127

128128
workspaceMeta := solvers.DevWorkspaceMetadata{
129-
DevWorkspaceId: instance.Spec.DevWorkspaceId,
130-
Namespace: instance.Namespace,
131-
PodSelector: instance.Spec.PodSelector,
129+
DevWorkspaceId: instance.Spec.DevWorkspaceId,
130+
DevWorkspaceName: instance.Name,
131+
Namespace: instance.Namespace,
132+
PodSelector: instance.Spec.PodSelector,
132133
}
133134

134135
restrictedAccess, setRestrictedAccess := instance.Annotations[constants.DevWorkspaceRestrictedAccessAnnotation]
@@ -152,7 +153,7 @@ func (r *DevWorkspaceRoutingReconciler) Reconcile(ctx context.Context, req ctrl.
152153

153154
var conflict *solvers.ServiceConflictError
154155
if errors.As(err, &conflict) {
155-
reqLogger.Error(conflict, "Routing controller detected a service conflict", "serviceName", conflict.Reason)
156+
reqLogger.Error(conflict, "Routing controller detected a service conflict", "endpointName", conflict.EndpointName, "workspaceName", conflict.WorkspaceName)
156157
return reconcile.Result{}, r.markRoutingFailed(instance, fmt.Sprintf("Unable to provision networking for DevWorkspace: %s", conflict))
157158
}
158159

controllers/controller/devworkspacerouting/solvers/common.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ import (
3434
)
3535

3636
type DevWorkspaceMetadata struct {
37-
DevWorkspaceId string
38-
Namespace string
39-
PodSelector map[string]string
37+
DevWorkspaceId string
38+
DevWorkspaceName string
39+
Namespace string
40+
PodSelector map[string]string
4041
}
4142

4243
// GetDiscoverableServicesForEndpoints converts the endpoint list into a set of services, each corresponding to a single discoverable
@@ -61,7 +62,8 @@ func GetDiscoverableServicesForEndpoints(endpoints map[string]controllerv1alpha1
6162
} else {
6263
if existingService.Labels[constants.DevWorkspaceIDLabel] != meta.DevWorkspaceId {
6364
return nil, &ServiceConflictError{
64-
EndpointName: endpoint.Name,
65+
EndpointName: endpoint.Name,
66+
WorkspaceName: existingService.Labels[constants.DevWorkspaceNameLabel],
6567
}
6668
}
6769
}
@@ -77,7 +79,8 @@ func GetDiscoverableServicesForEndpoints(endpoints map[string]controllerv1alpha1
7779
Name: serviceName,
7880
Namespace: meta.Namespace,
7981
Labels: map[string]string{
80-
constants.DevWorkspaceIDLabel: meta.DevWorkspaceId,
82+
constants.DevWorkspaceIDLabel: meta.DevWorkspaceId,
83+
constants.DevWorkspaceNameLabel: meta.DevWorkspaceName,
8184
},
8285
Annotations: map[string]string{
8386
constants.DevWorkspaceDiscoverableServiceAnnotation: "true",

controllers/controller/devworkspacerouting/solvers/common_test.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ func TestGetDiscoverableServicesForEndpoints(t *testing.T) {
4444
}
4545

4646
meta := DevWorkspaceMetadata{
47-
DevWorkspaceId: "current-workspace",
48-
Namespace: "test-namespace",
47+
DevWorkspaceId: "current-workspace-id",
48+
DevWorkspaceName: "current-workspace",
49+
Namespace: "test-namespace",
4950
}
5051

5152
tests := []struct {
@@ -68,14 +69,15 @@ func TestGetDiscoverableServicesForEndpoints(t *testing.T) {
6869
Name: "test-endpoint",
6970
Namespace: "test-namespace",
7071
Labels: map[string]string{
71-
constants.DevWorkspaceIDLabel: "other-workspace",
72+
constants.DevWorkspaceIDLabel: "other-workspace-id",
73+
constants.DevWorkspaceNameLabel: "other-workspace",
7274
},
7375
},
7476
},
7577
},
7678
expectErr: true,
7779
expectErrType: &ServiceConflictError{},
78-
expectMsg: "conflicts with existing service",
80+
expectMsg: "discoverable endpoint 'test-endpoint' is already in use by workspace 'other-workspace'",
7981
},
8082
{
8183
name: "Existing service with same owner (reconciliation)",
@@ -85,7 +87,8 @@ func TestGetDiscoverableServicesForEndpoints(t *testing.T) {
8587
Name: "test-endpoint",
8688
Namespace: "test-namespace",
8789
Labels: map[string]string{
88-
constants.DevWorkspaceIDLabel: "current-workspace",
90+
constants.DevWorkspaceIDLabel: "current-workspace-id",
91+
constants.DevWorkspaceNameLabel: "current-workspace",
8992
},
9093
},
9194
},
@@ -100,7 +103,8 @@ func TestGetDiscoverableServicesForEndpoints(t *testing.T) {
100103
Name: "test-endpoint",
101104
Namespace: "other-namespace",
102105
Labels: map[string]string{
103-
constants.DevWorkspaceIDLabel: "other-workspace",
106+
constants.DevWorkspaceIDLabel: "other-workspace-id",
107+
constants.DevWorkspaceNameLabel: "other-workspace",
104108
},
105109
},
106110
},
@@ -175,8 +179,9 @@ func TestGetDiscoverableServicesForEndpoints_MultipleEndpoints(t *testing.T) {
175179
}
176180

177181
meta := DevWorkspaceMetadata{
178-
DevWorkspaceId: "current-workspace",
179-
Namespace: "test-namespace",
182+
DevWorkspaceId: "current-workspace-id",
183+
DevWorkspaceName: "current-workspace",
184+
Namespace: "test-namespace",
180185
PodSelector: map[string]string{
181186
constants.DevWorkspaceIDLabel: "current-workspace",
182187
},
@@ -203,7 +208,8 @@ func TestGetDiscoverableServicesForEndpoints_MultipleEndpoints(t *testing.T) {
203208
Name: "postgresql",
204209
Namespace: "test-namespace",
205210
Labels: map[string]string{
206-
constants.DevWorkspaceIDLabel: "other-workspace",
211+
constants.DevWorkspaceIDLabel: "other-workspace-id",
212+
constants.DevWorkspaceNameLabel: "other-workspace",
207213
},
208214
},
209215
}

0 commit comments

Comments
 (0)