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

launch: Use appconfig.Compute for Plan guest information. #3219

Merged
merged 8 commits into from
Feb 13, 2024

Conversation

alichay
Copy link
Contributor

@alichay alichay commented Jan 31, 2024

Change Summary

What and Why: The Launch Plan now uses appconfig.Compute instead of the disparate fields like CPUs or MemoryMB. We still support reading those fields from the UI, though, and throw them into the default process' Compute definition when modifying the plan.

This means that the UI could be changed to write the Compute field instead of these individual fields, which would allow defining multiple guests for different groups (although I'm not sure we want that), but importantly it would allow defining things like launching GPU machines.

How: When we create the plan, we fill in both the Compute field, and all the deprecated individual fields. When we read the Plan from the UI, if the Compute field is empty (meaning the UI has not transmitted it back to us), we'll reconstruct it by taking the Compute from the appConfig, and modifying the default group's Compute with the values the UI passed back to us.

This should be totally transparent to users, should make fly.toml import a little bit better, and should future-proof Launch for things to come :)

Related to: conversation with Daniel in #fly-launch


Documentation

  • Fresh Produce
  • In superfly/docs, or asked for help from docs team
  • n/a

Comment on lines 91 to 105
// Fallback for versions of the UI that don't support a Compute field in the Plan.
var (
io = iostreams.FromContext(ctx)
defaultGroup = state.appConfig.DefaultProcessName()
matchedComputeStrong *appconfig.Compute
matchedComputeWeak *appconfig.Compute
)

{ // Temporary: set the appconfig Compute configuration based on the plan
for _, compute := range state.appConfig.Compute {
if slices.Contains(compute.Processes, defaultGroup) {
if matchedComputeStrong != nil {
fmt.Fprintf(io.Out, "Warning: multiple compute configurations match the default process group %s\n", defaultGroup)
}
matchedComputeStrong = compute
} else if len(compute.Processes) == 0 {
if matchedComputeWeak != nil {
fmt.Fprintf(io.Out, "Warning: multiple compute configurations exist that match all processes\n")
}
matchedComputeWeak = compute
}
}
// NOTE: the calls to applyGuestToCompute here will *still* clobbers guest config like kernel or gpu,
// even though we're trying to be good citizens and modifying instead of overwriting the compute config.
// The only real solution to this is updating the UI to return a Compute field.
switch {
case matchedComputeStrong != nil:
applyGuestToCompute(matchedComputeStrong, state.Plan.Guest())
case matchedComputeWeak != nil:
applyGuestToCompute(matchedComputeWeak, state.Plan.Guest())
default:
state.appConfig.Compute = append(state.appConfig.Compute, guestToCompute(state.Plan.Guest()))
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm going to rewrite this. This is 100% "I am very tired" code

This moves us closer to how fly.tomls get serialized

Unfortunately, we'll have to do some weird plan patching in a later commit to make this compatible with the plan shape the UI currently expects
This means we can write code *now* that expects the Launch Plan to have full compute fields, but also means that when the UI gets support for returning them, then we'll automatically start supporting that.
This allows launch to piggyback off the same logic. Initially I wanted to just copy-paste this into Launch and be done with it, but I had to copy `matchesGroups` too which just turns it into a big mess of unmaintainable code.

Not that this is *much* better, but it's a little better (I hope)
@alichay alichay force-pushed the chore/launch/use-appconfig-compute branch from 2c36929 to e6ab3a5 Compare February 12, 2024 21:46
@alichay alichay merged commit 1195da2 into master Feb 13, 2024
43 checks passed
@alichay alichay deleted the chore/launch/use-appconfig-compute branch February 13, 2024 23:43
Copy link

sentry-io bot commented Feb 14, 2024

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ agent.forkError: exec: "C:\Users\neros\.fly\bin\fly.exe": file does not exist github.com/superfly/flyctl/internal/sentry in C... View Issue

Did you find this useful? React with a 👍 or 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants