Skip to content

Commit 86ef032

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 b4448db commit 86ef032

File tree

6 files changed

+220
-89
lines changed

6 files changed

+220
-89
lines changed
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.pod_config.current);
19+
.should('have.text', workspace.pod_template.options.pod_config.current.display_name);
2020
};
2121

2222
// Test suite for workspace-related tests

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

Lines changed: 90 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,57 @@ const generateMockWorkspace = (
66
namespace: string,
77
state: WorkspaceState,
88
paused: boolean,
9-
imageConfig: string,
10-
podConfig: string,
9+
imageConfigId: string,
10+
imageConfigDisplayName: string,
11+
podConfigId: string,
12+
podConfigDisplayName: string,
1113
pvcName: string,
12-
): Workspace => {
14+
): {
15+
name: string;
16+
namespace: string;
17+
workspace_kind: { name: string };
18+
defer_updates: boolean;
19+
paused: boolean;
20+
paused_time: number;
21+
state: WorkspaceState;
22+
state_message: string;
23+
pod_template: {
24+
pod_metadata: { labels: {}; annotations: {} };
25+
volumes: {
26+
home: { pvc_name: string; mount_path: string; readOnly: boolean };
27+
data: { pvc_name: string; mount_path: string; readOnly: boolean }[];
28+
};
29+
options: {
30+
image_config: {
31+
current: {
32+
id: string;
33+
display_name: string;
34+
description: string;
35+
labels: { key: string; value: string }[];
36+
};
37+
};
38+
pod_config: {
39+
current: {
40+
id: string;
41+
display_name: string;
42+
description: string;
43+
labels: ({ key: string; value: string } | { key: string; value: string })[];
44+
};
45+
};
46+
};
47+
image_config: { current: string; desired: string; redirect_chain: any[] };
48+
pod_config: { current: string; desired: string; redirect_chain: any[] };
49+
};
50+
activity: { last_activity: number; last_update: number };
51+
} => {
1352
const currentTime = Date.now();
14-
const lastActivityTime = currentTime - Math.floor(Math.random() * 1000000); // Random last activity time
15-
const lastUpdateTime = currentTime - Math.floor(Math.random() * 100000); // Random last update time
53+
const lastActivityTime = currentTime - Math.floor(Math.random() * 1000000);
54+
const lastUpdateTime = currentTime - Math.floor(Math.random() * 100000);
1655

1756
return {
1857
name,
1958
namespace,
20-
workspace_kind: {
21-
name: 'jupyterlab',
22-
},
59+
workspace_kind: { name: 'jupyterlab' },
2360
defer_updates: paused,
2461
paused,
2562
paused_time: paused ? currentTime - Math.floor(Math.random() * 1000000) : 0,
@@ -45,41 +82,60 @@ const generateMockWorkspace = (
4582
{
4683
pvc_name: pvcName,
4784
mount_path: '/data/my-data',
48-
readOnly: paused, // Set based on the paused state
85+
readOnly: paused,
4986
},
5087
],
5188
},
89+
options: {
90+
image_config: {
91+
current: {
92+
id: imageConfigId,
93+
display_name: imageConfigDisplayName,
94+
description: 'JupyterLab environment',
95+
labels: [{ key: 'python_version', value: '3.11' }],
96+
},
97+
},
98+
pod_config: {
99+
current: {
100+
id: podConfigId,
101+
display_name: podConfigDisplayName,
102+
description: 'Pod configuration with resource limits',
103+
labels: [
104+
{ key: 'cpu', value: '100m' },
105+
{ key: 'memory', value: '128Mi' },
106+
],
107+
},
108+
},
109+
},
52110
image_config: {
53-
current: imageConfig,
111+
current: imageConfigId,
54112
desired: '',
55113
redirect_chain: [],
56114
},
57115
pod_config: {
58-
current: podConfig,
59-
desired: podConfig,
116+
current: podConfigId,
117+
desired: podConfigId,
60118
redirect_chain: [],
61119
},
62120
},
63121
activity: {
64122
last_activity: lastActivityTime,
65123
last_update: lastUpdateTime,
66-
last_probe: {
67-
start_time_ms: lastUpdateTime - 1000, // Simulated probe timing
68-
end_time_ms: lastUpdateTime,
69-
result: 'default_result',
70-
message: 'default_message',
71-
},
72124
},
73125
};
74126
};
75127

76128
const generateMockWorkspaces = (numWorkspaces: number, byNamespace = false) => {
77129
const mockWorkspaces = [];
78-
const podConfigs = ['Small CPU', 'Medium CPU', 'Large CPU'];
130+
const podConfigs = [
131+
{ id: 'small-cpu', display_name: 'Small CPU' },
132+
{ id: 'medium-cpu', display_name: 'Medium CPU' },
133+
{ id: 'large-cpu', display_name: 'Large CPU' },
134+
];
79135
const imageConfigs = [
80-
'jupyterlab_scipy_180',
81-
'jupyterlab_tensorflow_230',
82-
'jupyterlab_pytorch_120',
136+
{ id: 'jupyterlab_scipy_180', display_name: 'JupyterLab SciPy 1.8.0' },
137+
{ id: 'jupyterlab_tensorflow_230', display_name: 'JupyterLab TensorFlow 2.3.0' },
138+
{ id: 'jupyterlab_pytorch_120', display_name: 'JupyterLab PyTorch 1.2.0' },
83139
];
84140
const namespaces = byNamespace ? ['kubeflow'] : ['kubeflow', 'system', 'user-example', 'default'];
85141

@@ -94,11 +150,22 @@ const generateMockWorkspaces = (numWorkspaces: number, byNamespace = false) => {
94150
const name = `workspace-${i}`;
95151
const namespace = namespaces[i % namespaces.length];
96152
const pvcName = `data-pvc-${i}`;
153+
97154
const imageConfig = imageConfigs[i % imageConfigs.length];
98155
const podConfig = podConfigs[i % podConfigs.length];
99156

100157
mockWorkspaces.push(
101-
generateMockWorkspace(name, namespace, state, paused, imageConfig, podConfig, pvcName),
158+
generateMockWorkspace(
159+
name,
160+
namespace,
161+
state,
162+
paused,
163+
imageConfig.id,
164+
imageConfig.display_name,
165+
podConfig.id,
166+
podConfig.display_name,
167+
pvcName,
168+
),
102169
);
103170
}
104171

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

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ import { WorkspaceStartActionModal } from '~/app/pages/Workspaces/workspaceActio
5151
import { WorkspaceRestartActionModal } from '~/app/pages/Workspaces/workspaceActions/WorkspaceRestartActionModal';
5252
import { WorkspaceStopActionModal } from '~/app/pages/Workspaces/workspaceActions/WorkspaceStopActionModal';
5353
import Filter, { FilteredColumn } from 'shared/components/Filter';
54-
import { formatRam } from 'shared/utilities/WorkspaceUtils';
54+
import { formatRam, formatCPU } from 'shared/utilities/WorkspaceResources';
55+
import { formatRam } from 'shared/utilities/WorkspaceUtils'; //check if still exist
5556

5657
export enum ActionType {
5758
ViewDetails,
@@ -158,9 +159,17 @@ export const Workspaces: React.FunctionComponent = () => {
158159
case columnNames.kind:
159160
return workspace.workspace_kind.name.search(searchValueInput) >= 0;
160161
case columnNames.image:
161-
return workspace.pod_template.image_config.current.search(searchValueInput) >= 0;
162+
return (
163+
workspace.pod_template.options.image_config.current.display_name.search(
164+
searchValueInput,
165+
) >= 0
166+
);
162167
case columnNames.podConfig:
163-
return workspace.pod_template.pod_config.current.search(searchValueInput) >= 0;
168+
return (
169+
workspace.pod_template.options.pod_config.current.display_name.search(
170+
searchValueInput,
171+
) >= 0
172+
);
164173
case columnNames.state:
165174
return WorkspaceState[workspace.state].search(searchValueInput) >= 0;
166175
case columnNames.homeVol:
@@ -183,12 +192,12 @@ export const Workspaces: React.FunctionComponent = () => {
183192
redirectStatus: '',
184193
name: workspace.name,
185194
kind: workspace.workspace_kind.name,
186-
image: workspace.pod_template.image_config.current,
195+
image: workspace.pod_template.options.image_config.current.display_name,
187196
podConfig: workspace.pod_template.pod_config.current,
188197
state: workspace.state,
189198
homeVol: workspace.pod_template.volumes.home.pvc_name,
190-
cpu: workspace.cpu,
191-
ram: workspace.ram,
199+
cpu: getCpuValue(workspace),
200+
ram: getRamValue(workspace),
192201
lastActivity: workspace.activity.last_activity,
193202
};
194203
return [redirectStatus, name, kind, image, podConfig, state, homeVol, cpu, ram, lastActivity];
@@ -427,6 +436,14 @@ export const Workspaces: React.FunctionComponent = () => {
427436
</>
428437
);
429438

439+
const getCpuValue = (workspace: Workspace): string =>
440+
workspace.pod_template.options.pod_config.current.labels.find((label) => label.key === 'cpu')
441+
?.value || 'N/A';
442+
443+
const getRamValue = (workspace: Workspace): string =>
444+
workspace.pod_template.options.pod_config.current.labels.find((label) => label.key === 'memory')
445+
?.value || 'N/A';
446+
430447
return (
431448
<Drawer
432449
isInline

workspaces/frontend/src/shared/types.ts

Lines changed: 63 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
export interface WorkspaceIcon {
2-
url: string;
2+
url: string;
33
}
44

55
export interface WorkspaceLogo {
6-
url: string;
6+
url: string;
77
}
88

99
export interface WorkspaceKind {
@@ -67,68 +67,79 @@ export interface WorkspaceKind {
6767
}
6868

6969
export enum WorkspaceState {
70-
Running,
71-
Terminating,
72-
Paused,
73-
Pending,
74-
Error,
75-
Unknown,
76-
}
77-
78-
export interface WorkspaceStatus {
79-
activity: {
80-
lastActivity: number;
81-
lastUpdate: number;
82-
};
83-
pauseTime: number;
84-
pendingRestart: boolean;
85-
podTemplateOptions: {
86-
imageConfig: {
87-
desired: string;
88-
redirectChain: {
89-
source: string;
90-
target: string;
91-
}[];
92-
};
93-
};
94-
state: WorkspaceState;
95-
stateMessage: string;
70+
Running,
71+
Terminating,
72+
Paused,
73+
Pending,
74+
Error,
75+
Unknown,
9676
}
9777

9878
export interface Workspace {
9979
name: string;
10080
namespace: string;
81+
workspace_kind: WorkspaceKind;
82+
defer_updates: boolean;
10183
paused: boolean;
102-
deferUpdates: boolean;
103-
kind: string;
104-
cpu: number;
105-
ram: number;
106-
podTemplate: {
107-
podMetadata: {
108-
labels: string[];
109-
annotations: string[];
84+
paused_time: number;
85+
state: WorkspaceState;
86+
state_message: string;
87+
pod_template: {
88+
pod_metadata: {
89+
labels: Record<string, string>;
90+
annotations: Record<string, string>;
11091
};
11192
volumes: {
112-
home: string;
93+
home: {
94+
pvc_name: string;
95+
mount_path: string;
96+
readOnly: boolean;
97+
};
11398
data: {
114-
pvcName: string;
115-
mountPath: string;
99+
pvc_name: string;
100+
mount_path: string;
116101
readOnly: boolean;
117102
}[];
118103
};
119-
endpoints: {
120-
displayName: string;
121-
port: string;
122-
}[];
123-
};
124-
options: {
125-
imageConfig: string;
126-
podConfig: string;
104+
options: {
105+
image_config: {
106+
current: {
107+
id: string;
108+
display_name: string;
109+
description: string;
110+
labels: {
111+
key: string;
112+
value: number;
113+
}[];
114+
};
115+
};
116+
pod_config: {
117+
current: {
118+
id: string;
119+
display_name: string;
120+
description: string;
121+
labels: {
122+
key: string;
123+
value: string;
124+
}[];
125+
};
126+
};
127+
};
128+
image_config: {
129+
current: string;
130+
desired: string;
131+
redirect_chain: string[];
132+
};
133+
pod_config: {
134+
current: string;
135+
desired: string;
136+
redirect_chain: string[];
137+
};
127138
};
128-
status: WorkspaceStatus;
129-
redirectStatus: {
130-
level: 'Info' | 'Warning' | 'Danger';
131-
text: string;
139+
140+
activity: {
141+
last_activity: number;
142+
last_update: number;
132143
};
133144
}
134145

@@ -143,4 +154,4 @@ export type WorkspacesColumnNames = {
143154
ram: string;
144155
lastActivity: string;
145156
redirectStatus: string;
146-
};
157+
};

0 commit comments

Comments
 (0)