Skip to content

Restore external volumes from a snapshot the template names - #3785

Draft
Sneha-at (Sneha-at) wants to merge 23 commits into
agent-substrate:mainfrom
Sneha-at:external-volume-snapshot-import
Draft

Sneha-at (Sneha-at) wants to merge 23 commits into
agent-substrate:mainfrom
Sneha-at:external-volume-snapshot-import

Conversation

@Sneha-at

@Sneha-at Sneha-at (Sneha-at) commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #1951. Stacked on #3772: review the last two commits.

A template can now import a snapshot taken outside Substrate. ExternalVolumeTemplate gains content_source.snapshot.storage_snapshot_id, and each Actor of the template restores its volume from that snapshot on its first resume.

volumes:
- name: data
  external:
    template:
      capacityBytes: 10737418240
      storageClassName: csi-nfs-sc
      contentSource:
        snapshot:
          storageSnapshotId: <snapshot-id>

A tag's snapshot of the volume takes precedence over the template's:

Tag the Actor is created from Volume restores from
--with-volumes tag snapshot
--with-volumes=a,b including the volume tag snapshot
--with-volumes=a,b excluding the volume template snapshot
no --with-volumes, or no tag template snapshot

CreateActor fails with FAILED_PRECONDITION when the volume's driver cannot restore snapshots. It does not look the snapshot up, so a missing snapshot fails the first resume.

VolumeContentSource is a union with one member so that other sources can be added without a new field.

An older ate-api-server ignores content_source and drops it from the stored template on its next status write. The CSI volumes guide lists this under known limitations.

AI use: drafted with an AI agent under my direction.

  • Tests pass: apivalidation rows, a unit test for the driver check, a functional test covering each row of the table, and a new tagvolumes/TemplateContentSource e2e subtest (passes on kind with gVisor; microVM in CI). hack/verify-all.sh passes.
  • Docs updated: CSI volumes guide, API guide, kubectl reference.

An ExternalVolumeSnapshot records one external volume snapshot. It is
owned by the tag in origin.tag, in the same atespace. The API has Get
and List only, and viewers of the atespace may use them.

Signed-off-by: Sneha Aradhey <snehaaradhey@google.com>
Snapshots live in a new external_volume_snapshots table. Foreign keys
keep a tag or its atespace from being deleted while the tag owns
snapshots, and DeleteTag reports that as FailedPrecondition.

Create locks the tag row, and refuses a tag with a different uid, one
being deleted, or one without a PENDING durable snapshot.

No request carries a snapshot, so validation-gen generates no validator
for it. The store validates every write by hand, and lets an update
change only status: the handle and size are set once, ready_to_use only
becomes true, ready_to_use and size_bytes need a handle, and
error_message is cleared only by the write that records the handle.

GetExternalVolumeSnapshot and ListExternalVolumeSnapshots need the
ExternalVolumes preview gate and a client that opts in.

Signed-off-by: Sneha Aradhey <snehaaradhey@google.com>
The command lists or gets snapshots in an atespace or all atespaces.
--tag keeps the snapshots of one tag, filtered in the client since the
API has no filter. It needs --atespace, because a tag name is unique
only within an atespace. The STATE column is derived from status.

Signed-off-by: Sneha Aradhey <snehaaradhey@google.com>
Opt ExternalVolumeSnapshot into validation-gen and add the custom
validators its tags name. ServiceImpl now validates creates, and
validates updates against the stored snapshot, so unchanged values are
not re-validated. It reports changes to immutable fields as
ErrImmutableField, like the store. The store keeps only the checks on
the fields its rows are keyed by. Add ServiceImpl tests for update
validation and ratcheting.

Rename volume_type to driver_name, origin.tag to origin.tag_capture,
storage_snapshot_id to snapshot_id and size_bytes to
restore_size_bytes. Reads no longer need the ExternalVolumes gate.

This addresses review comments.

Signed-off-by: Sneha Aradhey <snehaaradhey@google.com>
MarkTagForDeletion checks for the tag's ExternalVolumeSnapshots in the
transaction that sets delete_time. The transaction runs at READ
COMMITTED, and the UPDATE's row lock conflicts with the FOR SHARE lock
that CreateExternalVolumeSnapshot takes, so the check and snapshot
creation serialize. A refused delete leaves the tag and its snapshot
untouched and can be retried. DeleteTag maps only the snapshot foreign
key, or a partition's copy of it, to a failed precondition.

This addresses review comments.

Signed-off-by: Sneha Aradhey <snehaaradhey@google.com>
…shot

Keep the old spellings as aliases. --tag takes <atespace>/<tag-name> or
a bare name with -a, and rejects malformed values.

This addresses review comments.

Signed-off-by: Sneha Aradhey <snehaaradhey@google.com>
Readers derive a snapshot's lifecycle from its status fields, the way a
tag's lifecycle follows from its fields. A status-level custom validator
keeps those fields consistent. snapshot_id and error_message are never
both set, and ready_to_use and restore_size_bytes need snapshot_id. Only
the write that records snapshot_id may clear error_message. An update
does not re-check a rule whose fields it left unchanged.

The field update tags already keep snapshot_id and restore_size_bytes
set once, and ready_to_use from going back to false. A stored status
can no longer be dropped, since that would bypass those tags.

Signed-off-by: Sneha Aradhey <snehaaradhey@google.com>
Global ListExternalVolumeSnapshots could return a page token longer than
ListOptions.page_token allows when the atespace and name are both 63
characters. The page token kind is now "evs".

MarkTagForDeletion checks for snapshots before it runs mutate, so a tag
that a previous attempt already marked is refused too.

kubectl ate get external-volume-snapshot accepts only the kebab-case
names. An explicit empty --tag fails, and a malformed -a is reported as
such.

Add the missing test cases the review asked for, and merge the update
validation test into one table.

Signed-off-by: Sneha Aradhey <snehaaradhey@google.com>
Tags are the only origin of an ExternalVolumeSnapshot until import
support lands. tag_name and tag_uid are NOT NULL, and the check that
paired their NULLs is gone. Drop the test that wrote a snapshot without a
tag, and the proto note about a planned imported origin.

driver_name follows the volume_type rule, not the CSI driver-name syntax.
The handle fields reject the control characters storage_volume_id
rejects, which leaves tab, LF and CR allowed.

Signed-off-by: Sneha Aradhey <snehaaradhey@google.com>
DeleteTag must delete a tag's snapshots while the tag is marked, so
MarkTagForDeletion no longer refuses a tag that owns snapshots. New
snapshots are still refused once the tag is marked, and the foreign key
still keeps a tag with snapshots from being dropped.

Add ListTagExternalVolumeSnapshots, DeleteExternalVolumeSnapshot, and
UpdateTagExternalVolumeSnapshots, which updates all of a tag's
snapshots in one transaction. ServiceImpl validates each update in the
batch against the stored snapshot.

Signed-off-by: Sneha Aradhey <snehaaradhey@google.com>
CreateTagRequest gains volume_selection. CreateTag records an
ExternalVolumeSnapshot with an empty status for each selected volume,
takes the CSI snapshots concurrently, and records every result in one
transaction: the handle with ready_to_use and restore_size_bytes, or
the driver's error. Capture is all-or-nothing, so any failure leaves the
tag pending.

DeleteTag marks the tag, deletes each storage snapshot and then its row,
then releases the external snapshot and drops the tag. A row without a
handle has it recovered with the idempotent CreateSnapshot. A failed
recovery keeps the tag for a retry.

Signed-off-by: Sneha Aradhey <snehaaradhey@google.com>
CreateTag now returns a code based on the driver's error instead of
Internal. A failed capture leaves the tag pending, so transient codes
become Aborted and the message says to delete the tag and create it
again. DeleteTag skips recovery for drivers without snapshot support and
for terminal CreateSnapshot errors, and keeps the row on transient ones.

Signed-off-by: Sneha Aradhey <snehaaradhey@google.com>
A bare --with-volumes captures every external volume, and
--with-volumes=a,b captures only those. Names separated from the flag
by a space get a hint to join them with =.

Signed-off-by: Sneha Aradhey <snehaaradhey@google.com>
…dles

Some drivers, like the Compute Engine PD driver, use the snapshot name as
a resource name limited to 63 characters. The volume name is hashed so the
name is always 62 characters. DeleteTag writes a recovered handle to the
ExternalVolumeSnapshot, so a retry deletes it by handle instead of cutting
the snapshot again.

Signed-off-by: Sneha Aradhey <snehaaradhey@google.com>
When the latest snapshot is a pending upload on a lost node, CreateTag
falls back to an older durable snapshot. Volumes hold what the latest
suspend wrote, so tagging them with that snapshot pairs old guest memory
with newer disks. CreateTag now fails with FailedPrecondition instead.

Signed-off-by: Sneha Aradhey <snehaaradhey@google.com>
DeleteTag treats ResourceExhausted as transient and keeps the row, since
drivers return it for rate limits and quota that clear over time. It
releases a tag's volume snapshots concurrently, as CreateTag takes them,
so many volumes do not run past the client deadline. ensureTagFinalized
maps store errors with tagCreateUpdateError, like the other create steps.

Selecting all volumes of an Actor with none fails with
FailedPrecondition, since it depends on the Actor's state.

--with-volumes rejects "*" among names and empty names, and the hint for
names after a bare --with-volumes quotes the argument it guessed.

Add tests for volumes on two drivers, a driver that returns no handle, a
pending snapshot promoted before its volumes are tagged, CreateActor from
a tag with volumes, and the createTagArgs hint. Fix comments on quiescing
and the tag authorization TODO.

Marking the tag bumps its version, so a retry that reuses the first
attempt's version precondition fails with Aborted.

Signed-off-by: Sneha Aradhey <snehaaradhey@google.com>
CreateActor no longer refuses a tag for a template with external
volumes. It copies the handle of each ExternalVolumeSnapshot the tag
owns to the new source_snapshot_id field of the matching volume, and
the first resume restores the volume from it. A volume the tag did not
capture starts empty.

CreateActor fails while a snapshot is not ready to use, and records
ready_to_use for one the driver now reports ready. A snapshot from a
driver that cannot report readiness is used as is. Resume maps
CreateVolume errors by code instead of returning Internal for all of
them.

Signed-off-by: Sneha Aradhey <snehaaradhey@google.com>
…shot

CreateTag does not wait for volume snapshots to be ready. GetTag now
asks the driver about each ExternalVolumeSnapshot of a finished tag that
has a handle but is not ready to use, and sets ready_to_use on the ready
ones, so callers can see when the tag can seed an Actor.
GetExternalVolumeSnapshot does the same for one snapshot. Neither
refreshes the snapshots of a tag being deleted, and a failed lookup or
write is only logged.

Signed-off-by: Sneha Aradhey <snehaaradhey@google.com>
The tagvolumes e2e suite tags an Actor with two external volumes and
creates Actors from the tag. It checks that every captured volume is
restored, that a named subset restores only those volumes, and that a tag
without volume_selection restores nothing. It also checks that clones and
the source do not share writes, that a tag restores after its source
Actor is deleted, and that DeleteTag removes the snapshots from the dev
NFS server.

The probe file helpers move from combinedvolumes to internal/e2e, so both
suites use them.

The API, kubectl and CSI volumes docs describe the restore. The CSI
volumes guide lists two known limitations of an ate-api-server from an
older release: it provisions a restored Actor's volumes empty, and it
cannot delete a tag that owns volume snapshots.

nfsExportHas passes the e2e kube context to kubectl, so the check runs
against the cluster under test.

List returns the stored state and never asks the driver, so --tag does
not show a snapshot becoming ready. Getting a snapshot by name does. Also
say which control characters source_snapshot_id rejects.

Signed-off-by: Sneha Aradhey <snehaaradhey@google.com>
CreateTag writes every volume's snapshot result in one batch. A handle
longer than snapshot_id allows, or one with control characters, failed
the whole write and dropped the other handles. Check each status first
and record a rejected one as that volume's error. DeleteTag recovers the
handle from the driver and deletes the snapshot.

A negative size_bytes from a CSI driver is now treated as unknown.

Add a TODO for ref and RWX volumes in selectTagVolumes.

Signed-off-by: Sneha Aradhey <snehaaradhey@google.com>
GetExternalVolumeSnapshot refreshed a snapshot even when its tag was
still PENDING. Both refresh paths now skip a tag that is not COMPLETED
or is being deleted.

A failed snapshot lookup in CreateActor returned Internal for every
error. Unavailable, DeadlineExceeded and ResourceExhausted now pass
through, as they do for CreateVolume.

A provisioned volume keeps source_snapshot_id, so its status shows which
snapshot it was restored from. The field can no longer be unset.

A negative size from the driver is not recorded as restore_size_bytes.

The tagvolumes e2e now checks that volumes a tag left out are writable,
and the kubectl docs show --preview for create actor --tag.

Signed-off-by: Sneha Aradhey <snehaaradhey@google.com>
ExternalVolumeTemplate gains content_source, which names a snapshot in
the storage system, possibly one taken outside Substrate. Each Actor of
the template restores its volume from it on the first resume.

A tag's snapshot of the volume takes precedence. A volume the tag did not
capture, or any volume of an Actor not created from a tag, starts from
the template's snapshot.

CreateActor fails with FailedPrecondition if the volume's driver cannot
restore snapshots.

Signed-off-by: Sneha Aradhey <snehaaradhey@google.com>
The tagvolumes suite takes a tag of a source Actor, then creates a template
whose data volume imports the tag's data snapshot. An Actor of that
template starts with the source's data. Actors created from its tags
restore data from the tag when the tag captured it, and from the
template's snapshot when it did not.

Signed-off-by: Sneha Aradhey <snehaaradhey@google.com>
@Sneha-at
Sneha-at (Sneha-at) force-pushed the external-volume-snapshot-import branch from d0fb8df to bcac681 Compare November 24, 2026 18:33

This branch has not been deployed

No deployments
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.

1 participant