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

Worker: prefer assigned CPU/memory to CPU/memory #250

Merged
merged 2 commits into from
Feb 13, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions internal/command/get/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,19 @@ func runGetWorker(cmd *cobra.Command, args []string) error {

table.AddRow("Machine ID", worker.MachineID)
table.AddRow("Scheduling paused", worker.SchedulingPaused)
table.AddRow("Default CPU", worker.DefaultCPU)
table.AddRow("Default memory", worker.DefaultCPU)

var resourcesInfo string
if len(worker.Resources) != 0 {
resourceDescriptions := lo.MapToSlice(worker.Resources, func(key string, value uint64) string {
return fmt.Sprintf("%s: %d", key, value)
})
resourcesInfo = strings.Join(resourceDescriptions, "\n")
}
resourcesInfo := strings.Join(lo.MapToSlice(worker.Resources, func(key string, value uint64) string {
return fmt.Sprintf("%s: %d", key, value)
}), "\n")
table.AddRow("Resources", nonEmptyOrNone(resourcesInfo))

labelsInfo := strings.Join(lo.MapToSlice(worker.Labels, func(key string, value string) string {
return fmt.Sprintf("%s: %s", key, value)
}), "\n")
table.AddRow("Labels", nonEmptyOrNone(labelsInfo))

fmt.Println(table)

return nil
Expand Down
22 changes: 18 additions & 4 deletions internal/worker/vmmanager/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,31 @@ func (vm *VM) cloneAndConfigure(ctx context.Context) error {
vm.imageFQN.Store(&fqn)
}

if vm.Resource.Memory != 0 {
// Set memory
memory := vm.Resource.AssignedMemory

if memory == 0 {
memory = vm.Resource.Memory
}

if memory != 0 {
_, _, err = tart.Tart(ctx, vm.logger, "set", "--memory",
strconv.FormatUint(vm.Resource.Memory, 10), vm.id())
strconv.FormatUint(memory, 10), vm.id())
if err != nil {
return err
}
}

if vm.Resource.CPU != 0 {
// Set CPU
cpu := vm.Resource.AssignedCPU

if cpu == 0 {
cpu = vm.Resource.CPU
}

if cpu != 0 {
_, _, err = tart.Tart(ctx, vm.logger, "set", "--cpu",
strconv.FormatUint(vm.Resource.CPU, 10), vm.id())
strconv.FormatUint(cpu, 10), vm.id())
if err != nil {
return err
}
Expand Down