Implements Phase 1: boot a Firecracker microVM, execute a command inside it via envd, and get the output back. Uses raw Firecracker HTTP API via Unix socket (not the Go SDK) for full control over the VM lifecycle. - internal/vm: VM manager with create/pause/resume/destroy, Firecracker HTTP client, process launcher with unshare + ip netns exec isolation - internal/network: per-sandbox network namespace with veth pair, TAP device, NAT rules, and IP forwarding - internal/envdclient: Connect RPC client for envd process/filesystem services with health check retry - cmd/host-agent: demo binary that boots a VM, runs "echo hello", prints output, and cleans up - proto/envd: canonical proto files with buf + protoc-gen-connect-go code generation - images/wrenn-init.sh: minimal PID 1 init script for guest VMs - CLAUDE.md: updated architecture to reflect TAP networking (not vsock) and Firecracker HTTP API (not Go SDK)
53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
package envdclient
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log/slog"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
// WaitUntilReady polls envd's health endpoint until it responds successfully
|
|
// or the context is cancelled. It retries every retryInterval.
|
|
func (c *Client) WaitUntilReady(ctx context.Context) error {
|
|
const retryInterval = 100 * time.Millisecond
|
|
|
|
slog.Info("waiting for envd to be ready", "url", c.healthURL)
|
|
|
|
ticker := time.NewTicker(retryInterval)
|
|
defer ticker.Stop()
|
|
|
|
for {
|
|
select {
|
|
case <-ctx.Done():
|
|
return fmt.Errorf("envd not ready: %w", ctx.Err())
|
|
case <-ticker.C:
|
|
if err := c.healthCheck(ctx); err == nil {
|
|
slog.Info("envd is ready", "host", c.hostIP)
|
|
return nil
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// healthCheck sends a single GET /health request to envd.
|
|
func (c *Client) healthCheck(ctx context.Context) error {
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.healthURL, nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
resp, err := c.httpClient.Do(req)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusNoContent {
|
|
return fmt.Errorf("health check returned %d", resp.StatusCode)
|
|
}
|
|
|
|
return nil
|
|
}
|