@@ -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+
131164func 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
0 commit comments