mirror of
https://github.com/biersoeckli/QuickStack.git
synced 2026-01-01 17:20:14 -06:00
volume show used storage ==> not yet working
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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 }: {
|
||||
|
||||
2
src/server/adapter/longhorn-api.adapter.ts
Normal file
2
src/server/adapter/longhorn-api.adapter.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
const LONGHORN_API_URL = 'http://longhorn-frontend.longhorn-system.svc.cluster.local';
|
||||
export default LONGHORN_API_URL;
|
||||
29
src/server/services/pvc.status.service.ts
Normal file
29
src/server/services/pvc.status.service.ts
Normal 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;
|
||||
Reference in New Issue
Block a user