Skip to content

Commit 71889fd

Browse files
mustard-mhroboquat
authored andcommitted
[supervisor] respond PortsStatus with order
1 parent 42cbc5b commit 71889fd

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

components/gitpod-protocol/go/gitpod-service.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,6 +1756,7 @@ type PortConfig struct {
17561756
Visibility string `json:"visibility,omitempty"`
17571757
Description string `json:"description,omitempty"`
17581758
Name string `json:"name,omitempty"`
1759+
Sort uint32 `json:"sort,omitempty"`
17591760
}
17601761

17611762
// TaskConfig is the TaskConfig message type

components/supervisor/pkg/ports/ports-config.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type RangeConfig struct {
2121
*gitpod.PortsItems
2222
Start uint32
2323
End uint32
24+
Sort uint32
2425
}
2526

2627
// Configs provides access to port configurations.
@@ -79,6 +80,7 @@ func (configs *Configs) Get(port uint32) (*gitpod.PortConfig, ConfigKind, bool)
7980
Visibility: rangeConfig.Visibility,
8081
Description: rangeConfig.Description,
8182
Name: rangeConfig.Name,
83+
Sort: rangeConfig.Sort,
8284
}, RangeConfigKind, true
8385
}
8486
}
@@ -184,7 +186,7 @@ func parseWorkspaceConfigs(ports []*gitpod.PortConfig) (portConfigs map[uint32]*
184186
}
185187

186188
func parseInstanceConfigs(ports []*gitpod.PortsItems) (portConfigs map[uint32]*gitpod.PortConfig, rangeConfigs []*RangeConfig) {
187-
for _, config := range ports {
189+
for index, config := range ports {
188190
if config == nil {
189191
continue
190192
}
@@ -204,6 +206,7 @@ func parseInstanceConfigs(ports []*gitpod.PortsItems) (portConfigs map[uint32]*g
204206
Visibility: config.Visibility,
205207
Description: config.Description,
206208
Name: config.Name,
209+
Sort: uint32(index),
207210
}
208211
}
209212
continue
@@ -224,6 +227,7 @@ func parseInstanceConfigs(ports []*gitpod.PortsItems) (portConfigs map[uint32]*g
224227
PortsItems: config,
225228
Start: uint32(start),
226229
End: uint32(end),
230+
Sort: uint32(index),
227231
})
228232
}
229233
return portConfigs, rangeConfigs

components/supervisor/pkg/ports/ports.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,8 +740,29 @@ func (pm *Manager) Subscribe() (*Subscription, error) {
740740
func (pm *Manager) getStatus() []*api.PortsStatus {
741741
res := make([]*api.PortsStatus, 0, len(pm.state))
742742
for port := range pm.state {
743-
res = append(res, pm.getPortStatus(port))
743+
portStatus := pm.getPortStatus(port)
744+
// Filter out ports that not served and not inside `.gitpod.yml`
745+
if _, _, ok := pm.configs.Get(port); !ok && !portStatus.Served {
746+
continue
747+
}
748+
res = append(res, portStatus)
744749
}
750+
sort.SliceStable(res, func(i, j int) bool {
751+
// Max number of port 65536
752+
score1 := 100000 + res[i].LocalPort
753+
score2 := 100000 + res[j].LocalPort
754+
if c, _, ok := pm.configs.Get(res[i].LocalPort); ok {
755+
score1 = c.Sort
756+
}
757+
if c, _, ok := pm.configs.Get(res[j].LocalPort); ok {
758+
score2 = c.Sort
759+
}
760+
if score1 != score2 {
761+
return score1 < score2
762+
}
763+
// Ranged ports
764+
return res[i].LocalPort < res[j].LocalPort
765+
})
745766
return res
746767
}
747768

0 commit comments

Comments
 (0)