Skip to content

Commit ea1b9f9

Browse files
author
Yehudit Kerido
committed
feat(ws): Notebooks 2.0 // Frontend // Fetch workspaces
Signed-off-by: Yehudit Kerido <yehudit.kerido@nokia.com>
1 parent bbaf66b commit ea1b9f9

File tree

6 files changed

+56
-102
lines changed

6 files changed

+56
-102
lines changed

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

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ func NewWorkspaceModelFromWorkspace(ws *kubefloworgv1beta1.Workspace, wsk *kubef
120120
ImageConfig: imageConfigModel,
121121
PodConfig: podConfigModel,
122122
},
123-
EndPoints: buildEndpointsList(ws, wsk),
124123
},
125124
Activity: Activity{
126125
LastActivity: ws.Status.Activity.LastActivity,
@@ -134,37 +133,6 @@ func NewWorkspaceModelFromWorkspace(ws *kubefloworgv1beta1.Workspace, wsk *kubef
134133
return workspaceModel
135134
}
136135

137-
func buildEndpointsList(ws *kubefloworgv1beta1.Workspace, wsk *kubefloworgv1beta1.WorkspaceKind) []EndPoints {
138-
var endpoints []EndPoints
139-
140-
// Return an empty list if wsk is nil.
141-
if wsk == nil {
142-
return endpoints
143-
}
144-
145-
// Get the image configuration from the WorkspaceKind's PodTemplate options.
146-
imageConfig := wsk.Spec.PodTemplate.Options.ImageConfig
147-
148-
for _, val := range imageConfig.Values {
149-
if len(val.Spec.Ports) == 0 {
150-
continue
151-
}
152-
firstPort := val.Spec.Ports[0]
153-
portStr := fmt.Sprintf("%d", firstPort.Port)
154-
displayName := firstPort.DisplayName
155-
if displayName == "" {
156-
displayName = val.Id
157-
}
158-
ep := EndPoints{
159-
DisplayName: displayName,
160-
Port: portStr,
161-
}
162-
endpoints = append(endpoints, ep)
163-
}
164-
165-
return endpoints
166-
}
167-
168136
func wskExists(wsk *kubefloworgv1beta1.WorkspaceKind) bool {
169137
return wsk != nil && wsk.UID != ""
170138
}

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,6 @@ type PodTemplate struct {
5959
PodMetadata PodMetadata `json:"podMetadata"`
6060
Volumes PodVolumes `json:"volumes"`
6161
Options PodTemplateOptions `json:"options"`
62-
EndPoints []EndPoints `json:"end_points"`
63-
}
64-
65-
type EndPoints struct {
66-
DisplayName string `json:"display_name"`
67-
Port string `json:"port"`
6862
}
6963

7064
type PodMetadata struct {
Binary file not shown.

workspaces/frontend/src/__tests__/cypress/cypress/tests/e2e/Workspaces.cy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const validateWorkspaceRow = (workspace: Workspace, index: number) => {
1616

1717
cy.findByTestId(`workspace-row-${index}`)
1818
.find('[data-testid="pod-config"]')
19-
.should('have.text', workspace.pod_template.options.pod_config.current.display_name);
19+
.should('have.text', workspace.podTemplate.options.podConfig.current.displayName);
2020
};
2121

2222
// Test suite for workspace-related tests

workspaces/frontend/src/__tests__/cypress/cypress/tests/mocked/workspace.mock.ts

Lines changed: 37 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,40 @@ const generateMockWorkspace = (
1313
): {
1414
name: string;
1515
namespace: string;
16-
workspace_kind: { name: string };
17-
defer_updates: boolean;
16+
workspaceKind: { name: string };
17+
deferUpdates: boolean;
1818
paused: boolean;
19-
paused_time: number;
19+
pausedTime: number;
20+
pendingRestart: boolean;
2021
state: WorkspaceState;
21-
state_message: string;
22-
pod_template: {
23-
pod_metadata: { labels: object; annotations: object };
22+
stateMessage: string;
23+
podTemplate: {
24+
podMetadata: { labels: object; annotations: object };
2425
volumes: {
25-
home: { pvc_name: string; mount_path: string; readOnly: boolean };
26-
data: { pvc_name: string; mount_path: string; readOnly: boolean }[];
26+
home: { pvcName: string; mountPath: string; readOnly: boolean };
27+
data: { pvcName: string; mountPath: string; readOnly: boolean }[];
2728
};
2829
options: {
29-
image_config: {
30+
imageConfig: {
3031
current: {
3132
id: string;
32-
display_name: string;
33+
displayName: string;
3334
description: string;
3435
labels: { key: string; value: string }[];
3536
};
3637
};
37-
pod_config: {
38+
podConfig: {
3839
current: {
3940
id: string;
40-
display_name: string;
41+
displayName: string;
4142
description: string;
4243
labels: ({ key: string; value: string } | { key: string; value: string })[];
4344
};
4445
};
4546
};
46-
image_config: { current: string; desired: string; redirect_chain: never[] };
47-
pod_config: { current: string; desired: string; redirect_chain: never[] };
48-
end_points: { display_name: string; port: string }[];
4947
};
5048
activity: { last_activity: number; last_update: number };
49+
services: { httpService: { displayName: string; httpPath: string } }[];
5150
} => {
5251
const currentTime = Date.now();
5352
const lastActivityTime = currentTime - Math.floor(Math.random() * 1000000);
@@ -56,55 +55,50 @@ const generateMockWorkspace = (
5655
return {
5756
name,
5857
namespace,
59-
workspace_kind: { name: 'jupyterlab' },
60-
defer_updates: paused,
58+
workspaceKind: { name: 'jupyterlab' },
59+
deferUpdates: paused,
6160
paused,
62-
paused_time: paused ? currentTime - Math.floor(Math.random() * 1000000) : 0,
61+
pausedTime: paused ? currentTime - Math.floor(Math.random() * 1000000) : 0,
62+
pendingRestart: false,
6363
state,
64-
state_message:
64+
stateMessage:
6565
state === WorkspaceState.Running
6666
? 'Workspace is running smoothly.'
6767
: state === WorkspaceState.Paused
6868
? 'Workspace is paused.'
6969
: 'Workspace is operational.',
70-
pod_template: {
71-
end_points: [
72-
{
73-
display_name: 'Jupyter-lab',
74-
port: '8888',
75-
},
76-
],
77-
pod_metadata: {
70+
podTemplate: {
71+
podMetadata: {
7872
labels: {},
7973
annotations: {},
8074
},
8175
volumes: {
8276
home: {
83-
pvc_name: `${pvcName}-home`,
84-
mount_path: '/home/jovyan',
77+
pvcName: `${pvcName}-home`,
78+
mountPath: '/home/jovyan',
8579
readOnly: false,
8680
},
8781
data: [
8882
{
89-
pvc_name: pvcName,
90-
mount_path: '/data/my-data',
83+
pvcName,
84+
mountPath: '/data/my-data',
9185
readOnly: paused,
9286
},
9387
],
9488
},
9589
options: {
96-
image_config: {
90+
imageConfig: {
9791
current: {
9892
id: imageConfigId,
99-
display_name: imageConfigDisplayName,
93+
displayName: imageConfigDisplayName,
10094
description: 'JupyterLab environment',
10195
labels: [{ key: 'python_version', value: '3.11' }],
10296
},
10397
},
104-
pod_config: {
98+
podConfig: {
10599
current: {
106100
id: podConfigId,
107-
display_name: podConfigDisplayName,
101+
displayName: podConfigDisplayName,
108102
description: 'Pod configuration with resource limits',
109103
labels: [
110104
{ key: 'cpu', value: '100m' },
@@ -113,21 +107,19 @@ const generateMockWorkspace = (
113107
},
114108
},
115109
},
116-
image_config: {
117-
current: imageConfigId,
118-
desired: '',
119-
redirect_chain: [],
120-
},
121-
pod_config: {
122-
current: podConfigId,
123-
desired: podConfigId,
124-
redirect_chain: [],
125-
},
126110
},
127111
activity: {
128112
last_activity: lastActivityTime,
129113
last_update: lastUpdateTime,
130114
},
115+
services: [
116+
{
117+
httpService: {
118+
displayName: 'Jupyter-lab',
119+
httpPath: `/workspace/${namespace}/${name}/Jupyter-lab/`,
120+
},
121+
},
122+
],
131123
};
132124
};
133125

workspaces/frontend/src/app/pages/Workspaces/Workspaces.tsx

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -184,19 +184,19 @@ export const Workspaces: React.FunctionComponent = () => {
184184
const [activeSortIndex, setActiveSortIndex] = React.useState<number | null>(null);
185185
const [activeSortDirection, setActiveSortDirection] = React.useState<'asc' | 'desc' | null>(null);
186186

187-
const getSortableRowValues = (workspace: Workspace): (string | number | undefined)[] => {
187+
const getSortableRowValues = (workspace: Workspace): (string | number)[] => {
188188
const { redirectStatus, name, kind, image, podConfig, state, homeVol, cpu, ram, lastActivity } =
189189
{
190190
redirectStatus: '',
191191
name: workspace.name,
192-
kind: workspace.workspace_kind.name,
193-
image: workspace.pod_template.options.image_config.current.display_name,
194-
podConfig: workspace.pod_template.pod_config.current,
192+
kind: workspace.workspaceKind.name,
193+
image: workspace.podTemplate.options.imageConfig.current.displayName,
194+
podConfig: workspace.podTemplate.options.podConfig.current.displayName,
195195
state: workspace.state,
196-
homeVol: workspace.pod_template.volumes.home.pvc_name,
196+
homeVol: workspace.podTemplate.volumes.home.pvcName,
197197
cpu: getCpuValue(workspace),
198198
ram: getRamValue(workspace),
199-
lastActivity: workspace.activity.last_activity,
199+
lastActivity: workspace.activity.lastActivity,
200200
};
201201
redirectStatus: '',
202202
name: workspace.name,
@@ -474,11 +474,11 @@ export const Workspaces: React.FunctionComponent = () => {
474474
);
475475

476476
const getCpuValue = (workspace: Workspace): string =>
477-
workspace.pod_template.options.pod_config.current.labels.find((label) => label.key === 'cpu')
477+
workspace.podTemplate.options.podConfig.current.labels.find((label) => label.key === 'cpu')
478478
?.value || 'N/A';
479479

480480
const getRamValue = (workspace: Workspace): string =>
481-
workspace.pod_template.options.pod_config.current.labels.find((label) => label.key === 'memory')
481+
workspace.podTemplate.options.podConfig.current.labels.find((label) => label.key === 'memory')
482482
?.value || 'N/A';
483483

484484
return (
@@ -540,7 +540,7 @@ export const Workspaces: React.FunctionComponent = () => {
540540
}}
541541
/>
542542
<Td dataLabel={columnNames.redirectStatus}>
543-
{workspaceRedirectStatus[workspace.kind]
543+
{workspaceRedirectStatus[workspace.workspaceKind.name]
544544
? getRedirectStatusIcon(
545545
workspaceRedirectStatus[workspace.kind]?.level,
546546
workspaceRedirectStatus[workspace.kind]?.message ||
@@ -552,37 +552,37 @@ export const Workspaces: React.FunctionComponent = () => {
552552
{workspace.name}
553553
</Td>
554554
<Td dataLabel={columnNames.kind}>
555-
{kindLogoDict[workspace.workspace_kind.name] ? (
556-
<Tooltip content={workspace.workspace_kind.name}>
555+
{kindLogoDict[workspace.workspaceKind.name] ? (
556+
<Tooltip content={workspace.workspaceKind.name}>
557557
<Brand
558-
src={kindLogoDict[workspace.workspace_kind.name]}
559-
alt={workspace.workspace_kind.name}
558+
src={kindLogoDict[workspace.workspaceKind.name]}
559+
alt={workspace.workspaceKind.name}
560560
style={{ width: '20px', height: '20px', cursor: 'pointer' }}
561561
/>
562562
</Tooltip>
563563
) : (
564-
<Tooltip content={workspace.workspace_kind.name}>
564+
<Tooltip content={workspace.workspaceKind.name}>
565565
<CodeIcon />
566566
</Tooltip>
567567
)}
568568
</Td>
569569
<Td dataLabel={columnNames.image}>
570-
{workspace.pod_template.options.image_config.current.display_name}
570+
{workspace.podTemplate.options.imageConfig.current.displayName}
571571
</Td>
572572
<Td data-testid="pod-config" dataLabel={columnNames.podConfig}>
573-
{workspace.pod_template.options.pod_config.current.display_name}
573+
{workspace.podTemplate.options.podConfig.current.displayName}
574574
</Td>
575575
<Td data-testid="state-label" dataLabel={columnNames.state}>
576576
<Label color={stateColors[workspace.state]}>{workspace.state}</Label>{' '}
577577
</Td>
578578
<Td dataLabel={columnNames.homeVol}>
579-
{workspace.pod_template.volumes.home.pvc_name}
579+
{workspace.podTemplate.volumes.home.pvcName}
580580
</Td>
581581
<Td dataLabel={columnNames.cpu}>{formatCPU(getCpuValue(workspace))}</Td>
582582
<Td dataLabel={columnNames.ram}>{formatRam(getRamValue(workspace))}</Td>
583583
<Td dataLabel={columnNames.lastActivity}>
584584
<Timestamp
585-
date={new Date(workspace.activity.last_activity)}
585+
date={new Date(workspace.activity.lastActivity)}
586586
tooltip={{ variant: TimestampTooltipVariant.default }}
587587
>
588588
1 hour ago

0 commit comments

Comments
 (0)