Skip to content

Commit df861c3

Browse files
authored
[ws-proxy] Return last instance if multiple instances are found (#17985)
1 parent 51b33d2 commit df861c3

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

components/ws-proxy/pkg/proxy/infoprovider.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package proxy
77
import (
88
"context"
99
"net/url"
10+
"sort"
1011
"time"
1112

1213
"golang.org/x/xerrors"
@@ -122,7 +123,18 @@ func (r *CRDWorkspaceInfoProvider) WorkspaceInfo(workspaceID string) *WorkspaceI
122123
return nil
123124
}
124125

125-
if len(workspaces) == 1 {
126+
if len(workspaces) >= 1 {
127+
if len(workspaces) != 1 {
128+
log.Warnf("multiple instances (%d) for workspace %s", len(workspaces), workspaceID)
129+
}
130+
131+
sort.Slice(workspaces, func(i, j int) bool {
132+
a := workspaces[i].(*WorkspaceInfo)
133+
b := workspaces[j].(*WorkspaceInfo)
134+
135+
return a.StartedAt.After(b.StartedAt)
136+
})
137+
126138
return workspaces[0].(*WorkspaceInfo)
127139
}
128140

0 commit comments

Comments
 (0)