-
Notifications
You must be signed in to change notification settings - Fork 155
beam-thunder integration #1814
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
Open
rohanphadnis-thunder
wants to merge
28
commits into
beam-cloud:main
Choose a base branch
from
Thunder-Compute:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
beam-thunder integration #1814
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
4706749
propagated gpu_virtualized field
rohanphadnis-thunder ffdde92
added GPU mount gate for virtual GPUs
rohanphadnis-thunder bf714d4
added thunder deployments files
rohanphadnis-thunder cfc8718
removed helm
rohanphadnis-thunder 92acd9e
added curl installer for sandbox setup
rohanphadnis-thunder a9669d5
added more logs for debugging
rohanphadnis-thunder ac65b55
added correct thunder install hook
rohanphadnis-thunder 5361f95
Merge pull request #2 from beam-cloud/main
rohanphadnis-thunder fa7fb7b
merge
rohanphadnis-thunder 2e8d572
Merge branch 'main' into rohan/gpu_virt_v1
rohanphadnis-thunder ff39938
rebuilt protos
rohanphadnis-thunder e03a1c2
added mounts and gates
rohanphadnis-thunder f19239e
adding libcuda into vgpu sandboxes
rohanphadnis-thunder aec0d68
Merge pull request #3 from beam-cloud/main
rohanphadnis-thunder 42fbe80
Merge branch 'main' into rohan/gpu_virt_v1
rohanphadnis-thunder de26fbe
Merge pull request #4 from beam-cloud/main
rohanphadnis-thunder 2151cd6
Merge branch 'main' into rohan/gpu_virt_v1
rohanphadnis-thunder 55d6c38
added gateway-side changes
rohanphadnis-thunder 214bf63
added agent soft failure
rohanphadnis-thunder 2d2e241
used existing token state utilities
rohanphadnis-thunder 545a3b1
added multi-enrollment creation functionality
rohanphadnis-thunder 08e4c66
fixed redis hashing
rohanphadnis-thunder fa51446
bugfixes
rohanphadnis-thunder 7a3b8cc
Merge pull request #5 from Thunder-Compute/rohan/gpu_virt_gateway
rohanphadnis-thunder bd73d5b
tailscale ip formatting
rohanphadnis-thunder 532ee76
Merge pull request #6 from Thunder-Compute/rohan/gpu_virt_gateway
rohanphadnis-thunder df4e3ee
Merge pull request #1 from Thunder-Compute/rohan/gpu_virt_v1
rohanphadnis-thunder 9a6a9bb
Merge pull request #7 from beam-cloud/main
rohanphadnis-thunder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| package agent | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "io" | ||
| "net" | ||
| "net/netip" | ||
| "os/exec" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/beam-cloud/beta9/pkg/common" | ||
| pb "github.com/beam-cloud/beta9/proto" | ||
| "google.golang.org/grpc" | ||
| ) | ||
|
|
||
| const thunderNodeInstallTimeout = 2 * time.Minute | ||
|
|
||
| var runThunderNodeInstallCommand = defaultRunThunderNodeInstallCommand | ||
|
|
||
| type nodeEnrollmentGatewayClient interface { | ||
| CreateNodeEnrollment(context.Context, *pb.CreateNodeEnrollmentRequest, ...grpc.CallOption) (*pb.CreateNodeEnrollmentResponse, error) | ||
| DeleteNodeEnrollment(context.Context, *pb.DeleteNodeEnrollmentRequest, ...grpc.CallOption) (*pb.DeleteNodeEnrollmentResponse, error) | ||
| } | ||
|
|
||
| func setupThunderNode(ctx context.Context, client nodeEnrollmentGatewayClient, agentToken string, tailscaleIPs []netip.Addr, stdout, stderr io.Writer) error { | ||
| if client == nil { | ||
| return fmt.Errorf("gateway client is required for Thunder node enrollment") | ||
| } | ||
|
|
||
| reachableIP, err := thunderReachableNodeIP(tailscaleIPs) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| res, err := client.CreateNodeEnrollment(ctx, &pb.CreateNodeEnrollmentRequest{AgentToken: agentToken}) | ||
| if err != nil { | ||
| return fmt.Errorf("create Thunder node enrollment: %w", err) | ||
| } | ||
| if res == nil || !res.Ok { | ||
| return fmt.Errorf("create Thunder node enrollment: %s", firstNonEmpty(res.GetErrorMsg(), "gateway rejected request")) | ||
| } | ||
|
|
||
| enrollmentToken := strings.TrimSpace(res.EnrollmentToken) | ||
| if enrollmentToken == "" { | ||
| verbosef(stdout, "Thunder node enrollment already exists\n") | ||
| return nil | ||
| } | ||
|
|
||
| cmd := thunderNodeInstallCommand(reachableIP, enrollmentToken) | ||
| installCtx, cancel := context.WithTimeout(ctx, thunderNodeInstallTimeout) | ||
| defer cancel() | ||
|
|
||
| statusf(stdout, "Installing Thunder node") | ||
| if err := runThunderNodeInstallCommand(installCtx, cmd); err != nil { | ||
| deleteThunderNodeEnrollment(context.Background(), client, agentToken, stderr) | ||
| return fmt.Errorf("install Thunder node: %w", err) | ||
| } | ||
| statusf(stdout, "Thunder node ready") | ||
| return nil | ||
| } | ||
|
|
||
| func deleteThunderNodeEnrollment(ctx context.Context, client nodeEnrollmentGatewayClient, agentToken string, stderr io.Writer) { | ||
| if client == nil { | ||
| return | ||
| } | ||
| if stderr == nil { | ||
| stderr = io.Discard | ||
| } | ||
| deleteCtx, cancel := context.WithTimeout(ctx, 30*time.Second) | ||
| defer cancel() | ||
|
|
||
| res, err := client.DeleteNodeEnrollment(deleteCtx, &pb.DeleteNodeEnrollmentRequest{AgentToken: agentToken}) | ||
| if err != nil { | ||
| fmt.Fprintf(stderr, "failed to delete Thunder node enrollment: %v\n", err) | ||
| return | ||
| } | ||
| if res == nil || !res.Ok { | ||
| fmt.Fprintf(stderr, "failed to delete Thunder node enrollment: %s\n", firstNonEmpty(res.GetErrorMsg(), "gateway rejected request")) | ||
| } | ||
| } | ||
|
|
||
| func thunderReachableNodeIP(ips []netip.Addr) (string, error) { | ||
| for _, ip := range ips { | ||
| if ip.IsValid() && ip.Is4() { | ||
| return ip.String(), nil | ||
| } | ||
| } | ||
| for _, ip := range ips { | ||
| if ip.IsValid() { | ||
| return ip.String(), nil | ||
| } | ||
| } | ||
| return "", fmt.Errorf("tailscale IP address is required for Thunder node enrollment") | ||
| } | ||
|
|
||
| func hostTailscaleIPs() []netip.Addr { | ||
| iface, err := net.InterfaceByName("tailscale0") | ||
| if err != nil { | ||
| return nil | ||
| } | ||
| addrs, err := iface.Addrs() | ||
| if err != nil { | ||
| return nil | ||
| } | ||
|
|
||
| ips := make([]netip.Addr, 0, len(addrs)) | ||
| for _, addr := range addrs { | ||
| prefix, err := netip.ParsePrefix(addr.String()) | ||
| if err == nil { | ||
| ips = append(ips, prefix.Addr()) | ||
| continue | ||
| } | ||
| if ip, err := netip.ParseAddr(addr.String()); err == nil { | ||
| ips = append(ips, ip) | ||
| } | ||
| } | ||
| return ips | ||
| } | ||
|
|
||
| func thunderNodeInstallCommand(reachableIP, enrollmentToken string) string { | ||
| return "curl -fsSL https://get.thundercompute.com/install.sh | sudo THUNDER_INSTALL_MODE=thunderd THUNDERD_IP=" + common.ShellQuote(reachableIP) + " THUNDER_ENROLLMENT_TOKEN=" + common.ShellQuote(enrollmentToken) + " sh" | ||
| } | ||
|
|
||
| func defaultRunThunderNodeInstallCommand(ctx context.Context, command string) error { | ||
| out, err := exec.CommandContext(ctx, "sh", "-c", command).CombinedOutput() | ||
| if err != nil { | ||
| output := strings.TrimSpace(string(out)) | ||
| if output != "" { | ||
| return fmt.Errorf("%w: %s", err, output) | ||
| } | ||
| return err | ||
| } | ||
| return nil | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still required? I know we talked about removing from the client, but I feel like it should also be removed from the container request as well.