Compare commits

..

4 Commits

Author SHA1 Message Date
c25d277abf save style 2025-06-10 13:17:49 +03:00
2715353d14 MUI 2025-06-10 09:10:27 +03:00
69ad5b657a Change title color 2025-06-10 09:02:02 +03:00
cdf7e40005 Create branch style 2025-06-10 03:15:14 +03:00
17 changed files with 220 additions and 259 deletions

1
backend/.gitignore vendored
View File

@ -1 +0,0 @@
__pycache__

View File

@ -1,6 +1,5 @@
import subprocess import subprocess
import json import json
import re
def get_namespaces(): def get_namespaces():
output = subprocess.check_output(["kubectl", "get", "ns", "-o", "json"]) output = subprocess.check_output(["kubectl", "get", "ns", "-o", "json"])
@ -11,18 +10,3 @@ def get_pvcs(namespace: str):
output = subprocess.check_output(["kubectl", "get", "pvc", "-n", namespace, "-o", "json"]) output = subprocess.check_output(["kubectl", "get", "pvc", "-n", namespace, "-o", "json"])
data = json.loads(output) data = json.loads(output)
return [item["metadata"]["name"] for item in data["items"]] return [item["metadata"]["name"] for item in data["items"]]
def get_all_backup_pvcs():
output = subprocess.check_output(["kubectl", "get", "pvc", "-A", "-o", "json"])
data = json.loads(output)
backup_pvcs = []
for item in data["items"]:
name = item["metadata"]["name"]
namespace = item["metadata"]["namespace"]
if re.match(r"^snapix-bkp-temp-", name):
backup_pvcs.append({
"name": name,
"namespace": namespace
})
return backup_pvcs

View File

@ -1,7 +1,7 @@
from fastapi import FastAPI from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware from fastapi.middleware.cors import CORSMiddleware
from models import BackupRequest, RestoreRequest from models import BackupRequest, RestoreRequest
from k8s_utils import get_namespaces, get_pvcs, get_all_backup_pvcs from k8s_utils import get_namespaces, get_pvcs
from backup_manager import create_backup, restore_backup from backup_manager import create_backup, restore_backup
app = FastAPI() app = FastAPI()
@ -33,11 +33,6 @@ def restore_pvc(request: RestoreRequest):
return {"message": "Restore job created."} return {"message": "Restore job created."}
@app.get("/backup-pvcs")
def list_backup_pvcs():
return get_all_backup_pvcs()
if __name__ == "__main__": if __name__ == "__main__":
import uvicorn import uvicorn
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True) uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)

View File

@ -11,8 +11,8 @@
"@emotion/react": "^11.14.0", "@emotion/react": "^11.14.0",
"@emotion/styled": "^11.14.0", "@emotion/styled": "^11.14.0",
"@mui/base": "^5.0.0-beta.70", "@mui/base": "^5.0.0-beta.70",
"@mui/icons-material": "^7.1.1",
"@mui/material": "^7.1.1", "@mui/material": "^7.1.1",
"@mui/styled-engine": "^7.1.1",
"axios": "^1.9.0", "axios": "^1.9.0",
"react": "^19.1.0", "react": "^19.1.0",
"react-dom": "^19.1.0" "react-dom": "^19.1.0"
@ -1054,6 +1054,31 @@
"url": "https://opencollective.com/mui-org" "url": "https://opencollective.com/mui-org"
} }
}, },
"node_modules/@mui/icons-material": {
"version": "7.1.1",
"resolved": "https://registry.npmjs.org/@mui/icons-material/-/icons-material-7.1.1.tgz",
"integrity": "sha512-X37+Yc8QpEnl0sYmz+WcLFy2dWgNRzbswDzLPXG7QU1XDVlP5TPp1HXjdmCupOWLL/I9m1fyhcyZl8/HPpp/Cg==",
"dependencies": {
"@babel/runtime": "^7.27.1"
},
"engines": {
"node": ">=14.0.0"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/mui-org"
},
"peerDependencies": {
"@mui/material": "^7.1.1",
"@types/react": "^17.0.0 || ^18.0.0 || ^19.0.0",
"react": "^17.0.0 || ^18.0.0 || ^19.0.0"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@mui/material": { "node_modules/@mui/material": {
"version": "7.1.1", "version": "7.1.1",
"resolved": "https://registry.npmjs.org/@mui/material/-/material-7.1.1.tgz", "resolved": "https://registry.npmjs.org/@mui/material/-/material-7.1.1.tgz",

View File

@ -13,8 +13,8 @@
"@emotion/react": "^11.14.0", "@emotion/react": "^11.14.0",
"@emotion/styled": "^11.14.0", "@emotion/styled": "^11.14.0",
"@mui/base": "^5.0.0-beta.70", "@mui/base": "^5.0.0-beta.70",
"@mui/icons-material": "^7.1.1",
"@mui/material": "^7.1.1", "@mui/material": "^7.1.1",
"@mui/styled-engine": "^7.1.1",
"axios": "^1.9.0", "axios": "^1.9.0",
"react": "^19.1.0", "react": "^19.1.0",
"react-dom": "^19.1.0" "react-dom": "^19.1.0"

View File

@ -1,36 +1,17 @@
body { .app-wrapper {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
/* Top-level layout container */
.snapix-container {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; /* horizontal center */ align-items: center;
justify-content: center; /* vertical center */
min-height: 100vh;
color: white;
padding: 2rem;
box-sizing: border-box;
}
/* Title styling */
.snapix-title {
text-align: center;
color: white;
margin-bottom: 2rem;
font-size: 2rem;
}
/* Dashboard: backup + restore side by side */
.snapix-dashboard {
display: flex;
justify-content: center; justify-content: center;
align-items: flex-start; min-height: 100vh;
gap: 30px; background-color: #121212;
flex-wrap: wrap; padding: 2rem;
margin: auto; margin: 0 auto;
max-width: 100%;
}
.title {
color: white;
text-align: center;
margin-bottom: 2rem;
} }

View File

@ -1,13 +1,13 @@
import './App.css';
import './style/global.css';
import BackupForm from './components/BackupForm'; import BackupForm from './components/BackupForm';
import RestoreForm from './components/RestoreForm'; import RestoreForm from './components/RestoreForm';
import './App.css';
function App() { function App() {
return ( return (
<div className="snapix-container"> <div className="app-wrapper">
<h1 className="snapix-title">🚀 Snapix Dashboard</h1> <h1 className="title">🚀 Snapix Dashboard</h1>
<div className="snapix-dashboard"> <div className="form-sections">
<BackupForm /> <BackupForm />
<RestoreForm /> <RestoreForm />
</div> </div>

View File

@ -1,12 +0,0 @@
import axios from 'axios';
const api = axios.create({
baseURL: 'http://localhost:8000', // שנה לכתובת האמיתית שלך
});
export const getNamespaces = () => api.get('/namespaces');
export const getPVCs = (namespace) => api.get(`/pvcs/${namespace}`);
export const createBackup = (payload) => api.post('/backup', payload);
export const restoreBackup = (payload) => api.post('/restore', payload);
export const getBackupPVCs = () => api.get('/backup-pvcs');

View File

@ -1,84 +1,74 @@
import { useEffect, useState } from 'react'; import { useState, useEffect } from 'react';
import { getNamespaces, getPVCs, createBackup } from '../api/snapix'; import { getNamespaces, getPVCs, createBackup } from '../service';
import { Button, Input } from '@mui/base'; import '../style/BackupForm.css';
import { Button, Input, Select, Option } from '@mui/base';
export default function BackupForm() { function BackupForm() {
const [namespaces, setNamespaces] = useState([]); const [namespaces, setNamespaces] = useState([]);
const [pvcs, setPvcs] = useState([]); const [pvcs, setPvcs] = useState([]);
const [selectedNs, setSelectedNs] = useState(''); const [namespace, setNamespace] = useState('');
const [selectedPvc, setSelectedPvc] = useState(''); const [pvc, setPvc] = useState('');
const [backupName, setBackupName] = useState(''); const [backupName, setBackupName] = useState('');
useEffect(() => { useEffect(() => {
getNamespaces().then(res => setNamespaces(res.data)); getNamespaces().then(setNamespaces);
}, []); }, []);
useEffect(() => { useEffect(() => {
if (selectedNs) { if (namespace) {
getPVCs(selectedNs).then(res => setPvcs(res.data)); getPVCs(namespace).then(setPvcs);
} else { } else {
setPvcs([]); setPvcs([]);
} }
}, [selectedNs]); }, [namespace]);
const handleSubmit = () => { const handleSubmit = async () => {
if (selectedNs && selectedPvc && backupName) { try {
createBackup({ await createBackup({ namespace, pvcName: pvc, backupName });
namespace: selectedNs, alert('✅ Backup created successfully!');
pvc_name: selectedPvc, } catch (error) {
backup_name: backupName, console.error(error);
}).then(() => { alert('❌ Backup failed');
alert('Backup started!');
setBackupName('');
});
} }
}; };
return ( return (
<div className="form-container BackupForm">
<h3>📦 Create Backup</h3>
<div className="form-group"> <div className="form-group">
<h2>📦 Backup PVC</h2> <label>Namespace</label>
<Select value={namespace} onChange={(e) => setNamespace(e.target.value)}>
<div className="form-content"> <Option value="">-- Select Namespace --</Option>
<label>Namespace:</label> {namespaces.map((ns) => (
<select value={selectedNs} onChange={(e) => setSelectedNs(e.target.value)}> <Option key={ns} value={ns}>{ns}</Option>
<option value="">-- Select Namespace --</option>
{namespaces.map(ns => (
<option key={ns} value={ns}>
{ns}
</option>
))} ))}
</select> </Select>
</div> </div>
<div className="form-content"> <div className="form-group">
<label>PVC:</label> <label>PVC</label>
<select <Select value={pvc} onChange={(e) => setPvc(e.target.value)} disabled={!namespace}>
value={selectedPvc} <Option value="">-- Select PVC --</Option>
onChange={(e) => setSelectedPvc(e.target.value)} {pvcs.map((p) => (
disabled={!selectedNs} <Option key={p} value={p}>{p}</Option>
>
<option value="">-- Select PVC --</option>
{pvcs.map(pvc => (
<option key={pvc} value={pvc}>
{pvc}
</option>
))} ))}
</select> </Select>
</div> </div>
<div className="form-content"> <div className="form-group">
<label>Backup Name:</label> <label>Backup Name</label>
<Input <Input
type="text" type="text"
value={backupName} value={backupName}
onChange={(e) => setBackupName(e.target.value)} onChange={(e) => setBackupName(e.target.value)}
placeholder="e.g. git-bkp"
/> />
</div> </div>
<Button className="btn" onClick={handleSubmit}> <Button className="btn" onClick={handleSubmit} disabled={!namespace || !pvc || !backupName}>
Create Backup Create Backup
</Button> </Button>
</div> </div>
); );
} }
export default BackupForm;

View File

@ -1,84 +1,58 @@
import { useEffect, useState } from 'react'; import { useState } from 'react';
import { restoreBackup, getNamespaces, getBackupPVCs } from '../api/snapix'; import { restoreBackup } from '../service';
import { Button } from '@mui/base';
import '../style/RestoreForm.css'; import '../style/RestoreForm.css';
import { Button, Input } from '@mui/base';
export default function RestoreForm() { function RestoreForm() {
const [namespace, setNamespace] = useState('');
const [targetPVC, setTargetPVC] = useState('');
const [backupName, setBackupName] = useState(''); const [backupName, setBackupName] = useState('');
const [targetNs, setTargetNs] = useState('');
const [targetPvc, setTargetPvc] = useState('');
const [namespaces, setNamespaces] = useState([]);
const [backupPvcs, setBackupPvcs] = useState([]);
useEffect(() => { const handleSubmit = async () => {
getNamespaces().then(res => setNamespaces(res.data)); try {
}, []); await restoreBackup({ namespace, targetPVC, backupName });
alert('✅ Restore completed successfully!');
useEffect(() => { } catch (error) {
if (targetNs) { console.error(error);
getBackupPVCs().then(res => { alert('❌ Restore failed');
// Filter backup PVCs only for the selected namespace
const filtered = res.data.filter(pvc => pvc.namespace === targetNs);
setBackupPvcs(filtered);
});
} else {
setBackupPvcs([]);
}
}, [targetNs]);
const handleRestore = () => {
if (backupName && targetNs && targetPvc) {
restoreBackup({
backup_name: backupName,
target_namespace: targetNs,
target_pvc: targetPvc,
}).then(() => {
alert('Restore started!');
});
} }
}; };
return ( return (
<div className="form-container RestoreForm">
<h3> Restore from Backup</h3>
<div className="form-group"> <div className="form-group">
<h2>🔁 Restore PVC</h2> <label>Namespace</label>
<div className="form-content">
<label>Target Namespace:</label>
<select value={targetNs} onChange={e => setTargetNs(e.target.value)}>
<option value="">-- Select Namespace --</option>
{namespaces.map(ns => (
<option key={ns} value={ns}>{ns}</option>
))}
</select>
</div>
<div className="form-content">
<label>Backup PVC:</label>
<select
value={backupName}
onChange={e => setBackupName(e.target.value)}
disabled={!targetNs}
>
<option value="">-- Select Backup PVC --</option>
{backupPvcs.map(({ name }) => (
<option key={name} value={name}>{name}</option>
))}
</select>
</div>
<div className="form-content">
<label>Target PVC:</label>
<input <input
type="text" type="text"
value={targetPvc} value={namespace}
onChange={e => setTargetPvc(e.target.value)} onChange={(e) => setNamespace(e.target.value)}
placeholder="the exact name of the pvc of your app"
/> />
</div> </div>
<Button id="restore-btn" className="btn" onClick={handleRestore}> <div className="form-group">
<label>Target PVC</label>
<input
type="text"
value={targetPVC}
onChange={(e) => setTargetPVC(e.target.value)}
/>
</div>
<div className="form-group">
<label>Backup Name</label>
<Input
type="text"
value={backupName}
onChange={(e) => setBackupName(e.target.value)}
/>
</div>
<Button className="btn" onClick={handleSubmit} disabled={!namespace || !targetPVC || !backupName}>
Restore Restore
</Button> </Button>
</div> </div>
); );
} }
export default RestoreForm;

View File

@ -1,7 +1,6 @@
import { StrictMode } from 'react' import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client' import { createRoot } from 'react-dom/client'
import './index.css' import './index.css'
import './style/global.css'
import App from './App.jsx' import App from './App.jsx'
createRoot(document.getElementById('root')).render( createRoot(document.getElementById('root')).render(

33
frontend/src/service.js Normal file
View File

@ -0,0 +1,33 @@
const API_BASE = "http://localhost:8000";
export async function getNamespaces() {
const res = await fetch(`${API_BASE}/namespaces`);
if (!res.ok) throw new Error("Failed to fetch namespaces");
return await res.json();
}
export async function getPVCs(namespace) {
const res = await fetch(`${API_BASE}/pvcs/${namespace}`);
if (!res.ok) throw new Error("Failed to fetch PVCs");
return await res.json();
}
export async function createBackup({ namespace, pvcName, backupName }) {
const res = await fetch(`${API_BASE}/backup`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ namespace, pvc_name: pvcName, backup_name: backupName }),
});
if (!res.ok) throw new Error("Failed to create backup");
return await res.json();
}
export async function restoreBackup({ namespace, targetPVC, backupName }) {
const res = await fetch(`${API_BASE}/restore`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ namespace, target_pvc: targetPVC, backup_name: backupName }),
});
if (!res.ok) throw new Error("Failed to restore backup");
return await res.json();
}

View File

@ -0,0 +1,7 @@
.BackupForm {
background: #e3f2fd;
padding: 24px;
border-radius: 8px;
box-shadow: 0 2px 6px rgba(0,0,0,0.2);
color: rgb(0, 0, 0);
}

View File

@ -1,3 +1,7 @@
#restore-btn { .RestoreForm {
background-color: dodgerblue; background: #f1f8e9;
padding: 24px;
border-radius: 8px;
box-shadow: 0 2px 6px rgba(0,0,0,0.2);
color: rgb(0, 0, 0);
} }

View File

@ -1,76 +1,58 @@
h2 { /* Global button style */
text-align: center; .btn {
}
.form-group {
border: 2px solid #ccc;
border-radius: 8px;
padding: 13px;
margin: 10px;
height: auto;
width: 500px;
flex: 1;
max-width: 500px;
min-width: 300px;
}
.form-content {
display: flex;
flex-direction: column;
padding: 10px; padding: 10px;
} font-weight: bold;
background: #1976d2;
/* Unified input/select styling */
input,
select {
width: 100%;
padding: 10px;
background-color: #1a1a1a;
border: 1px solid #444;
border-radius: 8px;
color: white; color: white;
font-size: 1rem; border: none;
box-sizing: border-box; border-radius: 6px;
appearance: none; cursor: pointer;
} }
input:hover, .btn:disabled {
select:hover { background: #ccc;
border-color: #1a73e8;
}
input:disabled,
select:disabled {
opacity: 0.5;
cursor: not-allowed; cursor: not-allowed;
} }
.btn { /* Inputs */
background-color: #4CAF50; input, select {
color: white; padding: 8px;
margin-top: 30px;
padding: 10px 20px;
border: none;
border-radius: 8px;
cursor: pointer;
font-size: 1rem; font-size: 1rem;
} border: 1px solid #ccc;
.btn:hover {
background-color: #45a049;
}
/* Scrollbar inside <select> dropdown (some browsers only) */
select {
scrollbar-color: #666 #1a1a1a;
scrollbar-width: thin;
}
select::-webkit-scrollbar {
width: 6px;
}
select::-webkit-scrollbar-thumb {
background-color: #666;
border-radius: 4px; border-radius: 4px;
} }
/* Shared spacing for forms */
.form-group {
margin-bottom: 16px;
display: flex;
flex-direction: column;
}
.form-group label {
margin-bottom: 4px;
font-weight: 500;
color: #333;
}
.form-sections {
width: 100%;
max-width: 480px;
display: flex;
flex-direction: column;
gap: 2rem;
margin: 0 auto;
}
.form-container {
display: flex;
flex-direction: column;
}
/* .input {
padding: 8px;
font-size: 1rem;
border: 1px solid #ccc;
border-radius: 4px;
background-color: transparent;
} */