diff --git a/components/gitpod-protocol/go/gitpod-config-types.go b/components/gitpod-protocol/go/gitpod-config-types.go index f9cd78253cdb30..b6f29108a4d623 100644 --- a/components/gitpod-protocol/go/gitpod-config-types.go +++ b/components/gitpod-protocol/go/gitpod-config-types.go @@ -72,7 +72,10 @@ type Image_object struct { // PortsItems type PortsItems struct { - // Port name (deprecated). + // A description to identify what is this port used for. + Description string `yaml:"description,omitempty"` + + // Port name. Name string `yaml:"name,omitempty"` // What to do when a service on this port was detected. 'notify' (default) will show a notification asking the user what to do. 'open-browser' will open a new browser tab. 'open-preview' will open in the preview on the right of the IDE. 'ignore' will do nothing. @@ -84,7 +87,7 @@ type PortsItems struct { // The protocol to be used. (deprecated) Protocol string `yaml:"protocol,omitempty"` - // Whether the port visibility should be private or public. 'public' (default) will allow everyone with the port URL to access the port. 'private' will only allow users with workspace access to access the port. + // Whether the port visibility should be private or public. 'private' (default) will only allow users with workspace access to access the port. 'public' will allow everyone with the port URL to access the port. Visibility string `yaml:"visibility,omitempty"` } diff --git a/components/supervisor/pkg/ports/ports-config.go b/components/supervisor/pkg/ports/ports-config.go index 691e30b19f143a..50faa79ab317e3 100644 --- a/components/supervisor/pkg/ports/ports-config.go +++ b/components/supervisor/pkg/ports/ports-config.go @@ -74,9 +74,11 @@ func (configs *Configs) Get(port uint32) (*gitpod.PortConfig, ConfigKind, bool) for _, rangeConfig := range configs.instanceRangeConfigs { if rangeConfig.Start <= port && port <= rangeConfig.End { return &gitpod.PortConfig{ - Port: float64(port), - OnOpen: rangeConfig.OnOpen, - Visibility: rangeConfig.Visibility, + Port: float64(port), + OnOpen: rangeConfig.OnOpen, + Visibility: rangeConfig.Visibility, + Description: rangeConfig.Description, + Name: rangeConfig.Name, }, RangeConfigKind, true } } @@ -197,9 +199,11 @@ func parseInstanceConfigs(ports []*gitpod.PortsItems) (portConfigs map[uint32]*g _, exists := portConfigs[port] if !exists { portConfigs[port] = &gitpod.PortConfig{ - OnOpen: config.OnOpen, - Port: float64(Port), - Visibility: config.Visibility, + OnOpen: config.OnOpen, + Port: float64(Port), + Visibility: config.Visibility, + Description: config.Description, + Name: config.Name, } } continue diff --git a/components/supervisor/pkg/ports/ports-config_test.go b/components/supervisor/pkg/ports/ports-config_test.go index 5cbcdbebc75e14..39c88d7490741d 100644 --- a/components/supervisor/pkg/ports/ports-config_test.go +++ b/components/supervisor/pkg/ports/ports-config_test.go @@ -29,17 +29,21 @@ func TestPortsConfig(t *testing.T) { Desc: "workspace port config", WorkspacePorts: []*gitpod.PortConfig{ { - Port: 9229, - OnOpen: "ignore", - Visibility: "public", + Port: 9229, + OnOpen: "ignore", + Visibility: "public", + Name: "Nice Port Name", + Description: "Nice Port Description", }, }, Expectation: &PortConfigTestExpectations{ WorkspaceConfigs: []*gitpod.PortConfig{ { - Port: 9229, - OnOpen: "ignore", - Visibility: "public", + Port: 9229, + OnOpen: "ignore", + Visibility: "public", + Name: "Nice Port Name", + Description: "Nice Port Description", }, }, }, @@ -49,18 +53,22 @@ func TestPortsConfig(t *testing.T) { GitpodConfig: &gitpod.GitpodConfig{ Ports: []*gitpod.PortsItems{ { - Port: 9229, - OnOpen: "ignore", - Visibility: "public", + Port: 9229, + OnOpen: "ignore", + Visibility: "public", + Name: "Nice Port Name", + Description: "Nice Port Description", }, }, }, Expectation: &PortConfigTestExpectations{ InstancePortConfigs: []*gitpod.PortConfig{ { - Port: 9229, - OnOpen: "ignore", - Visibility: "public", + Port: 9229, + OnOpen: "ignore", + Visibility: "public", + Name: "Nice Port Name", + Description: "Nice Port Description", }, }, }, @@ -70,9 +78,11 @@ func TestPortsConfig(t *testing.T) { GitpodConfig: &gitpod.GitpodConfig{ Ports: []*gitpod.PortsItems{ { - Port: "9229-9339", - OnOpen: "ignore", - Visibility: "public", + Port: "9229-9339", + OnOpen: "ignore", + Visibility: "public", + Name: "Nice Port Name", + Description: "Nice Port Description", }, }, }, @@ -80,9 +90,11 @@ func TestPortsConfig(t *testing.T) { InstanceRangeConfigs: []*RangeConfig{ { PortsItems: &gitpod.PortsItems{ - Port: "9229-9339", - OnOpen: "ignore", - Visibility: "public", + Port: "9229-9339", + OnOpen: "ignore", + Visibility: "public", + Description: "Nice Port Description", + Name: "Nice Port Name", }, Start: 9229, End: 9339, diff --git a/components/supervisor/pkg/ports/ports.go b/components/supervisor/pkg/ports/ports.go index 74998519c903e6..9ada4a4d336b33 100644 --- a/components/supervisor/pkg/ports/ports.go +++ b/components/supervisor/pkg/ports/ports.go @@ -411,6 +411,12 @@ func (pm *Manager) nextState(ctx context.Context) map[uint32]*managedPort { var public bool config, kind, exists := pm.configs.Get(mp.LocalhostPort) + if exists { + mp.Name = config.Name + mp.Description = config.Description + mp.OnExposed = getOnExposedAction(config, mp.LocalhostPort) + } + configured := exists && kind == PortConfigKind if mp.Exposed || configured { public = mp.Visibility == api.PortVisibility_public