-
Notifications
You must be signed in to change notification settings - Fork 132
Add basic per-actor external volume flow #405
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
Michelle Au (msau42)
wants to merge
6
commits into
agent-substrate:main
Choose a base branch
from
msau42:mock-mount-dev
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.
+1,661
−366
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1b3ad2a
ActorTemplate api changes to add per-actor external volumes.
msau42 a9c90db
ateapi handling of external volumes.
msau42 79bd689
atelet handling of external volumes.
msau42 ff871f7
Allow ateom to see host mounts
msau42 8e69611
Volume plugin interface and mock volume implementation.
msau42 4890a34
Update counter demo with external volume using mock volume plugin.
msau42 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| // Copyright 2026 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package controlapi | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "log/slog" | ||
|
|
||
| "github.com/agent-substrate/substrate/internal/volume" | ||
| atev1alpha1 "github.com/agent-substrate/substrate/pkg/api/v1alpha1" | ||
| "github.com/agent-substrate/substrate/pkg/proto/ateapipb" | ||
| "google.golang.org/grpc/codes" | ||
| "google.golang.org/grpc/status" | ||
| ) | ||
|
|
||
| var ( | ||
| globalVolumePlugin = volume.NewMockVolumePlugin() | ||
| ) | ||
|
|
||
| // TODO: Replace with actual volume plugin search | ||
| func getVolumePlugin() volume.VolumePlugin { | ||
| return globalVolumePlugin | ||
| } | ||
|
|
||
| // TODO: we should persist creation first so that we can handle background cleanup. | ||
| // this probably requires us to add a PROVISIONING actor state. | ||
|
|
||
| // createActorVolumes provisions external volumes specified in the actor template. | ||
| // It returns the list of created external volumes, or an error if any creation fails. | ||
| // If any volume creation fails, it cleans up any volumes created in this call on a best-effort basis. | ||
| func (s *Service) createActorVolumes(ctx context.Context, ref *ateapipb.ObjectRef, template *atev1alpha1.ActorTemplate) ([]*ateapipb.ExternalVolume, error) { | ||
| var volumes []*ateapipb.ExternalVolume | ||
| for _, vol := range template.Spec.Volumes { | ||
| if vol.ExternalVolumeTemplate != nil { | ||
| // Use a unique name for the volume to ensure idempotency | ||
| uniqueVolName := actorVolumeID(ref, vol.Name) | ||
| storageVolumeID, err := getVolumePlugin().CreateVolume(ctx, uniqueVolName, vol.ExternalVolumeTemplate.Capacity.String(), vol.ExternalVolumeTemplate.StorageClassName) | ||
| if err != nil { | ||
| // TODO: need better system - best effort cleanup of already created volumes | ||
| s.deleteActorVolumes(ctx, ref, volumes) | ||
| return nil, status.Errorf(codes.Internal, "failed to create volume %q: %v", vol.Name, err) | ||
| } | ||
| volumes = append(volumes, &ateapipb.ExternalVolume{ | ||
| ActorVolumeId: uniqueVolName, | ||
| StorageVolumeId: storageVolumeID, | ||
| VolumeType: "mock", // TODO fix when we support multiple plugins | ||
| Status: ateapipb.ExternalVolume_CREATED, | ||
| }) | ||
| } | ||
| } | ||
| return volumes, nil | ||
| } | ||
|
|
||
| // deleteActorVolumes deletes all external volumes in the list on a best-effort basis. | ||
| func (s *Service) deleteActorVolumes(ctx context.Context, ref *ateapipb.ObjectRef, volumes []*ateapipb.ExternalVolume) { | ||
| for _, vol := range volumes { | ||
| if err := getVolumePlugin().DeleteVolume(ctx, vol.GetStorageVolumeId()); err != nil { | ||
| slog.ErrorContext(ctx, "failed to delete volume", | ||
| slog.String("atespace", ref.GetAtespace()), | ||
| slog.String("actor_id", ref.GetName()), | ||
| slog.String("volume_id", vol.GetStorageVolumeId()), | ||
| slog.Any("error", err)) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // getMountedActorVolumes filters the actor's volumes and returns only those that are declared and mounted in the ActorTemplate. | ||
| func getMountedActorVolumes(ctx context.Context, ref *ateapipb.ObjectRef, volumes []*ateapipb.ExternalVolume, template *atev1alpha1.ActorTemplate) []*ateapipb.ExternalVolume { | ||
| var mounted []*ateapipb.ExternalVolume | ||
| for _, vol := range volumes { | ||
| // Find the corresponding volume in the ActorTemplate to check if it's mounted | ||
| var matchedTemplateVol *atev1alpha1.Volume | ||
| for _, tVol := range template.Spec.Volumes { | ||
| expectedID := actorVolumeID(ref, tVol.Name) | ||
| if vol.GetActorVolumeId() == expectedID { | ||
| matchedTemplateVol = &tVol | ||
| break | ||
| } | ||
| } | ||
|
|
||
| if matchedTemplateVol == nil { | ||
| slog.WarnContext(ctx, "Volume not found in template, skipping", slog.String("volume_id", vol.GetStorageVolumeId())) | ||
| continue | ||
| } | ||
|
|
||
| if !isVolumeMounted(matchedTemplateVol.Name, template) { | ||
| slog.InfoContext(ctx, "Volume not mounted in template, skipping", slog.String("volume_id", vol.GetStorageVolumeId())) | ||
| continue | ||
| } | ||
| mounted = append(mounted, vol) | ||
| } | ||
| return mounted | ||
| } | ||
|
|
||
| func actorVolumeID(ref *ateapipb.ObjectRef, volumeName string) string { | ||
| // TODO consider if this should be actor UUID | ||
| return fmt.Sprintf("%s-%s-%s", ref.GetAtespace(), ref.GetName(), volumeName) | ||
| } |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Discuss: In general, how should we approach errors when an operation only partially succeeds? Should we rollback all the partially completed operations? What happens if the rollback fails?
Or we leave the system in the partial state and require users to cleanup by calling Delete? Even then, if deletion fails and Create is called again, we could still have partially leftover resources from a previous invocation.
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.
My current thoughts:
If there is a pair of "Create" and "Delete" operations, then we can leave the partial state and clean it up on the Delete. This does imply we will have to add some "Creating" and possibly "Deleting" state to Actor before we start creating resources for it. I already have marked that as a todo.
For operations like "Resume", there isn't a corresponding delete operation if the resume failed. It's possible resume could be called on a different node. That means we could have partial state left on the first node. In those cases we can try to rollback the state as much as possible but that would still be a best effort operation. This has a few implications: