Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cluster-wide MachineType #2437

Merged
merged 1 commit into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions controllers/operands/kubevirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ const (
machineTypeEnvName = "MACHINETYPE"
)

const (
DefaultAMD64OVMFPath = "/usr/share/OVMF"
DefaultAMD64EmulatedMachines = "q35*,pc-q35*"
)

var (
useKVMEmulation = false
)
Expand Down Expand Up @@ -426,6 +431,14 @@ func getKVConfig(hc *hcov1beta1.HyperConverged) (*kubevirtcorev1.KubeVirtConfigu
if val, ok := os.LookupEnv(machineTypeEnvName); ok {
if val = strings.TrimSpace(val); val != "" {
config.MachineType = val

config.ArchitectureConfiguration = &kubevirtcorev1.ArchConfiguration{
Amd64: &kubevirtcorev1.ArchSpecificConfiguration{
MachineType: val,
OVMFPath: DefaultAMD64OVMFPath,
EmulatedMachines: strings.Split(DefaultAMD64EmulatedMachines, ","),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently MachineType takes the value of MACHINETYPE env variable that can be set at bundle build time.
Are OVMFPath and EmulatedMachines completely independent from MachineType or we should also introduce 2 additional optional env variables for them?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are 3 independent settings, we can, of course, give the option to set all 3 with env vars but I thought that for the sake of simplicity to just hardcode the remaining 2 to KubeVirt's default.

},
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions controllers/operands/kubevirt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ Version: 1.2.3`)
Expect(*foundResource.Spec.Configuration.DeveloperConfiguration.DiskVerification.MemoryLimit).Should(Equal(kvDiskVerificationMemoryLimit))

Expect(foundResource.Spec.Configuration.MachineType).Should(Equal("machine-type"))
Expect(foundResource.Spec.Configuration.ArchitectureConfiguration.Amd64.MachineType).Should(Equal("machine-type"))

Expect(foundResource.Spec.Configuration.SMBIOSConfig).ToNot(BeNil())
Expect(foundResource.Spec.Configuration.SMBIOSConfig.Family).Should(Equal("smbios family"))
Expand Down Expand Up @@ -309,6 +310,11 @@ Version: 1.2.3`)
FeatureGates: []string{"wrongFG1", "wrongFG2", "wrongFG3"},
}
existKv.Spec.Configuration.MachineType = "wrong machine type"
existKv.Spec.Configuration.ArchitectureConfiguration = &kubevirtcorev1.ArchConfiguration{
Amd64: &kubevirtcorev1.ArchSpecificConfiguration{
MachineType: "wrong machine type",
},
}
existKv.Spec.Configuration.SMBIOSConfig = &kubevirtcorev1.SMBiosConfiguration{
Family: "wrong family",
Product: "wrong product",
Expand Down Expand Up @@ -365,6 +371,7 @@ Version: 1.2.3`)
))

Expect(foundResource.Spec.Configuration.MachineType).Should(Equal("machine-type"))
Expect(foundResource.Spec.Configuration.ArchitectureConfiguration.Amd64.MachineType).Should(Equal("machine-type"))

Expect(foundResource.Spec.Configuration.SMBIOSConfig).ToNot(BeNil())
Expect(foundResource.Spec.Configuration.SMBIOSConfig.Family).Should(Equal("smbios family"))
Expand Down