Skip to content

Commit be4f303

Browse files
committed
Detect architecture
Signed-off-by: Lukas Frank <[email protected]>
1 parent afd7cf9 commit be4f303

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

internal/controllers/machine_controller.go

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"fmt"
1212
"os"
1313
"path/filepath"
14+
"runtime"
1415
"slices"
1516
"sync"
1617
"time"
@@ -44,6 +45,9 @@ const (
4445
rootFSAlias = "ua-rootfs"
4546
libvirtDomainXMLIgnitionKeyName = "opt/com.coreos/config"
4647
networkInterfaceAliasPrefix = "ua-networkinterface-"
48+
49+
ArchitectureAARCH64 = "aarch64"
50+
ArchitectureX8664 = "x86_64"
4751
)
4852

4953
var (
@@ -600,12 +604,27 @@ func (r *MachineReconciler) createDomain(
600604
return volumeStates, nicStates, nil
601605
}
602606

607+
func detectArchitecture() (string, error) {
608+
switch runtime.GOARCH {
609+
case "amd64":
610+
return ArchitectureX8664, nil
611+
case "arm64":
612+
return ArchitectureAARCH64, nil
613+
default:
614+
return "", fmt.Errorf("unsupported architecture: %s", runtime.GOARCH)
615+
}
616+
}
617+
603618
func (r *MachineReconciler) domainFor(
604619
ctx context.Context,
605620
log logr.Logger,
606621
machine *api.Machine,
607622
) (*libvirtxml.Domain, []api.VolumeStatus, []api.NetworkInterfaceStatus, error) {
608-
architecture := "aarch64" // TODO: Detect this from the image / machine specification.
623+
architecture, err := detectArchitecture()
624+
if err != nil {
625+
return nil, nil, nil, err
626+
}
627+
609628
osType := guest.OSTypeHVM // TODO: Make this configurable via machine class
610629
domainSettings, err := r.guestCapabilities.SettingsFor(guest.Requests{
611630
Architecture: architecture,
@@ -616,16 +635,19 @@ func (r *MachineReconciler) domainFor(
616635
return nil, nil, nil, err
617636
}
618637

638+
cpu := &libvirtxml.DomainCPU{}
639+
if architecture != ArchitectureAARCH64 {
640+
cpu.Mode = "host-passthrough"
641+
}
642+
619643
domainDesc := &libvirtxml.Domain{
620644
Name: machine.GetID(),
621645
UUID: machine.GetID(),
622646
Type: domainSettings.Type,
623647
OnPoweroff: "destroy",
624648
OnReboot: "restart",
625649
OnCrash: "coredump-restart",
626-
CPU: &libvirtxml.DomainCPU{
627-
Mode: "host-passthrough",
628-
},
650+
CPU: cpu,
629651
Features: &libvirtxml.DomainFeatureList{
630652
ACPI: &libvirtxml.DomainFeature{},
631653
APIC: &libvirtxml.DomainFeatureAPIC{},

0 commit comments

Comments
 (0)