import { useState, useEffect } from 'react'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from '../ui/dialog'; import { Button } from '../ui/button'; import { Alert } from '../ui/alert'; import { CheckCircle, AlertCircle, Loader2 } from 'lucide-react'; import { BootstrapProgress } from './BootstrapProgress'; import { clusterApi } from '../../services/api/cluster'; import { useOperation } from '../../services/api/hooks/useOperations'; interface BootstrapModalProps { instanceName: string; nodeName: string; nodeIp: string; onClose: () => void; } export function BootstrapModal({ instanceName, nodeName, nodeIp, onClose, }: BootstrapModalProps) { const [operationId, setOperationId] = useState(null); const [isStarting, setIsStarting] = useState(false); const [startError, setStartError] = useState(null); const [showConfirmation, setShowConfirmation] = useState(true); const { data: operation } = useOperation(instanceName, operationId || ''); const handleStartBootstrap = async () => { setIsStarting(true); setStartError(null); try { const response = await clusterApi.bootstrap(instanceName, nodeName); setOperationId(response.operation_id); setShowConfirmation(false); } catch (err) { setStartError((err as Error).message || 'Failed to start bootstrap'); } finally { setIsStarting(false); } }; useEffect(() => { if (operation?.status === 'completed') { setTimeout(() => onClose(), 2000); } }, [operation?.status, onClose]); const isComplete = operation?.status === 'completed'; const isFailed = operation?.status === 'failed'; const isRunning = operation?.status === 'running' || operation?.status === 'pending'; return ( Bootstrap Cluster Initialize the Kubernetes cluster on {nodeName} ({nodeIp}) {showConfirmation ? ( <>
Important

This will initialize the etcd cluster and start the control plane components. This operation can only be performed once per cluster and should be run on the first control plane node.

{startError && ( setStartError(null)}>
Bootstrap Failed

{startError}

)}

Before bootstrapping, ensure:

  • Node configuration has been applied successfully
  • Node is in maintenance mode and ready
  • This is the first control plane node
  • No other nodes have been bootstrapped
) : ( <>
{operation && operation.details?.bootstrap ? ( ) : (
Starting bootstrap...
)}
{isComplete && (
Bootstrap Complete!

The cluster has been successfully initialized. Additional control plane nodes can now join automatically.

)} {isFailed && (
Bootstrap Failed

{operation.error || 'The bootstrap process encountered an error.'}

)} {isComplete || isFailed ? ( ) : ( )} )}
); }