Skip to content

Commit 9a76f73

Browse files
committed
ARTESCA-15417 // Fix issue with volume already exists
1 parent fce82e5 commit 9a76f73

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed

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

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,32 @@ describe('Metalk8sLocalVolumeProvider', () => {
372372

373373
it('should raise an error if volume creation fails', async () => {
374374
//S
375+
(mockCoreV1Api.listNode as jest.Mock).mockResolvedValue({
376+
body: {
377+
apiVersion: 'v1',
378+
kind: 'NodeList',
379+
items: [
380+
{
381+
metadata: {
382+
name: 'test-node',
383+
},
384+
status: {
385+
addresses: [{ type: 'InternalIP', address: '192.168.1.100' }],
386+
},
387+
},
388+
],
389+
},
390+
});
375391
(
376392
mockCustomObjectsApi.createClusterCustomObject as jest.Mock
377-
).mockRejectedValue(new Error('Error'));
393+
).mockResolvedValue({
394+
error: {
395+
message: 'Error',
396+
body: {
397+
code: 500,
398+
},
399+
},
400+
});
378401
//E+V
379402
await expect(
380403
provider.attachHardwareVolume({
@@ -399,5 +422,49 @@ describe('Metalk8sLocalVolumeProvider', () => {
399422
}),
400423
).rejects.toThrow('Failed to fetch nodes: Error');
401424
});
425+
426+
it('should return volume info if volume already exists (409 conflict)', async () => {
427+
//S
428+
(mockCoreV1Api.listNode as jest.Mock).mockResolvedValue({
429+
body: {
430+
apiVersion: 'v1',
431+
kind: 'NodeList',
432+
items: [
433+
{
434+
metadata: {
435+
name: 'test-node',
436+
},
437+
status: {
438+
addresses: [{ type: 'InternalIP', address: '192.168.1.100' }],
439+
},
440+
},
441+
],
442+
},
443+
});
444+
(
445+
mockCustomObjectsApi.createClusterCustomObject as jest.Mock
446+
).mockResolvedValue({
447+
error: {
448+
body: {
449+
code: 409,
450+
},
451+
message: 'Volume already exists',
452+
},
453+
});
454+
//E
455+
const result = await provider.attachHardwareVolume({
456+
IP: '192.168.1.100',
457+
devicePath: '/dev/sda',
458+
type: HardwareDiskType.SATA,
459+
});
460+
//V
461+
expect(result).toEqual({
462+
IP: '192.168.1.100',
463+
devicePath: '/dev/sda',
464+
nodeName: 'test-node',
465+
volumeType: VolumeType.Hardware,
466+
volumeName: 'storage-data-192.168.1.100-dev-sda',
467+
});
468+
});
402469
});
403470
});

ui/src/services/k8s/Metalk8sLocalVolumeProvider.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,17 @@ export default class Metalk8sLocalVolumeProvider {
258258
},
259259
},
260260
});
261+
262+
if (isError(volume) && volume.error.body.code === 409) {
263+
return {
264+
IP,
265+
devicePath,
266+
nodeName,
267+
volumeType: VolumeType.Hardware,
268+
volumeName,
269+
};
270+
}
271+
261272
if (isError(volume)) {
262273
throw new Error(
263274
`Failed to attach hardware volume: ${volume.error.message}`,

0 commit comments

Comments
 (0)