Skip to content

Commit dc3e193

Browse files
mustard-mhroboquat
authored andcommitted
[supervisor] add test cases and fix workspace configed ports alway on top
1 parent 9df6cf8 commit dc3e193

File tree

3 files changed

+104
-3
lines changed

3 files changed

+104
-3
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import (
1616
"github.com/gitpod-io/gitpod/supervisor/pkg/config"
1717
)
1818

19+
const NON_CONFIGED_BASIC_SCORE = 100000
20+
1921
// RangeConfig is a port range config.
2022
type RangeConfig struct {
2123
gitpod.PortsItems
@@ -190,7 +192,7 @@ func parseWorkspaceConfigs(ports []*gitpod.PortConfig) (portConfigs map[uint32]*
190192
portConfigs[port] = &SortConfig{
191193
PortConfig: *config,
192194
// We don't care about workspace configs but instance config
193-
Sort: 0,
195+
Sort: NON_CONFIGED_BASIC_SCORE - 1,
194196
}
195197
}
196198
}

components/supervisor/pkg/ports/ports.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,8 +748,8 @@ func (pm *Manager) getStatus() []*api.PortsStatus {
748748
}
749749
sort.SliceStable(res, func(i, j int) bool {
750750
// Max number of port 65536
751-
score1 := 100000 + res[i].LocalPort
752-
score2 := 100000 + res[j].LocalPort
751+
score1 := NON_CONFIGED_BASIC_SCORE + res[i].LocalPort
752+
score2 := NON_CONFIGED_BASIC_SCORE + res[j].LocalPort
753753
if c, _, ok := pm.configs.Get(res[i].LocalPort); ok {
754754
score1 = c.Sort
755755
}

components/supervisor/pkg/ports/ports_test.go

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,105 @@ func TestPortsUpdateState(t *testing.T) {
577577
},
578578
},
579579
},
580+
{
581+
Desc: "change configed ports order with ranged covered not ranged",
582+
Changes: []Change{
583+
{
584+
Config: &ConfigChange{
585+
workspace: []*gitpod.PortConfig{
586+
{Port: 3000, Visibility: "private", Name: "react"},
587+
},
588+
instance: []*gitpod.PortsItems{
589+
{Port: 3001, Visibility: "private", Name: "react"},
590+
{Port: 3000, Visibility: "private", Name: "react"},
591+
},
592+
},
593+
},
594+
{
595+
Config: &ConfigChange{
596+
workspace: []*gitpod.PortConfig{
597+
{Port: 3000, Visibility: "private", Name: "react"},
598+
},
599+
instance: []*gitpod.PortsItems{
600+
{Port: 3003, Visibility: "private", Name: "react"},
601+
{Port: 3001, Visibility: "private", Name: "react"},
602+
{Port: "3001-3005", Visibility: "private", Name: "react"},
603+
{Port: 3000, Visibility: "private", Name: "react"},
604+
},
605+
},
606+
},
607+
{
608+
Served: []ServedPort{{net.IPv4zero, 3000, false}},
609+
},
610+
{
611+
Served: []ServedPort{{net.IPv4zero, 3000, false}, {net.IPv4zero, 3001, false}, {net.IPv4zero, 3002, false}},
612+
},
613+
{
614+
Config: &ConfigChange{
615+
workspace: []*gitpod.PortConfig{
616+
{Port: 3000, Visibility: "private", Name: "react"},
617+
},
618+
instance: []*gitpod.PortsItems{
619+
{Port: 3003, Visibility: "private", Name: "react"},
620+
{Port: 3000, Visibility: "private", Name: "react"},
621+
},
622+
},
623+
},
624+
{
625+
Config: &ConfigChange{
626+
workspace: []*gitpod.PortConfig{
627+
{Port: 3000, Visibility: "private", Name: "react"},
628+
},
629+
instance: []*gitpod.PortsItems{
630+
{Port: "3001-3005", Visibility: "private", Name: "react"},
631+
{Port: 3003, Visibility: "private", Name: "react"},
632+
{Port: 3000, Visibility: "private", Name: "react"},
633+
},
634+
},
635+
},
636+
},
637+
ExpectedExposure: []ExposedPort{
638+
{LocalPort: 3000},
639+
{LocalPort: 3001},
640+
{LocalPort: 3002},
641+
{LocalPort: 3003},
642+
},
643+
ExpectedUpdates: UpdateExpectation{
644+
{},
645+
{
646+
{LocalPort: 3001, Name: "react", OnOpen: api.PortsStatus_notify},
647+
{LocalPort: 3000, Name: "react", OnOpen: api.PortsStatus_notify},
648+
},
649+
{
650+
{LocalPort: 3003, Name: "react", OnOpen: api.PortsStatus_notify},
651+
{LocalPort: 3001, Name: "react", OnOpen: api.PortsStatus_notify},
652+
{LocalPort: 3000, Name: "react", OnOpen: api.PortsStatus_notify},
653+
},
654+
{
655+
{LocalPort: 3003, Name: "react", OnOpen: api.PortsStatus_notify},
656+
{LocalPort: 3001, Name: "react", OnOpen: api.PortsStatus_notify},
657+
{LocalPort: 3000, Served: true, Name: "react", OnOpen: api.PortsStatus_notify},
658+
},
659+
{
660+
{LocalPort: 3003, Name: "react", OnOpen: api.PortsStatus_notify},
661+
{LocalPort: 3001, Served: true, Name: "react", OnOpen: api.PortsStatus_notify},
662+
{LocalPort: 3002, Served: true, Name: "react", OnOpen: api.PortsStatus_notify},
663+
{LocalPort: 3000, Served: true, Name: "react", OnOpen: api.PortsStatus_notify},
664+
},
665+
{
666+
{LocalPort: 3003, Name: "react", OnOpen: api.PortsStatus_notify},
667+
{LocalPort: 3000, Served: true, Name: "react", OnOpen: api.PortsStatus_notify},
668+
{LocalPort: 3001, Served: true, OnOpen: api.PortsStatus_notify_private},
669+
{LocalPort: 3002, Served: true, OnOpen: api.PortsStatus_notify_private},
670+
},
671+
{
672+
{LocalPort: 3001, Name: "react", Served: true, OnOpen: api.PortsStatus_notify},
673+
{LocalPort: 3002, Name: "react", Served: true, OnOpen: api.PortsStatus_notify},
674+
{LocalPort: 3003, Name: "react", OnOpen: api.PortsStatus_notify},
675+
{LocalPort: 3000, Served: true, Name: "react", OnOpen: api.PortsStatus_notify},
676+
},
677+
},
678+
},
580679
}
581680

582681
log.Log.Logger.SetLevel(logrus.FatalLevel)

0 commit comments

Comments
 (0)