volume show used storage ==> not yet working

This commit is contained in:
stefan.meyer
2024-11-14 18:36:50 +00:00
parent 5e85391dd8
commit 0e54248374
4 changed files with 40 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ import appService from "@/server/services/app.service";
import { getAuthUserSession, saveFormAction, simpleAction } from "@/server/utils/action-wrapper.utils";
import { z } from "zod";
import { ServiceException } from "@/model/service.exception.model";
import pvcStatusService from "@/server/services/pvc.status.service";
const actionAppVolumeEditZodModel = appVolumeEditZodModel.merge(z.object({
appId: z.string(),
@@ -32,3 +33,9 @@ export const deleteVolume = async (volumeID: string) =>
await appService.deleteVolumeById(volumeID);
return new SuccessActionResult(undefined, 'Successfully deleted volume');
});
export const getPvcUsage = async (pvcName: string, pvcNamespace: string) =>
simpleAction(async () => {
await getAuthUserSession();
return await pvcStatusService.getPvcUsageByName(pvcName, pvcNamespace);
});

View File

@@ -25,6 +25,8 @@ import { CheckIcon, CrossIcon, DeleteIcon, EditIcon, TrashIcon, XIcon } from "lu
import DialogEditDialog from "./storage-edit-overlay";
import { Toast } from "@/lib/toast.utils";
import { deleteVolume } from "./actions";
import { getPvcUsage } from "./actions";
import pvcStatusService from "@/server/services/pvc.status.service";
export default function StorageList({ app }: {

View File

@@ -0,0 +1,2 @@
const LONGHORN_API_URL = 'http://longhorn-frontend.longhorn-system.svc.cluster.local';
export default LONGHORN_API_URL;

View File

@@ -0,0 +1,29 @@
import LONGHORN_API_URL from "../adapter/longhorn-api.adapter";
class PvcStatusService {
async getPvcUsageByName(pvcName: string, pvcNamespace: string) {
try {
// Anfrage an Longhorn API, mit deaktiviertem Cache
const response = await fetch(`${LONGHORN_API_URL}/v1/volumes/${pvcName}`, { cache: 'no-cache' });
// Überprüfen, ob die Antwort erfolgreich ist
if (!response.ok) {
throw new Error(`Failed to fetch data for PVC ${pvcName}: ${response.statusText} (Status Code: ${response.status})`);
}
// Antwortdaten in JSON umwandeln
const volumeData = await response.json();
const actualSize = volumeData.actualSize;
return actualSize;
} catch (error) {
// Fehler protokollieren
console.error(`Error fetching PVC usage for ${pvcName} in namespace ${pvcNamespace}:`, error);
throw error; // Fehler erneut auslösen, falls weitere Behandlung erforderlich ist
}
}
}
const pvcStatusService = new PvcStatusService();
export default pvcStatusService;