Allow creating VMs with implicit CPU and memory (#243)

* Allow creating VMs with implicit CPU and memory

* Clarify why cpu/memory can be 0 a bit better

* Controller(API): don't forget to update DefaultCPU and DefaultMemory

* Add an integration test for implicit CPU and memory
This commit is contained in:
Nikolay Edigaryev
2025-02-06 00:50:01 +04:00
committed by GitHub
parent 6b3d64be96
commit 581de320b9
10 changed files with 150 additions and 12 deletions
+15 -2
View File
@@ -65,8 +65,21 @@ func runGetVM(cmd *cobra.Command, args []string) error {
table.AddRow("Created", createdAtInfo)
table.AddRow("Image", vm.Image)
table.AddRow("Image pull policy", vm.ImagePullPolicy)
table.AddRow("CPU", vm.CPU)
table.AddRow("Memory", vm.Memory)
cpu := vm.CPU
if cpu == 0 {
// Implicit CPU assignment, CPU will always be 0
cpu = vm.AssignedCPU
}
table.AddRow("CPU", cpu)
memory := vm.Memory
if memory == 0 {
// Implicit memory assignment, memory will always be 0
memory = vm.AssignedMemory
}
table.AddRow("Memory", memory)
table.AddRow("Softnet enabled", vm.NetSoftnet)
table.AddRow("Bridged networking interface", nonEmptyOrNone(vm.NetBridged))
table.AddRow("Headless mode", vm.Headless)
+7
View File
@@ -29,6 +29,8 @@ var bootstrapTokenStdin bool
var logFilePath string
var stringToStringResources map[string]string
var noPKI bool
var defaultCPU uint64
var defaultMemory uint64
var debug bool
func newRunCommand() *cobra.Command {
@@ -53,6 +55,10 @@ func newRunCommand() *cobra.Command {
"do not use the host's root CA set and instead validate the Controller's presented "+
"certificate using a bootstrap token (or manually via fingerprint, "+
"if no bootstrap token is provided)")
cmd.PersistentFlags().Uint64Var(&defaultCPU, "default-cpu", 4, "number of CPUs to use for VMs "+
"that do not explicitly specify a value")
cmd.PersistentFlags().Uint64Var(&defaultMemory, "default-memory", 8*1024, "megabytes of memory "+
"to use for VMs that do not explicitly specify a value")
cmd.PersistentFlags().BoolVar(&debug, "debug", false, "enable debug logging")
return cmd
@@ -116,6 +122,7 @@ func runWorker(cmd *cobra.Command, args []string) (err error) {
controllerClient,
worker.WithName(name),
worker.WithResources(resources),
worker.WithDefaultCPUAndMemory(defaultCPU, defaultMemory),
worker.WithLogger(logger),
)
if err != nil {