({ onCreated, storageClasses }: { onCreated: (msg: string) => void; storageClasses: SC[] })
| 261 | } |
| 262 | |
| 263 | function QuickCreatePVC({ onCreated, storageClasses }: { onCreated: (msg: string) => void; storageClasses: SC[] }) { |
| 264 | const [name, setName] = useState(""); |
| 265 | const [namespace, setNamespace] = useState("default"); |
| 266 | const [size, setSize] = useState("1Gi"); |
| 267 | const [accessMode, setAccessMode] = useState("ReadWriteOnce"); |
| 268 | const [storageClass, setStorageClass] = useState(""); |
| 269 | const [creating, setCreating] = useState(false); |
| 270 | const [error, setError] = useState<string | null>(null); |
| 271 | const [success, setSuccess] = useState<string | null>(null); |
| 272 | |
| 273 | const handleCreate = () => { |
| 274 | if (!name) { |
| 275 | setError("Name is required"); |
| 276 | return; |
| 277 | } |
| 278 | setCreating(true); |
| 279 | setError(null); |
| 280 | setSuccess(null); |
| 281 | |
| 282 | const body = JSON.stringify({ |
| 283 | apiVersion: "v1", |
| 284 | kind: "PersistentVolumeClaim", |
| 285 | metadata: { name, namespace }, |
| 286 | spec: { |
| 287 | accessModes: [accessMode], |
| 288 | resources: { requests: { storage: size } }, |
| 289 | ...(storageClass ? { storageClassName: storageClass } : {}), |
| 290 | }, |
| 291 | }); |
| 292 | |
| 293 | const headers: Record<string, string> = { |
| 294 | "Content-Type": "application/json", |
| 295 | Accept: "application/json", |
| 296 | }; |
| 297 | const token = sessionStorage.getItem("rusternetes-token"); |
| 298 | if (token) headers["Authorization"] = `Bearer ${token}`; |
| 299 | |
| 300 | fetch(`/api/v1/namespaces/${namespace}/persistentvolumeclaims`, { |
| 301 | method: "POST", |
| 302 | headers, |
| 303 | body, |
| 304 | }) |
| 305 | .then(async (res) => { |
| 306 | if (res.ok) { |
| 307 | const createdName = name; |
| 308 | setName(""); |
| 309 | onCreated(`PVC "${createdName}" created in ${namespace}`); |
| 310 | } else { |
| 311 | const data = await res.json().catch(() => ({})); |
| 312 | setError(data.message ?? `HTTP ${res.status}: ${res.statusText}`); |
| 313 | } |
| 314 | }) |
| 315 | .catch((err) => { |
| 316 | setError(`Network error: ${err.message ?? err}`); |
| 317 | }) |
| 318 | .finally(() => { |
| 319 | setCreating(false); |
| 320 | }); |
nothing calls this directly
no test coverage detected