Compare commits

...

8 Commits

Author SHA1 Message Date
970933b4a1 Add .gitignore 2025-06-11 05:30:06 +03:00
bbe2bc4a01 Merge pull request 'fix-select-ns' (#2) from fix-select-ns into master
Reviewed-on: #2
2025-06-11 02:28:43 +00:00
9b5666a72e Add dropdown also to Backup PVC 2025-06-11 05:28:21 +03:00
81ec39d1f0 Fix drop down 2025-06-11 05:14:23 +03:00
ec145e4531 Merge pull request 'style-app' (#1) from style-app into master
Reviewed-on: #1
2025-06-11 02:03:37 +00:00
0e55ff2568 Back to native select and option 2025-06-11 04:54:20 +03:00
5c6cbb5195 colored restore button 2025-06-10 20:51:49 +03:00
ff18c5d6d7 Center it 2025-06-10 20:46:34 +03:00
15 changed files with 1166 additions and 103 deletions

1
backend/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
__pycache__

View File

@ -1,5 +1,6 @@
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"])
@ -10,3 +11,18 @@ 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 from k8s_utils import get_namespaces, get_pvcs, get_all_backup_pvcs
from backup_manager import create_backup, restore_backup from backup_manager import create_backup, restore_backup
app = FastAPI() app = FastAPI()
@ -33,6 +33,11 @@ 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)

File diff suppressed because it is too large Load Diff

View File

@ -10,6 +10,11 @@
"preview": "vite preview" "preview": "vite preview"
}, },
"dependencies": { "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", "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,42 +1,36 @@
#root { body {
max-width: 1280px; display: flex;
margin: 0 auto; 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; padding: 2rem;
box-sizing: border-box;
}
/* Title styling */
.snapix-title {
text-align: center; text-align: center;
color: white;
margin-bottom: 2rem;
font-size: 2rem;
} }
.logo { /* Dashboard: backup + restore side by side */
height: 6em; .snapix-dashboard {
padding: 1.5em; display: flex;
will-change: filter; justify-content: center;
transition: filter 300ms; align-items: flex-start;
} gap: 30px;
.logo:hover { flex-wrap: wrap;
filter: drop-shadow(0 0 2em #646cffaa); margin: auto;
}
.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;
} }

View File

@ -1,14 +1,17 @@
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 style={{ padding: "2rem" }}> <div className="snapix-container">
<h1>🚀 Snapix Dashboard</h1> <h1 className="snapix-title">🚀 Snapix Dashboard</h1>
<div className="snapix-dashboard">
<BackupForm /> <BackupForm />
<hr />
<RestoreForm /> <RestoreForm />
</div> </div>
</div>
); );
} }

View File

@ -8,3 +8,5 @@ export const getNamespaces = () => api.get('/namespaces');
export const getPVCs = (namespace) => api.get(`/pvcs/${namespace}`); export const getPVCs = (namespace) => api.get(`/pvcs/${namespace}`);
export const createBackup = (payload) => api.post('/backup', payload); export const createBackup = (payload) => api.post('/backup', payload);
export const restoreBackup = (payload) => api.post('/restore', payload); export const restoreBackup = (payload) => api.post('/restore', payload);
export const getBackupPVCs = () => api.get('/backup-pvcs');

View File

@ -1,5 +1,6 @@
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { getNamespaces, getPVCs, createBackup } from '../api/snapix'; import { getNamespaces, getPVCs, createBackup } from '../api/snapix';
import { Button, Input } from '@mui/base';
export default function BackupForm() { export default function BackupForm() {
const [namespaces, setNamespaces] = useState([]); const [namespaces, setNamespaces] = useState([]);
@ -27,41 +28,57 @@ export default function BackupForm() {
pvc_name: selectedPvc, pvc_name: selectedPvc,
backup_name: backupName, backup_name: backupName,
}).then(() => { }).then(() => {
alert("Backup started!"); alert('Backup started!');
setBackupName(''); setBackupName('');
}); });
} }
}; };
return ( return (
<div> <div className="form-group">
<h2>📦 Backup PVC</h2> <h2>📦 Backup PVC</h2>
<div className="form-content">
<label>Namespace:</label> <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> <option value="">-- Select Namespace --</option>
{namespaces.map(ns => <option key={ns}>{ns}</option>)} {namespaces.map(ns => (
<option key={ns} value={ns}>
{ns}
</option>
))}
</select> </select>
</div>
<div className="form-content">
<label>PVC:</label> <label>PVC:</label>
<select <select
onChange={e => setSelectedPvc(e.target.value)}
value={selectedPvc} value={selectedPvc}
onChange={(e) => setSelectedPvc(e.target.value)}
disabled={!selectedNs} disabled={!selectedNs}
> >
<option value="">-- Select PVC --</option> <option value="">-- Select PVC --</option>
{pvcs.map(pvc => <option key={pvc}>{pvc}</option>)} {pvcs.map(pvc => (
<option key={pvc} value={pvc}>
{pvc}
</option>
))}
</select> </select>
</div>
<div className="form-content">
<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" placeholder="e.g. git-bkp"
/> />
</div>
<button onClick={handleSubmit}>Create Backup</button> <Button className="btn" onClick={handleSubmit}>
Create Backup
</Button>
</div> </div>
); );
} }

View File

@ -1,10 +1,30 @@
import { useState } from 'react'; import { useEffect, useState } from 'react';
import { restoreBackup } from '../api/snapix'; import { restoreBackup, getNamespaces, getBackupPVCs } from '../api/snapix';
import { Button } from '@mui/base';
import '../style/RestoreForm.css';
export default function RestoreForm() { export default function RestoreForm() {
const [backupName, setBackupName] = useState(''); const [backupName, setBackupName] = useState('');
const [targetNs, setTargetNs] = useState(''); const [targetNs, setTargetNs] = useState('');
const [targetPvc, setTargetPvc] = 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 = () => { const handleRestore = () => {
if (backupName && targetNs && targetPvc) { if (backupName && targetNs && targetPvc) {
@ -13,37 +33,52 @@ export default function RestoreForm() {
target_namespace: targetNs, target_namespace: targetNs,
target_pvc: targetPvc, target_pvc: targetPvc,
}).then(() => { }).then(() => {
alert("Restore started!"); alert('Restore started!');
}); });
} }
}; };
return ( return (
<div> <div className="form-group">
<h2>🔁 Restore PVC</h2> <h2>🔁 Restore PVC</h2>
<label>Backup Name:</label> <div className="form-content">
<input <label>Target Namespace:</label>
type="text" <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} value={backupName}
onChange={e => setBackupName(e.target.value)} onChange={e => setBackupName(e.target.value)}
/> disabled={!targetNs}
>
<label>Target Namespace:</label> <option value="">-- Select Backup PVC --</option>
<input {backupPvcs.map(({ name }) => (
type="text" <option key={name} value={name}>{name}</option>
value={targetNs} ))}
onChange={e => setTargetNs(e.target.value)} </select>
/> </div>
<div className="form-content">
<label>Target PVC:</label> <label>Target PVC:</label>
<input <input
type="text" type="text"
value={targetPvc} value={targetPvc}
onChange={e => setTargetPvc(e.target.value)} 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> </div>
); );
} }

View File

@ -1,6 +1,7 @@
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(

View File

@ -0,0 +1,3 @@
#restore-btn {
background-color: dodgerblue;
}

View 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;
}