Skip to content

Commit 87f3c2d

Browse files
author
Yehudit Kerido
committed
Add missing ports field to workspace model
Signed-off-by: Yehudit Kerido <[email protected]>
1 parent e5d4e41 commit 87f3c2d

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

workspaces/backend/internal/models/workspaces/funcs.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,39 @@ func NewWorkspaceModelFromWorkspace(ws *kubefloworgv1beta1.Workspace, wsk *kubef
128128
return workspaceModel
129129
}
130130

131+
func buildPortsList(ws *kubefloworgv1beta1.Workspace, wsk *kubefloworgv1beta1.WorkspaceKind) []ImagePort {
132+
var ports []ImagePort
133+
134+
// Return an empty list if wsk is nil.
135+
if !wskExists(wsk) {
136+
return ports
137+
}
138+
139+
// Get the image configuration from the WorkspaceKind's PodTemplate options.
140+
imageConfig := wsk.Spec.PodTemplate.Options.ImageConfig
141+
142+
for _, val := range imageConfig.Values {
143+
if len(val.Spec.Ports) == 0 {
144+
continue
145+
}
146+
firstPort := val.Spec.Ports[0]
147+
portStr := fmt.Sprintf("%d", firstPort.Port)
148+
id := firstPort.Id
149+
displayName := firstPort.DisplayName
150+
if displayName == "" {
151+
displayName = val.Id
152+
}
153+
imagePort := ImagePort{
154+
ID: id,
155+
DisplayName: displayName,
156+
Port: portStr,
157+
}
158+
ports = append(ports, imagePort)
159+
}
160+
161+
return ports
162+
}
163+
131164
func wskExists(wsk *kubefloworgv1beta1.WorkspaceKind) bool {
132165
return wsk != nil && wsk.UID != ""
133166
}
@@ -218,6 +251,7 @@ func buildImageConfig(ws *kubefloworgv1beta1.Workspace, wsk *kubefloworgv1beta1.
218251
Current: currentImageConfig,
219252
Desired: desiredImageConfig,
220253
RedirectChain: redirectChain,
254+
Ports: buildPortsList(ws, wsk),
221255
}
222256
}
223257

workspaces/backend/internal/models/workspaces/types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ type ImageConfig struct {
8484
Current OptionInfo `json:"current"`
8585
Desired *OptionInfo `json:"desired,omitempty"`
8686
RedirectChain []RedirectStep `json:"redirect_chain,omitempty"`
87+
Ports []ImagePort `json:"ports,omitempty"`
88+
}
89+
90+
type ImagePort struct {
91+
ID string `json:"id"`
92+
DisplayName string `json:"display_name"`
93+
Port string `json:"port"`
8794
}
8895

8996
type PodConfig struct {

0 commit comments

Comments
 (0)