mirror of
https://github.com/getcompanion-ai/computer-host.git
synced 2026-04-15 01:00:27 +00:00
revert: undo 4 racing/reconcile fix commits
This commit is contained in:
parent
637036b8c8
commit
0e5e989192
5 changed files with 29 additions and 35 deletions
|
|
@ -32,7 +32,11 @@ func (d *Daemon) ListMachines(ctx context.Context) (*contracthost.ListMachinesRe
|
|||
|
||||
machines := make([]contracthost.Machine, 0, len(records))
|
||||
for _, record := range records {
|
||||
machines = append(machines, machineToContract(record))
|
||||
reconciled, err := d.reconcileMachine(ctx, record.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
machines = append(machines, machineToContract(*reconciled))
|
||||
}
|
||||
return &contracthost.ListMachinesResponse{Machines: machines}, nil
|
||||
}
|
||||
|
|
@ -386,8 +390,13 @@ func (d *Daemon) reconcileMachine(ctx context.Context, machineID contracthost.Ma
|
|||
if !ready {
|
||||
return record, nil
|
||||
}
|
||||
_ = d.personalizeGuest(ctx, record, *state)
|
||||
guestSSHPublicKey, _ := d.readGuestSSHPublicKey(ctx, state.RuntimeHost)
|
||||
if err := d.personalizeGuest(ctx, record, *state); err != nil {
|
||||
return d.failMachineStartup(ctx, record, err.Error())
|
||||
}
|
||||
guestSSHPublicKey, err := d.readGuestSSHPublicKey(ctx, state.RuntimeHost)
|
||||
if err != nil {
|
||||
return d.failMachineStartup(ctx, record, err.Error())
|
||||
}
|
||||
record.RuntimeHost = state.RuntimeHost
|
||||
record.TapDevice = state.TapName
|
||||
record.Ports = defaultMachinePorts()
|
||||
|
|
|
|||
|
|
@ -141,21 +141,3 @@ func writeConfigFile(chrootRootDir string, spec MachineSpec, paths machinePaths,
|
|||
|
||||
return "/vm_config.json", nil
|
||||
}
|
||||
|
||||
func writeMetadataFile(chrootRootDir string, spec MachineSpec) (string, error) {
|
||||
if spec.MMDS == nil || spec.MMDS.Data == nil {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
data, err := json.Marshal(spec.MMDS.Data)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("marshal mmds data: %w", err)
|
||||
}
|
||||
|
||||
metadataPath := filepath.Join(chrootRootDir, "mmds.json")
|
||||
if err := os.WriteFile(metadataPath, data, 0o644); err != nil {
|
||||
return "", fmt.Errorf("write mmds data: %w", err)
|
||||
}
|
||||
|
||||
return "/mmds.json", nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ func configureMachine(ctx context.Context, client *apiClient, paths machinePaths
|
|||
return nil
|
||||
}
|
||||
|
||||
func launchJailedFirecracker(paths machinePaths, machineID MachineID, firecrackerBinaryPath string, jailerBinaryPath string, enablePCI bool, configFilePath string, metadataFilePath string) (*exec.Cmd, error) {
|
||||
func launchJailedFirecracker(paths machinePaths, machineID MachineID, firecrackerBinaryPath string, jailerBinaryPath string, enablePCI bool, configFilePath string) (*exec.Cmd, error) {
|
||||
args := []string{
|
||||
"--id", string(machineID),
|
||||
"--uid", strconv.Itoa(os.Getuid()),
|
||||
|
|
@ -81,9 +81,6 @@ func launchJailedFirecracker(paths machinePaths, machineID MachineID, firecracke
|
|||
}
|
||||
if configFilePath != "" {
|
||||
args = append(args, "--config-file", configFilePath)
|
||||
if metadataFilePath != "" {
|
||||
args = append(args, "--metadata", metadataFilePath)
|
||||
}
|
||||
} else {
|
||||
args = append(args,
|
||||
"--log-path", paths.JailedFirecrackerLogPath,
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ func TestLaunchJailedFirecrackerPassesDaemonAndLoggingFlags(t *testing.T) {
|
|||
t.Fatalf("create log dir: %v", err)
|
||||
}
|
||||
|
||||
if _, err := launchJailedFirecracker(paths, "vm-1", "/usr/bin/firecracker", jailerPath, false, "", ""); err != nil {
|
||||
if _, err := launchJailedFirecracker(paths, "vm-1", "/usr/bin/firecracker", jailerPath, false, ""); err != nil {
|
||||
t.Fatalf("launch jailed firecracker: %v", err)
|
||||
}
|
||||
|
||||
|
|
@ -62,7 +62,7 @@ func TestLaunchJailedFirecrackerPassesEnablePCIWhenConfigured(t *testing.T) {
|
|||
t.Fatalf("create log dir: %v", err)
|
||||
}
|
||||
|
||||
if _, err := launchJailedFirecracker(paths, "vm-1", "/usr/bin/firecracker", jailerPath, true, "", ""); err != nil {
|
||||
if _, err := launchJailedFirecracker(paths, "vm-1", "/usr/bin/firecracker", jailerPath, true, ""); err != nil {
|
||||
t.Fatalf("launch jailed firecracker: %v", err)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -125,13 +125,7 @@ func (r *Runtime) Boot(ctx context.Context, spec MachineSpec, usedNetworks []Net
|
|||
return nil, fmt.Errorf("write config file: %w", err)
|
||||
}
|
||||
|
||||
metadataFilePath, err := writeMetadataFile(paths.ChrootRootDir, spec)
|
||||
if err != nil {
|
||||
cleanup(network, paths, nil, 0)
|
||||
return nil, fmt.Errorf("write metadata file: %w", err)
|
||||
}
|
||||
|
||||
command, err := launchJailedFirecracker(paths, spec.ID, r.firecrackerBinaryPath, r.jailerBinaryPath, r.enablePCI, configFilePath, metadataFilePath)
|
||||
command, err := launchJailedFirecracker(paths, spec.ID, r.firecrackerBinaryPath, r.jailerBinaryPath, r.enablePCI, configFilePath)
|
||||
if err != nil {
|
||||
cleanup(network, paths, nil, 0)
|
||||
return nil, err
|
||||
|
|
@ -143,6 +137,18 @@ func (r *Runtime) Boot(ctx context.Context, spec MachineSpec, usedNetworks []Net
|
|||
}
|
||||
socketPath := procSocketPath(firecrackerPID)
|
||||
|
||||
if spec.MMDS != nil && spec.MMDS.Data != nil {
|
||||
client := newAPIClient(socketPath)
|
||||
if err := waitForSocket(ctx, client, socketPath); err != nil {
|
||||
cleanup(network, paths, command, firecrackerPID)
|
||||
return nil, fmt.Errorf("wait for firecracker socket: %w", err)
|
||||
}
|
||||
if err := client.PutMMDS(ctx, spec.MMDS.Data); err != nil {
|
||||
cleanup(network, paths, command, firecrackerPID)
|
||||
return nil, fmt.Errorf("put mmds data: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
now := time.Now().UTC()
|
||||
state := MachineState{
|
||||
ID: spec.ID,
|
||||
|
|
@ -282,7 +288,7 @@ func (r *Runtime) RestoreBoot(ctx context.Context, loadSpec SnapshotLoadSpec, us
|
|||
return nil, err
|
||||
}
|
||||
|
||||
command, err := launchJailedFirecracker(paths, loadSpec.ID, r.firecrackerBinaryPath, r.jailerBinaryPath, r.enablePCI, "", "")
|
||||
command, err := launchJailedFirecracker(paths, loadSpec.ID, r.firecrackerBinaryPath, r.jailerBinaryPath, r.enablePCI, "")
|
||||
if err != nil {
|
||||
cleanup(network, paths, nil, 0)
|
||||
return nil, err
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue