Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 970933b4a1 | |||
| bbe2bc4a01 | |||
| 9b5666a72e | |||
| 81ec39d1f0 | |||
| ec145e4531 | |||
| 0e55ff2568 | |||
| 5c6cbb5195 | |||
| ff18c5d6d7 |
1
backend/.gitignore
vendored
Normal file
1
backend/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
__pycache__
|
||||
Binary file not shown.
Binary file not shown.
@ -1,5 +1,6 @@
|
||||
import subprocess
|
||||
import json
|
||||
import re
|
||||
|
||||
def get_namespaces():
|
||||
output = subprocess.check_output(["kubectl", "get", "ns", "-o", "json"])
|
||||
@ -10,3 +11,18 @@ def get_pvcs(namespace: str):
|
||||
output = subprocess.check_output(["kubectl", "get", "pvc", "-n", namespace, "-o", "json"])
|
||||
data = json.loads(output)
|
||||
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
|
||||
@ -1,7 +1,7 @@
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from models import BackupRequest, RestoreRequest
|
||||
from k8s_utils import get_namespaces, get_pvcs
|
||||
from k8s_utils import get_namespaces, get_pvcs, get_all_backup_pvcs
|
||||
from backup_manager import create_backup, restore_backup
|
||||
|
||||
app = FastAPI()
|
||||
@ -33,6 +33,11 @@ def restore_pvc(request: RestoreRequest):
|
||||
return {"message": "Restore job created."}
|
||||
|
||||
|
||||
@app.get("/backup-pvcs")
|
||||
def list_backup_pvcs():
|
||||
return get_all_backup_pvcs()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)
|
||||
27
frontend/package-lock.json
generated
27
frontend/package-lock.json
generated
@ -11,8 +11,8 @@
|
||||
"@emotion/react": "^11.14.0",
|
||||
"@emotion/styled": "^11.14.0",
|
||||
"@mui/base": "^5.0.0-beta.70",
|
||||
"@mui/icons-material": "^7.1.1",
|
||||
"@mui/material": "^7.1.1",
|
||||
"@mui/styled-engine": "^7.1.1",
|
||||
"axios": "^1.9.0",
|
||||
"react": "^19.1.0",
|
||||
"react-dom": "^19.1.0"
|
||||
@ -1054,31 +1054,6 @@
|
||||
"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": {
|
||||
"version": "7.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@mui/material/-/material-7.1.1.tgz",
|
||||
|
||||
@ -13,8 +13,8 @@
|
||||
"@emotion/react": "^11.14.0",
|
||||
"@emotion/styled": "^11.14.0",
|
||||
"@mui/base": "^5.0.0-beta.70",
|
||||
"@mui/icons-material": "^7.1.1",
|
||||
"@mui/material": "^7.1.1",
|
||||
"@mui/styled-engine": "^7.1.1",
|
||||
"axios": "^1.9.0",
|
||||
"react": "^19.1.0",
|
||||
"react-dom": "^19.1.0"
|
||||
|
||||
@ -1,17 +1,36 @@
|
||||
.app-wrapper {
|
||||
body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 100vh;
|
||||
background-color: #121212;
|
||||
padding: 2rem;
|
||||
margin: 0 auto;
|
||||
max-width: 100%;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
.title {
|
||||
/* Top-level layout container */
|
||||
.snapix-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center; /* horizontal center */
|
||||
justify-content: center; /* vertical center */
|
||||
min-height: 100vh;
|
||||
color: white;
|
||||
text-align: center;
|
||||
margin-bottom: 2rem;
|
||||
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;
|
||||
align-items: flex-start;
|
||||
gap: 30px;
|
||||
flex-wrap: wrap;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
import './App.css';
|
||||
import './style/global.css';
|
||||
import BackupForm from './components/BackupForm';
|
||||
import RestoreForm from './components/RestoreForm';
|
||||
import './App.css';
|
||||
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<div className="app-wrapper">
|
||||
<h1 className="title">🚀 Snapix Dashboard</h1>
|
||||
<div className="form-sections">
|
||||
<div className="snapix-container">
|
||||
<h1 className="snapix-title">🚀 Snapix Dashboard</h1>
|
||||
<div className="snapix-dashboard">
|
||||
<BackupForm />
|
||||
<RestoreForm />
|
||||
</div>
|
||||
|
||||
12
frontend/src/api/snapix.js
Normal file
12
frontend/src/api/snapix.js
Normal file
@ -0,0 +1,12 @@
|
||||
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');
|
||||
|
||||
@ -1,74 +1,84 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { getNamespaces, getPVCs, createBackup } from '../service';
|
||||
import '../style/BackupForm.css';
|
||||
import { Button, Input, Select, Option } from '@mui/base';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { getNamespaces, getPVCs, createBackup } from '../api/snapix';
|
||||
import { Button, Input } from '@mui/base';
|
||||
|
||||
function BackupForm() {
|
||||
export default function BackupForm() {
|
||||
const [namespaces, setNamespaces] = useState([]);
|
||||
const [pvcs, setPvcs] = useState([]);
|
||||
const [namespace, setNamespace] = useState('');
|
||||
const [pvc, setPvc] = useState('');
|
||||
const [selectedNs, setSelectedNs] = useState('');
|
||||
const [selectedPvc, setSelectedPvc] = useState('');
|
||||
const [backupName, setBackupName] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
getNamespaces().then(setNamespaces);
|
||||
getNamespaces().then(res => setNamespaces(res.data));
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (namespace) {
|
||||
getPVCs(namespace).then(setPvcs);
|
||||
if (selectedNs) {
|
||||
getPVCs(selectedNs).then(res => setPvcs(res.data));
|
||||
} else {
|
||||
setPvcs([]);
|
||||
}
|
||||
}, [namespace]);
|
||||
}, [selectedNs]);
|
||||
|
||||
const handleSubmit = async () => {
|
||||
try {
|
||||
await createBackup({ namespace, pvcName: pvc, backupName });
|
||||
alert('✅ Backup created successfully!');
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
alert('❌ Backup failed');
|
||||
const handleSubmit = () => {
|
||||
if (selectedNs && selectedPvc && backupName) {
|
||||
createBackup({
|
||||
namespace: selectedNs,
|
||||
pvc_name: selectedPvc,
|
||||
backup_name: backupName,
|
||||
}).then(() => {
|
||||
alert('Backup started!');
|
||||
setBackupName('');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="form-container BackupForm">
|
||||
<h3>📦 Create Backup</h3>
|
||||
<div className="form-group">
|
||||
<label>Namespace</label>
|
||||
<Select value={namespace} onChange={(e) => setNamespace(e.target.value)}>
|
||||
<Option value="">-- Select Namespace --</Option>
|
||||
{namespaces.map((ns) => (
|
||||
<Option key={ns} value={ns}>{ns}</Option>
|
||||
<h2>📦 Backup PVC</h2>
|
||||
|
||||
<div className="form-content">
|
||||
<label>Namespace:</label>
|
||||
<select value={selectedNs} onChange={(e) => setSelectedNs(e.target.value)}>
|
||||
<option value="">-- Select Namespace --</option>
|
||||
{namespaces.map(ns => (
|
||||
<option key={ns} value={ns}>
|
||||
{ns}
|
||||
</option>
|
||||
))}
|
||||
</Select>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label>PVC</label>
|
||||
<Select value={pvc} onChange={(e) => setPvc(e.target.value)} disabled={!namespace}>
|
||||
<Option value="">-- Select PVC --</Option>
|
||||
{pvcs.map((p) => (
|
||||
<Option key={p} value={p}>{p}</Option>
|
||||
<div className="form-content">
|
||||
<label>PVC:</label>
|
||||
<select
|
||||
value={selectedPvc}
|
||||
onChange={(e) => setSelectedPvc(e.target.value)}
|
||||
disabled={!selectedNs}
|
||||
>
|
||||
<option value="">-- Select PVC --</option>
|
||||
{pvcs.map(pvc => (
|
||||
<option key={pvc} value={pvc}>
|
||||
{pvc}
|
||||
</option>
|
||||
))}
|
||||
</Select>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label>Backup Name</label>
|
||||
<div className="form-content">
|
||||
<label>Backup Name:</label>
|
||||
<Input
|
||||
type="text"
|
||||
value={backupName}
|
||||
onChange={(e) => setBackupName(e.target.value)}
|
||||
placeholder="e.g. git-bkp"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Button className="btn" onClick={handleSubmit} disabled={!namespace || !pvc || !backupName}>
|
||||
<Button className="btn" onClick={handleSubmit}>
|
||||
Create Backup
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default BackupForm;
|
||||
|
||||
@ -1,58 +1,84 @@
|
||||
import { useState } from 'react';
|
||||
import { restoreBackup } from '../service';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { restoreBackup, getNamespaces, getBackupPVCs } from '../api/snapix';
|
||||
import { Button } from '@mui/base';
|
||||
import '../style/RestoreForm.css';
|
||||
import { Button, Input } from '@mui/base';
|
||||
|
||||
function RestoreForm() {
|
||||
const [namespace, setNamespace] = useState('');
|
||||
const [targetPVC, setTargetPVC] = useState('');
|
||||
export default function RestoreForm() {
|
||||
const [backupName, setBackupName] = useState('');
|
||||
const [targetNs, setTargetNs] = useState('');
|
||||
const [targetPvc, setTargetPvc] = useState('');
|
||||
const [namespaces, setNamespaces] = useState([]);
|
||||
const [backupPvcs, setBackupPvcs] = useState([]);
|
||||
|
||||
const handleSubmit = async () => {
|
||||
try {
|
||||
await restoreBackup({ namespace, targetPVC, backupName });
|
||||
alert('✅ Restore completed successfully!');
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
alert('❌ Restore failed');
|
||||
useEffect(() => {
|
||||
getNamespaces().then(res => setNamespaces(res.data));
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (targetNs) {
|
||||
getBackupPVCs().then(res => {
|
||||
// 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 (
|
||||
<div className="form-container RestoreForm">
|
||||
<h3>♻️ Restore from Backup</h3>
|
||||
<div className="form-group">
|
||||
<label>Namespace</label>
|
||||
<input
|
||||
type="text"
|
||||
value={namespace}
|
||||
onChange={(e) => setNamespace(e.target.value)}
|
||||
/>
|
||||
<h2>🔁 Restore PVC</h2>
|
||||
|
||||
<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-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"
|
||||
<div className="form-content">
|
||||
<label>Backup PVC:</label>
|
||||
<select
|
||||
value={backupName}
|
||||
onChange={(e) => setBackupName(e.target.value)}
|
||||
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
|
||||
type="text"
|
||||
value={targetPvc}
|
||||
onChange={e => setTargetPvc(e.target.value)}
|
||||
placeholder="the exact name of the pvc of your app"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Button className="btn" onClick={handleSubmit} disabled={!namespace || !targetPVC || !backupName}>
|
||||
<Button id="restore-btn" className="btn" onClick={handleRestore}>
|
||||
Restore
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default RestoreForm;
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { StrictMode } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import './index.css'
|
||||
import './style/global.css'
|
||||
import App from './App.jsx'
|
||||
|
||||
createRoot(document.getElementById('root')).render(
|
||||
|
||||
@ -1,33 +0,0 @@
|
||||
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();
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
.BackupForm {
|
||||
background: #e3f2fd;
|
||||
padding: 24px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 6px rgba(0,0,0,0.2);
|
||||
color: rgb(0, 0, 0);
|
||||
}
|
||||
@ -1,7 +1,3 @@
|
||||
.RestoreForm {
|
||||
background: #f1f8e9;
|
||||
padding: 24px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 6px rgba(0,0,0,0.2);
|
||||
color: rgb(0, 0, 0);
|
||||
#restore-btn {
|
||||
background-color: dodgerblue;
|
||||
}
|
||||
@ -1,58 +1,76 @@
|
||||
/* Global button style */
|
||||
.btn {
|
||||
padding: 10px;
|
||||
font-weight: bold;
|
||||
background: #1976d2;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
h2 {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.btn:disabled {
|
||||
background: #ccc;
|
||||
.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;
|
||||
}
|
||||
|
||||
/* Unified input/select styling */
|
||||
input,
|
||||
select {
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
background-color: #1a1a1a;
|
||||
border: 1px solid #444;
|
||||
border-radius: 8px;
|
||||
color: white;
|
||||
font-size: 1rem;
|
||||
box-sizing: border-box;
|
||||
appearance: none;
|
||||
}
|
||||
|
||||
input:hover,
|
||||
select:hover {
|
||||
border-color: #1a73e8;
|
||||
}
|
||||
|
||||
input:disabled,
|
||||
select:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
/* Inputs */
|
||||
input, select {
|
||||
padding: 8px;
|
||||
.btn {
|
||||
background-color: #4CAF50;
|
||||
color: white;
|
||||
margin-top: 30px;
|
||||
padding: 10px 20px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
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;
|
||||
}
|
||||
|
||||
/* 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;
|
||||
} */
|
||||
Loading…
x
Reference in New Issue
Block a user