Skip to content

Commit 04e4138

Browse files
committed
Enhance Metalk8sLocalVolumeProvider to support additional volume types and improve error handling in volume listing
1 parent 48eb00c commit 04e4138

File tree

3 files changed

+51
-24
lines changed

3 files changed

+51
-24
lines changed

ui/rspack.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,12 @@ const config: Configuration = {
155155
{
156156
from: path.resolve(__dirname, 'build/static/js/@mf-types.zip'),
157157
to: '@mf-types.zip',
158+
noErrorOnMissing: true,
158159
},
159160
{
160161
from: path.resolve(__dirname, 'build/static/js/@mf-types.d.ts'),
161162
to: '@mf-types.d.ts',
163+
noErrorOnMissing: true,
162164
},
163165
],
164166
}),

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

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jest.mock('../k8s/api', () => ({
77
updateApiServerConfig: jest.fn(),
88
}));
99

10-
describe('K8SLocalVolumeProvider', () => {
10+
describe('Metalk8sLocalVolumeProvider', () => {
1111
let provider: Metalk8sLocalVolumeProvider;
1212
const mockUrl = 'mock-url';
1313
const mockToken = 'mock-token';
@@ -77,17 +77,43 @@ describe('K8SLocalVolumeProvider', () => {
7777
rawBlockDevice: { devicePath: '/dev/sda' },
7878
},
7979
},
80+
{
81+
metadata: { name: 'test-lvm' },
82+
spec: {
83+
nodeName: 'test-node',
84+
lvmLogicalVolume: { vgName: 'test-lvm', size: '10Gi' },
85+
},
86+
},
87+
{
88+
metadata: { name: 'test-sparseLoop' },
89+
spec: {
90+
nodeName: 'test-node',
91+
sparseLoopDevice: {
92+
size: '1Gi',
93+
},
94+
},
95+
},
8096
],
8197
},
8298
});
8399

84100
const volumes = await provider.listLocalPersistentVolumes('test-node');
85101

86-
expect(volumes).toHaveLength(1);
102+
expect(volumes).toHaveLength(3);
87103
expect(volumes[0]).toMatchObject({
88104
IP: '192.168.1.100',
89105
devicePath: '/dev/sda',
90-
metadata: { name: 'test-volume' },
106+
nodeName: 'test-node',
107+
});
108+
expect(volumes[1]).toMatchObject({
109+
IP: '192.168.1.100',
110+
devicePath: 'test-lvm',
111+
nodeName: 'test-node',
112+
});
113+
expect(volumes[2]).toMatchObject({
114+
IP: '192.168.1.100',
115+
devicePath: 'test-sparseLoop',
116+
nodeName: 'test-node',
91117
});
92118
});
93119

ui/src/services/k8s/Metalk8sLocalVolumeProvider.ts

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ export default class Metalk8sLocalVolumeProvider
2626
{
2727
volumeClient: Metalk8sV1alpha1VolumeClient;
2828
k8sClient: CoreV1Api;
29-
constructor(private url: string, private token: string) {
29+
constructor(url: string, token: string) {
3030
const { coreV1, customObjects } = ApiK8s.updateApiServerConfig(url, token);
3131
this.volumeClient = new Metalk8sV1alpha1VolumeClient(customObjects);
3232
this.k8sClient = coreV1;
3333
}
34-
public async listLocalPersistentVolumes(
34+
public listLocalPersistentVolumes = async (
3535
serverName: string,
36-
): Promise<LocalPersistentVolume[]> {
36+
): Promise<LocalPersistentVolume[]> => {
3737
try {
3838
const nodes = await this.k8sClient.listNode();
3939
const nodeIP = nodes.body.items
@@ -52,23 +52,22 @@ export default class Metalk8sLocalVolumeProvider
5252
);
5353
const pv = await this.k8sClient.listPersistentVolume();
5454

55-
const localPv: LocalPersistentVolume[] = nodeVolumes.reduce(
56-
(acc, item) => {
57-
const isLocalPv = pv.body.items.find(
58-
(p) => p.metadata.name === item.metadata['name'],
59-
);
60-
return [
61-
...acc,
62-
{
63-
...isLocalPv,
64-
IP: nodeIP.address,
65-
devicePath: item.spec?.rawBlockDevice?.devicePath,
66-
nodeName: item.spec.nodeName,
67-
},
68-
];
69-
},
70-
[],
71-
);
55+
const localPv = nodeVolumes.reduce((acc, item) => {
56+
const isLocalPv = pv.body.items.find(
57+
(p) => p.metadata.name === item.metadata['name'],
58+
);
59+
60+
return [
61+
...acc,
62+
{
63+
...isLocalPv,
64+
IP: nodeIP.address,
65+
devicePath:
66+
item.spec?.rawBlockDevice?.devicePath || item.metadata['name'],
67+
nodeName: item.spec.nodeName,
68+
},
69+
];
70+
}, [] as LocalPersistentVolume[]);
7271

7372
return localPv;
7473
} else {
@@ -79,5 +78,5 @@ export default class Metalk8sLocalVolumeProvider
7978
`Failed to fetch local persistent volumes: ${error.message}`,
8079
);
8180
}
82-
}
81+
};
8382
}

0 commit comments

Comments
 (0)