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)
|
||||
931
frontend/package-lock.json
generated
931
frontend/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -10,6 +10,11 @@
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@emotion/react": "^11.14.0",
|
||||
"@emotion/styled": "^11.14.0",
|
||||
"@mui/base": "^5.0.0-beta.70",
|
||||
"@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,42 +1,36 @@
|
||||
#root {
|
||||
max-width: 1280px;
|
||||
margin: 0 auto;
|
||||
body {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
/* 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;
|
||||
padding: 2rem;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
/* Title styling */
|
||||
.snapix-title {
|
||||
text-align: center;
|
||||
color: white;
|
||||
margin-bottom: 2rem;
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
.logo {
|
||||
height: 6em;
|
||||
padding: 1.5em;
|
||||
will-change: filter;
|
||||
transition: filter 300ms;
|
||||
}
|
||||
.logo:hover {
|
||||
filter: drop-shadow(0 0 2em #646cffaa);
|
||||
}
|
||||
.logo.react:hover {
|
||||
filter: drop-shadow(0 0 2em #61dafbaa);
|
||||
}
|
||||
|
||||
@keyframes logo-spin {
|
||||
from {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: no-preference) {
|
||||
a:nth-of-type(2) .logo {
|
||||
animation: logo-spin infinite 20s linear;
|
||||
}
|
||||
}
|
||||
|
||||
.card {
|
||||
padding: 2em;
|
||||
}
|
||||
|
||||
.read-the-docs {
|
||||
color: #888;
|
||||
/* 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,14 +1,17 @@
|
||||
import BackupForm from './components/BackupForm';
|
||||
import RestoreForm from './components/RestoreForm';
|
||||
import './App.css';
|
||||
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<div style={{ padding: "2rem" }}>
|
||||
<h1>🚀 Snapix Dashboard</h1>
|
||||
<div className="snapix-container">
|
||||
<h1 className="snapix-title">🚀 Snapix Dashboard</h1>
|
||||
<div className="snapix-dashboard">
|
||||
<BackupForm />
|
||||
<hr />
|
||||
<RestoreForm />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -8,3 +8,5 @@ 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,5 +1,6 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { getNamespaces, getPVCs, createBackup } from '../api/snapix';
|
||||
import { Button, Input } from '@mui/base';
|
||||
|
||||
export default function BackupForm() {
|
||||
const [namespaces, setNamespaces] = useState([]);
|
||||
@ -27,41 +28,57 @@ export default function BackupForm() {
|
||||
pvc_name: selectedPvc,
|
||||
backup_name: backupName,
|
||||
}).then(() => {
|
||||
alert("Backup started!");
|
||||
alert('Backup started!');
|
||||
setBackupName('');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="form-group">
|
||||
<h2>📦 Backup PVC</h2>
|
||||
|
||||
<div className="form-content">
|
||||
<label>Namespace:</label>
|
||||
<select onChange={e => setSelectedNs(e.target.value)} value={selectedNs}>
|
||||
<select value={selectedNs} onChange={(e) => setSelectedNs(e.target.value)}>
|
||||
<option value="">-- Select Namespace --</option>
|
||||
{namespaces.map(ns => <option key={ns}>{ns}</option>)}
|
||||
{namespaces.map(ns => (
|
||||
<option key={ns} value={ns}>
|
||||
{ns}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div className="form-content">
|
||||
<label>PVC:</label>
|
||||
<select
|
||||
onChange={e => setSelectedPvc(e.target.value)}
|
||||
value={selectedPvc}
|
||||
onChange={(e) => setSelectedPvc(e.target.value)}
|
||||
disabled={!selectedNs}
|
||||
>
|
||||
<option value="">-- Select PVC --</option>
|
||||
{pvcs.map(pvc => <option key={pvc}>{pvc}</option>)}
|
||||
{pvcs.map(pvc => (
|
||||
<option key={pvc} value={pvc}>
|
||||
{pvc}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div className="form-content">
|
||||
<label>Backup Name:</label>
|
||||
<input
|
||||
<Input
|
||||
type="text"
|
||||
value={backupName}
|
||||
onChange={e => setBackupName(e.target.value)}
|
||||
onChange={(e) => setBackupName(e.target.value)}
|
||||
placeholder="e.g. git-bkp"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<button onClick={handleSubmit}>Create Backup</button>
|
||||
<Button className="btn" onClick={handleSubmit}>
|
||||
Create Backup
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,10 +1,30 @@
|
||||
import { useState } from 'react';
|
||||
import { restoreBackup } from '../api/snapix';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { restoreBackup, getNamespaces, getBackupPVCs } from '../api/snapix';
|
||||
import { Button } from '@mui/base';
|
||||
import '../style/RestoreForm.css';
|
||||
|
||||
export default function RestoreForm() {
|
||||
const [backupName, setBackupName] = useState('');
|
||||
const [targetNs, setTargetNs] = useState('');
|
||||
const [targetPvc, setTargetPvc] = useState('');
|
||||
const [namespaces, setNamespaces] = useState([]);
|
||||
const [backupPvcs, setBackupPvcs] = useState([]);
|
||||
|
||||
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) {
|
||||
@ -13,37 +33,52 @@ export default function RestoreForm() {
|
||||
target_namespace: targetNs,
|
||||
target_pvc: targetPvc,
|
||||
}).then(() => {
|
||||
alert("Restore started!");
|
||||
alert('Restore started!');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="form-group">
|
||||
<h2>🔁 Restore PVC</h2>
|
||||
|
||||
<label>Backup Name:</label>
|
||||
<input
|
||||
type="text"
|
||||
<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)}
|
||||
/>
|
||||
|
||||
<label>Target Namespace:</label>
|
||||
<input
|
||||
type="text"
|
||||
value={targetNs}
|
||||
onChange={e => setTargetNs(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 onClick={handleRestore}>Restore</button>
|
||||
<Button id="restore-btn" className="btn" onClick={handleRestore}>
|
||||
Restore
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@ -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(
|
||||
|
||||
3
frontend/src/style/RestoreForm.css
Normal file
3
frontend/src/style/RestoreForm.css
Normal file
@ -0,0 +1,3 @@
|
||||
#restore-btn {
|
||||
background-color: dodgerblue;
|
||||
}
|
||||
76
frontend/src/style/global.css
Normal file
76
frontend/src/style/global.css
Normal file
@ -0,0 +1,76 @@
|
||||
h2 {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
|
||||
.btn {
|
||||
background-color: #4CAF50;
|
||||
color: white;
|
||||
margin-top: 30px;
|
||||
padding: 10px 20px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user