mirror of
https://github.com/biersoeckli/QuickStack.git
synced 2026-05-14 14:03:42 -05:00
Fix volume size
This commit is contained in:
@@ -83,8 +83,8 @@ export default function StorageList({ app }: {
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Mount Path</TableHead>
|
||||
<TableHead>Available Storage</TableHead>
|
||||
<TableHead>Used Storage</TableHead>
|
||||
<TableHead>Storage Size</TableHead>
|
||||
<TableHead>Storage Used</TableHead>
|
||||
<TableHead>Access Mode</TableHead>
|
||||
<TableHead className="w-[100px]">Action</TableHead>
|
||||
</TableRow>
|
||||
|
||||
@@ -2,53 +2,48 @@ import { any, number } from "zod";
|
||||
|
||||
class LonghornApiAdapter {
|
||||
|
||||
async getLonghornVolume(pvcName: String) { //Soll PVC Name und Used Size zurückgeben
|
||||
async getLonghornVolume(pvcName: String) {
|
||||
let longhornApiUrl = process.env.NODE_ENV === 'production' ? 'http://longhorn-frontend.longhorn-system.svc.cluster.local/v1/volumes' : 'http://localhost:4000/v1/volumes';
|
||||
|
||||
// Request senden
|
||||
const response = await fetch(`${longhornApiUrl}/${pvcName}`, {
|
||||
cache: 'no-cache',
|
||||
method: 'GET', // Standardmäßig GET
|
||||
method: 'GET',
|
||||
headers: {
|
||||
|
||||
'Accept': 'application/json', // Optional, falls JSON erwartet wird
|
||||
'Content-Type': 'application/json' // Optional, falls JSON zurückgegeben wird
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
// Überprüfen, ob die Anfrage erfolgreich war
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP-Error: ${response.status}`);
|
||||
}
|
||||
|
||||
// Antwort als JSON parsen
|
||||
const data = await response.json();
|
||||
|
||||
const usedStorage = data.controllers?.[0]?.actualSize;
|
||||
|
||||
return (usedStorage / (1024 * 1024)); // Rückgabe mit Erfolgsfall
|
||||
return (usedStorage / (1024 * 1024));
|
||||
}
|
||||
|
||||
|
||||
async getNodeStorageInfo(nodeName: String) { //Soll PVC Name und Used Size zurückgeben
|
||||
async getNodeStorageInfo(nodeName: String) {
|
||||
let longhornApiUrl = process.env.NODE_ENV === 'production' ? 'http://longhorn-frontend.longhorn-system.svc.cluster.local/v1/nodes' : 'http://localhost:4000/v1/nodes';
|
||||
// Request senden
|
||||
|
||||
const response = await fetch(`${longhornApiUrl}/${nodeName}`, {
|
||||
cache: 'no-cache',
|
||||
method: 'GET', // Standardmäßig GET
|
||||
method: 'GET',
|
||||
headers: {
|
||||
|
||||
'Accept': 'application/json', // Optional, falls JSON erwartet wird
|
||||
'Content-Type': 'application/json' // Optional, falls JSON zurückgegeben wird
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
// Überprüfen, ob die Anfrage erfolgreich war
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP-Error: ${response.status}`);
|
||||
}
|
||||
|
||||
// Antwort als JSON parsen
|
||||
const data = await response.json() as {
|
||||
disks: {
|
||||
[key: string]: {
|
||||
@@ -62,11 +57,9 @@ class LonghornApiAdapter {
|
||||
throw new Error("Invalid node data: 'disks' property is missing or not an object.");
|
||||
}
|
||||
|
||||
// Initialize totals
|
||||
let totalStorageMaximum = 0;
|
||||
let totalStorageAvailable = 0;
|
||||
|
||||
// Iterate over each disk and sum up the values
|
||||
Object.values(data.disks).forEach(disk => {
|
||||
|
||||
totalStorageMaximum += disk.storageMaximum;
|
||||
|
||||
@@ -56,17 +56,9 @@ class PvcService {
|
||||
const volumeName = pvc.spec?.volumeName;
|
||||
|
||||
if (pvcName && volumeName) {
|
||||
try {
|
||||
// Rufe Speicherverbrauchsdaten von getLonghornVolume ab
|
||||
const usage = await longhornApiAdapter.getLonghornVolume(volumeName);
|
||||
console.log(usage)
|
||||
// Füge die Daten in das Array ein
|
||||
pvcUsageData.push({ pvcName, usage });
|
||||
} catch (error) {
|
||||
console.error(`Fehler beim Abrufen der Daten für PVC ${pvcName} und Volume ${volumeName}:`, error);
|
||||
}
|
||||
} else {
|
||||
console.warn(`PVC ${pvc.metadata?.name} hat keinen gültigen Namen oder Volume-Namen.`);
|
||||
|
||||
const usage = await longhornApiAdapter.getLonghornVolume(volumeName);
|
||||
pvcUsageData.push({ pvcName, usage });
|
||||
}
|
||||
}
|
||||
return pvcUsageData;
|
||||
|
||||
Reference in New Issue
Block a user