-
Notifications
You must be signed in to change notification settings - Fork 387
csi: add publishContext to actor volumes #1578
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ import ( | |
| "github.com/agent-substrate/substrate/internal/ateattr" | ||
| "github.com/agent-substrate/substrate/internal/proto/ateletpb" | ||
| "github.com/agent-substrate/substrate/internal/resources" | ||
| "github.com/agent-substrate/substrate/internal/volume" | ||
| "github.com/agent-substrate/substrate/pkg/proto/ateapipb" | ||
| "google.golang.org/grpc/codes" | ||
| "google.golang.org/grpc/status" | ||
|
|
@@ -121,10 +122,12 @@ func (w *ActorWorkflow) ResumeActor(ctx context.Context, actorRef resources.Acto | |
| return nil, false, err | ||
| } | ||
| actor = assigned | ||
| if err = w.ensureVolumesAttached(leaseCtx, actor, worker, actorTemplate); err != nil { | ||
| var attached *ateapipb.Actor | ||
| if attached, err = w.ensureVolumesAttached(leaseCtx, actorRef, actor, worker, actorTemplate); err != nil { | ||
| return nil, false, err | ||
| } | ||
| if tele, err = w.ensureAteletRestored(leaseCtx, actorRef, actor, actorTemplate, src); err != nil { | ||
| actor = attached | ||
| if tele, err = w.ensureAteletRestored(leaseCtx, actorRef, actor, actorTemplate, worker.GetNodeName(), src); err != nil { | ||
| return nil, false, err | ||
| } | ||
| var running *ateapipb.Actor | ||
|
|
@@ -613,30 +616,52 @@ func schedulingConstraints(actor *ateapipb.Actor, tmpl *ateapipb.ActorTemplate) | |
| } | ||
|
|
||
| // ensureVolumesAttached attaches the actor's mounted external volumes to the | ||
| // assigned worker's node. Attachment is idempotent, so a re-entered workflow | ||
| // safely runs it again. | ||
| // assigned worker's node and records the driver's attachment metadata. | ||
| // TODO replace re-execution with a proper check on the volumes' attach state. | ||
| func (w *ActorWorkflow) ensureVolumesAttached(ctx context.Context, actor *ateapipb.Actor, worker *ateapipb.Worker, actorTemplate *ateapipb.ActorTemplate) (err error) { | ||
| func (w *ActorWorkflow) ensureVolumesAttached(ctx context.Context, actorRef resources.ActorRef, actor *ateapipb.Actor, worker *ateapipb.Worker, actorTemplate *ateapipb.ActorTemplate) (_ *ateapipb.Actor, err error) { | ||
| ctx, done := stepSpan(ctx, "AttachVolumes") | ||
| defer func() { err = done(err) }() | ||
|
|
||
| node := worker.GetNodeName() | ||
| if node == "" { | ||
| return fmt.Errorf("assigned worker has no node name") | ||
| return nil, fmt.Errorf("assigned worker has no node name") | ||
| } | ||
|
|
||
| ref := &ateapipb.ObjectRef{Atespace: actor.GetMetadata().GetAtespace(), Name: actor.GetMetadata().GetName()} | ||
| attached := make(map[string]*ateapipb.ExternalVolume) | ||
| for _, vol := range getMountedActorVolumes(ctx, ref, actor.GetStatus().GetActorVolumes(), actorTemplate) { | ||
| slog.InfoContext(ctx, "Attaching volume to node", slog.String("volume_id", vol.GetStorageVolumeId()), slog.String("node", node)) | ||
| plugin, err := w.pluginRegistry.GetPlugin(ctx, vol.GetVolumeType()) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to get volume plugin for %q: %w", vol.GetVolumeType(), err) | ||
| return nil, fmt.Errorf("failed to get volume plugin for %q: %w", vol.GetVolumeType(), err) | ||
| } | ||
| if err := plugin.AttachVolume(ctx, vol.GetStorageVolumeId(), node); err != nil { | ||
| return fmt.Errorf("failed to attach volume %q to node %q: %w", vol.GetStorageVolumeId(), node, err) | ||
|
|
||
| resp, err := plugin.AttachVolume(ctx, volume.AttachVolumeRequest{VolumeID: vol.GetStorageVolumeId(), Node: node}) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to attach volume %q to node %q: %w", vol.GetStorageVolumeId(), node, err) | ||
| } | ||
| vol.PublishContext = resp.PublishContext | ||
| vol.PublishContextNode = node | ||
| attached[vol.GetVolumeName()] = vol | ||
|
|
||
| } | ||
|
|
||
| storedActor, updateErr := w.store.UpdateActor(ctx, actorRef, store.PreconditionFrom(actor), func(toUpdate *ateapipb.Actor) error { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do we use this publish context information stored for a volume? I do not see a DB update on volume detach, if we plan to use the DB details to get the current publish context for the actor volume then it might not have the right details. Though, if the details are checked only for a running actor then implicitly the actor volumes are already attached and thus the DB has correct up-to-date information. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We use PublishContext to tell the worker where the attached disk is located (i.e /dev/xvdf) so it can mount it. On detach, we now explicitly wipe it from the database (PublishContext = nil). When an actor resumes, we always attach the disk and refresh this in the DB before launching the container. Answered in #1729 |
||
| for _, vol := range toUpdate.GetStatus().GetActorVolumes() { | ||
| if a, ok := attached[vol.GetVolumeName()]; ok { | ||
| vol.PublishContext = a.GetPublishContext() | ||
| vol.PublishContextNode = a.GetPublishContextNode() | ||
| } | ||
| } | ||
| return nil | ||
| }) | ||
| if updateErr != nil { | ||
| if errors.Is(updateErr, store.ErrVersionConflict) { | ||
| return nil, status.Error(codes.Aborted, "concurrent update conflict, please retry") | ||
| } | ||
| return nil, fmt.Errorf("while updating actor after volume attach: %w", updateErr) | ||
| } | ||
| return nil | ||
| return storedActor, nil | ||
| } | ||
|
|
||
| // ensureAteletRestored brings the workload up on the assigned worker: | ||
|
|
@@ -646,7 +671,7 @@ func (w *ActorWorkflow) ensureVolumesAttached(ctx context.Context, actor *ateapi | |
| // the worker pod UID, so a re-entered workflow re-sends the same semantic | ||
| // request; once atelet's Restore/Run are idempotent on those keys this step | ||
| // becomes fully reentrant with no changes here. | ||
| func (w *ActorWorkflow) ensureAteletRestored(ctx context.Context, actorRef resources.ActorRef, actor *ateapipb.Actor, actorTemplate *ateapipb.ActorTemplate, src resumeSnapshotSource) (tele restoreTelemetry, err error) { | ||
| func (w *ActorWorkflow) ensureAteletRestored(ctx context.Context, actorRef resources.ActorRef, actor *ateapipb.Actor, actorTemplate *ateapipb.ActorTemplate, node string, src resumeSnapshotSource) (tele restoreTelemetry, err error) { | ||
| ctx, done := stepSpan(ctx, "CallAteletRestore") | ||
| defer func() { err = done(err) }() | ||
|
|
||
|
|
@@ -657,7 +682,7 @@ func (w *ActorWorkflow) ensureAteletRestored(ctx context.Context, actorRef resou | |
| } | ||
| client := ateletpb.NewAteomHerderClient(ateletConn) | ||
|
|
||
| workloadSpec, err := workloadSpecFromActorTemplate(actorTemplate, actor) | ||
| workloadSpec, err := workloadSpecFromActorTemplate(actorTemplate, actor, node) | ||
| if err != nil { | ||
| return tele, err | ||
| } | ||
|
|
||
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.
Should we skip the DB update if there are no external volumes to be attached? i.e
len(attached) == 0Uh 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.
I am currently doing this. In ensuredVolumesAttached, if len(mountedVols) == 0 { return actor, nil } to immediately bypass the store update. Also, I am checking !maps.Equal(vol.GetPublishContext(), pubCtx) so we also skip the DB write if the volume is already attached to that node. Answered in #1729