From 2dfa5904c37b700e1bb7d3b95c72aab20ff7850a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gra=C3=B1a?= Date: Tue, 16 Jul 2024 17:35:50 -0300 Subject: [PATCH 1/2] `fly m run` support for spot-price restart policy and gpu bid price --- go.mod | 2 +- go.sum | 4 ++-- internal/command/machine/run.go | 10 ++++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index a25c4eeb3e..50ff178550 100644 --- a/go.mod +++ b/go.mod @@ -71,7 +71,7 @@ require ( github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.19.0 github.com/stretchr/testify v1.9.0 - github.com/superfly/fly-go v0.1.19-0.20240716210409-e3d434ec3f18 + github.com/superfly/fly-go v0.1.19-0.20240722210612-a53ef77115d0 github.com/superfly/graphql v0.2.4 github.com/superfly/lfsc-go v0.1.1 github.com/superfly/macaroon v0.2.14-0.20240702184853-b8ac52a1fc77 diff --git a/go.sum b/go.sum index ead036ea15..5667686357 100644 --- a/go.sum +++ b/go.sum @@ -626,8 +626,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= -github.com/superfly/fly-go v0.1.19-0.20240716210409-e3d434ec3f18 h1:lXtwecpu2Ynwm1mkSl7pcJFFM86HzJNUsrNC4vswrYg= -github.com/superfly/fly-go v0.1.19-0.20240716210409-e3d434ec3f18/go.mod h1:JQke/BwoZqrWurqYkypSlcSo7bIUgCI3eVnqMC6AUj0= +github.com/superfly/fly-go v0.1.19-0.20240722210612-a53ef77115d0 h1:wm4EJAxGKSyk+8QOHS2kWUMl7a6jQXUSmamspSHeQRs= +github.com/superfly/fly-go v0.1.19-0.20240722210612-a53ef77115d0/go.mod h1:JQke/BwoZqrWurqYkypSlcSo7bIUgCI3eVnqMC6AUj0= github.com/superfly/graphql v0.2.4 h1:Av8hSk4x8WvKJ6MTnEwrLknSVSGPc7DWpgT3z/kt3PU= github.com/superfly/graphql v0.2.4/go.mod h1:CVfDl31srm8HnJ9udwLu6hFNUW/P6GUM2dKcG1YQ8jc= github.com/superfly/lfsc-go v0.1.1 h1:dGjLgt81D09cG+aR9lJZIdmonjZSR5zYCi7s54+ZU2Q= diff --git a/internal/command/machine/run.go b/internal/command/machine/run.go index 83e0cf3a99..a400ce2090 100644 --- a/internal/command/machine/run.go +++ b/internal/command/machine/run.go @@ -124,6 +124,11 @@ var sharedFlags = flag.Set{ Description: `Set the restart policy for a Machine. Options include 'no', 'always', and 'on-fail'. Default is 'on-fail' for Machines created by 'fly deploy' and Machines with a schedule. Default is 'always' for Machines created by 'fly m run'.`, }, + flag.Float64{ + Name: "gpu-bid-price", + Description: `Set the GPU price to bid for (HELP!)`, + Hidden: true, + }, flag.StringSlice{ Name: "standby-for", Description: "For Machines without services, a comma separated list of Machine IDs to act as standby for.", @@ -734,6 +739,11 @@ func determineMachineConfig( machineConf.Restart = &fly.MachineRestart{ Policy: fly.MachineRestartPolicyAlways, } + case "spot-price": + machineConf.Restart = &fly.MachineRestart{ + Policy: fly.MachineRestartPolicySpotPrice, + GPUBidPrice: float32(flag.GetFloat64(ctx, "gpu-bid-price")), + } case "": if flag.IsSpecified(ctx, "restart") { // An empty policy was explicitly requested. From 15a93a4bb1b665125f5d768b02c1cc73673fd060 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gra=C3=B1a?= Date: Thu, 25 Jul 2024 16:26:15 -0300 Subject: [PATCH 2/2] skip launch when creating or updating spot machines --- internal/command/deploy/machines_launchinput.go | 2 ++ internal/command/machine/run.go | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/command/deploy/machines_launchinput.go b/internal/command/deploy/machines_launchinput.go index 5a84bbb59f..8fc551d9d5 100644 --- a/internal/command/deploy/machines_launchinput.go +++ b/internal/command/deploy/machines_launchinput.go @@ -214,6 +214,8 @@ func skipLaunch(origMachineRaw *fly.Machine, mConfig *fly.MachineConfig) bool { return true } } + case mConfig.Restart != nil && mConfig.Restart.Policy == fly.MachineRestartPolicySpotPrice: + return true } return false } diff --git a/internal/command/machine/run.go b/internal/command/machine/run.go index a400ce2090..6cf45fc28c 100644 --- a/internal/command/machine/run.go +++ b/internal/command/machine/run.go @@ -409,8 +409,11 @@ func runMachineRun(ctx context.Context) error { return nil } - input.SkipLaunch = (len(machineConf.Standbys) > 0 || isCreate) input.Config = machineConf + input.SkipLaunch = (len(machineConf.Standbys) > 0 || isCreate) + if machineConf.Restart != nil && machineConf.Restart.Policy == fly.MachineRestartPolicySpotPrice { + input.SkipLaunch = true + } machine, err := flapsClient.Launch(ctx, input) if err != nil {