feat: volume details

This commit is contained in:
Nicolas Meienberger
2025-09-07 16:08:08 +02:00
parent aa82f95c56
commit 833bcb590f
13 changed files with 280 additions and 153 deletions

View File

@@ -22,10 +22,16 @@ const mount = async (config: BackendConfig, path: string) => {
const cmd = `mount -t nfs -o ${options.join(",")} ${source} ${path}`;
return new Promise<void>((resolve, reject) => {
const timeout = setTimeout(() => {
reject(new Error("Mount command timed out"));
}, 5000);
exec(cmd, (error, stdout, stderr) => {
console.log("Mount command executed:", { cmd, error, stdout, stderr });
clearTimeout(timeout);
if (error) {
// console.error(`Error mounting NFS volume: ${stderr}`);
console.error(`Error mounting NFS volume: ${stderr}`);
return reject(new Error(`Failed to mount NFS volume: ${stderr}`));
}
console.log(`NFS volume mounted successfully: ${stdout}`);
@@ -43,8 +49,14 @@ const unmount = async (path: string) => {
const cmd = `umount -f ${path}`;
return new Promise<void>((resolve, reject) => {
const timeout = setTimeout(() => {
reject(new Error("Mount command timed out"));
}, 5000);
exec(cmd, (error, stdout, stderr) => {
console.log("Unmount command executed:", { cmd, error, stdout, stderr });
clearTimeout(timeout);
if (error) {
console.error(`Error unmounting NFS volume: ${stderr}`);
return reject(new Error(`Failed to unmount NFS volume: ${stderr}`));

View File

@@ -12,6 +12,7 @@ import {
testConnectionDto,
updateVolumeBody,
updateVolumeDto,
type VolumeDto,
} from "./volume.dto";
import { volumeService } from "./volume.service";
@@ -68,13 +69,11 @@ export const volumeController = new Hono()
}
const response = {
name: res.volume.name,
path: res.volume.path,
type: res.volume.type,
...res.volume,
createdAt: res.volume.createdAt.getTime(),
updatedAt: res.volume.updatedAt.getTime(),
config: res.volume.config,
};
lastHealthCheck: res.volume.lastHealthCheck.getTime(),
} satisfies VolumeDto;
return c.json(response, 200);
})

View File

@@ -15,6 +15,8 @@ const volumeSchema = type({
config: volumeConfigSchema,
});
export type VolumeDto = typeof volumeSchema.infer;
/**
* List all volumes
*/

View File

@@ -108,25 +108,17 @@ const updateVolume = async (name: string, backendConfig: BackendConfig) => {
return { error: new NotFoundError("Volume not found") };
}
const oldBackend = createVolumeBackend(existing);
await oldBackend.unmount().catch((err) => {
console.warn("Failed to unmount backend:", err);
});
const updated = await db
.update(volumesTable)
.set({
config: backendConfig,
type: backendConfig.backend,
updatedAt: new Date(),
status: "unmounted",
})
.where(eq(volumesTable.name, name))
.returning();
// Mount with new configuration
const newBackend = createVolumeBackend(updated[0]);
await newBackend.mount();
return { volume: updated[0] };
} catch (error) {
return {