MCPcopy Create free account
hub / github.com/calfonso/rusternetes / QuickCreateStorageClass

Function QuickCreateStorageClass

console/src/views/StorageView.tsx:181–261  ·  view source on GitHub ↗
({ onCreated }: { onCreated: (msg: string) => void })

Source from the content-addressed store, hash-verified

179// --- Quick create forms ---
180
181function QuickCreateStorageClass({ onCreated }: { onCreated: (msg: string) => void }) {
182 const [name, setName] = useState("");
183 const [provisioner, setProvisioner] = useState("rusternetes.io/hostpath");
184 const [reclaimPolicy, setReclaimPolicy] = useState("Delete");
185 const [bindingMode, setBindingMode] = useState("WaitForFirstConsumer");
186 const [creating, setCreating] = useState(false);
187 const [error, setError] = useState<string | null>(null);
188 const [success, setSuccess] = useState<string | null>(null);
189
190 const handleCreate = async () => {
191 if (!name) { setError("Name is required"); return; }
192 setCreating(true);
193 setError(null);
194 setSuccess(null);
195 try {
196 await k8sCreate(buildApiPath("storage.k8s.io", "v1", "storageclasses"), {
197 apiVersion: "storage.k8s.io/v1",
198 kind: "StorageClass",
199 metadata: { name },
200 provisioner,
201 reclaimPolicy,
202 volumeBindingMode: bindingMode,
203 } as unknown as K8sResource);
204 setName("");
205 onCreated(`StorageClass "${name}" created`);
206 } catch (err) {
207 const errObj = err as { message?: string };
208 setError(errObj.message ?? String(err));
209 } finally {
210 setCreating(false);
211 }
212 };
213
214 return (
215 <div className="space-y-3">
216 {error && <div className="rounded-md border border-container-red/30 bg-container-red/5 px-3 py-2 text-xs text-container-red">{error}</div>}
217 {success && <div className="rounded-md border border-walle-eye/30 bg-walle-eye/5 px-3 py-2 text-xs text-walle-eye">{success}</div>}
218 <div className="grid gap-3 sm:grid-cols-2">
219 <div>
220 <label className="mb-1 block text-[10px] text-[#a89880]">Name</label>
221 <input type="text" value={name} onChange={(e) => setName(e.target.value)} placeholder="standard"
222 className="w-full rounded-md border border-surface-3 bg-surface-2 px-3 py-1.5 text-sm text-[#e8ddd0] outline-none focus:border-accent" />
223 </div>
224 <div>
225 <label className="mb-1 block text-[10px] text-[#a89880]">Provisioner</label>
226 <select value={provisioner} onChange={(e) => setProvisioner(e.target.value)}
227 className="w-full rounded-md border border-surface-3 bg-surface-2 px-3 py-1.5 text-sm text-[#e8ddd0] outline-none focus:border-accent">
228 <option value="rusternetes.io/hostpath">Host path (auto-provisions)</option>
229 <option value="kubernetes.io/no-provisioner">No provisioner (manual PV binding)</option>
230 </select>
231 <span className="mt-0.5 block text-[9px] text-[#a89880]">
232 {provisioner === "rusternetes.io/hostpath"
233 ? "Automatically creates PVs as host directories"
234 : "PVCs will stay Pending until a PV is manually created"}
235 </span>
236 </div>
237 <div>
238 <label className="mb-1 block text-[10px] text-[#a89880]">Reclaim Policy</label>

Callers

nothing calls this directly

Calls 1

handleCreateFunction · 0.85

Tested by

no test coverage detected