Skip to content

Commit 11534d6

Browse files
committed
Merge branch 'w/130.0/improvement/update-localvolumeProvider' into tmp/octopus/q/130.0
2 parents 9b4e8d8 + 212212c commit 11534d6

File tree

3 files changed

+46
-16
lines changed

3 files changed

+46
-16
lines changed

ui/src/services/k8s/Metalk8sLocalVolumeProvider.test.ts

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ describe('Metalk8sLocalVolumeProvider', () => {
2929
listNode: jest.fn(),
3030
listPersistentVolume: jest.fn(),
3131
deletePersistentVolume: jest.fn(),
32+
readPersistentVolume: jest.fn(),
3233
} as unknown as CoreV1Api;
3334

3435
beforeEach(() => {
@@ -232,12 +233,15 @@ describe('Metalk8sLocalVolumeProvider', () => {
232233
expect(result).toBe(false);
233234
});
234235

235-
it('should return true if the volume is provisioned', async () => {
236+
it('should return volume if the volume is provisioned', async () => {
236237
//S
237238
(
238239
mockCustomObjectsApi.getClusterCustomObject as jest.Mock
239240
).mockResolvedValue({
240-
status: { conditions: [{ type: 'Ready', status: 'True' }] },
241+
body: { status: { conditions: [{ type: 'Ready', status: 'True' }] } },
242+
});
243+
(mockCoreV1Api.readPersistentVolume as jest.Mock).mockResolvedValue({
244+
status: { phase: 'Bound' },
241245
});
242246
//E
243247
const result = await provider.isVolumeProvisioned({
@@ -248,22 +252,29 @@ describe('Metalk8sLocalVolumeProvider', () => {
248252
volumeName: 'test-volume',
249253
});
250254
//V
251-
expect(result).toBe(true);
255+
expect(result).toMatchObject({
256+
IP: '192.168.1.100',
257+
devicePath: '/dev/sda',
258+
volumeType: VolumeType.Hardware,
259+
nodeName: 'test-node',
260+
});
252261
});
253262

254263
it('should raise an error if the volume is failed to provisioned', async () => {
255264
//S
256265
(
257266
mockCustomObjectsApi.getClusterCustomObject as jest.Mock
258267
).mockResolvedValue({
259-
status: {
260-
conditions: [
261-
{
262-
type: 'Ready',
263-
status: 'False',
264-
reason: 'Volume is not provisioned',
265-
},
266-
],
268+
body: {
269+
status: {
270+
conditions: [
271+
{
272+
type: 'Ready',
273+
status: 'False',
274+
reason: 'Volume is not provisioned',
275+
},
276+
],
277+
},
267278
},
268279
});
269280
//E+V
@@ -333,6 +344,11 @@ describe('Metalk8sLocalVolumeProvider', () => {
333344
nodeName: 'test-node',
334345
rawBlockDevice: { devicePath: '/dev/sda' },
335346
storageClassName: 'ssd-ext4',
347+
template: {
348+
metadata: {
349+
labels: { 'xcore.scality.com/volume-type': 'data' },
350+
},
351+
},
336352
},
337353
},
338354
);

ui/src/services/k8s/Metalk8sLocalVolumeProvider.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export default class Metalk8sLocalVolumeProvider {
133133

134134
public isVolumeProvisioned = async (
135135
localVolume: LocalVolume,
136-
): Promise<boolean> => {
136+
): Promise<false | LocalPersistentVolume> => {
137137
const volumeName = localVolume.volumeName;
138138

139139
const token = await this.getToken();
@@ -150,7 +150,7 @@ export default class Metalk8sLocalVolumeProvider {
150150
throw new Error(`Failed to get volume ${volumeName}: ${volume.error}`);
151151
}
152152

153-
const volumeStatus = volume.status?.conditions?.find(
153+
const volumeStatus = volume.body?.status?.conditions?.find(
154154
(condition) => condition.type === 'Ready',
155155
);
156156

@@ -169,7 +169,17 @@ export default class Metalk8sLocalVolumeProvider {
169169
}
170170

171171
if (volumeStatus?.status === 'True') {
172-
return true;
172+
const token = await this.getToken();
173+
const { coreV1 } = ApiK8s.updateApiServerConfig(this.apiUrl, token);
174+
const k8sClient = coreV1;
175+
const pv = await k8sClient.readPersistentVolume(volumeName);
176+
return {
177+
...pv.body,
178+
IP: localVolume.IP,
179+
devicePath: localVolume.devicePath,
180+
nodeName: localVolume.nodeName,
181+
volumeType: localVolume.volumeType,
182+
};
173183
}
174184

175185
return false;
@@ -240,6 +250,11 @@ export default class Metalk8sLocalVolumeProvider {
240250
nodeName,
241251
rawBlockDevice: { devicePath },
242252
storageClassName,
253+
template: {
254+
metadata: {
255+
labels: { 'xcore.scality.com/volume-type': 'data' },
256+
},
257+
},
243258
},
244259
});
245260
if (isError(volume)) {

ui/src/services/k8s/Metalk8sVolumeClient.generated.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,8 @@ export class Metalk8sV1alpha1VolumeClient {
237237

238238
async getMetalk8sV1alpha1Volume(
239239
Metalk8sV1alpha1VolumeName: string,
240-
): Promise<Result<Metalk8sV1alpha1Volume>> {
240+
): Promise<Result<{ body: Metalk8sV1alpha1Volume }>> {
241241
try {
242-
// @ts-expect-error - FIXME when you are working on it
243242
return await this.customObjects.getClusterCustomObject(
244243
'storage.metalk8s.scality.com',
245244
'v1alpha1',

0 commit comments

Comments
 (0)