Repository navigation
Conversation
| } | ||
| } | ||
|
|
||
| s.providerLeaseMu.RLock() |
There was a problem hiding this comment.
This RLock covers the whole pull, and reconcile takes the write lock around a RPC that can take up to 30s. Since RWMutex blocks new readers once a writer is waiting, a plugin restart during a long pull, or a hung plugin, stalls every Run/Restore/Terminate on the node. Could the lock cover only the acquire-to-WriteSpec window, or could reconcile include in-flight lease IDs instead of excluding writers?
There was a problem hiding this comment.
Agreed. The RWMutex is gone. atelet now tracks leases that are taken but not yet in a spec in an in-memory set, and reconcile sends the specs plus that set. No lock is held across pulls or prepare RPCs. Reconcile still holds a plain mutex across its RPC. Otherwise a lease added after the snapshot whose prepare finishes before the plugin handles the reconcile would be dropped. That only delays registering a new lease, only during a reconcile, and for at most providerReconcileTimeout. Covered by TestReconcileProviderLeasesWithBundles.
| images.release(ctx, v.LeaseID, v.ImageDigest) | ||
| } | ||
| } | ||
| if err := os.Remove(filepath.Join(bundle, imagecache.OverlaySpecFileName)); err != nil { |
There was a problem hiding this comment.
If ReleaseImage fails we still delete the spec, and reconcile only runs on a socket change, so the lease leaks until the plugin restarts. Could we keep the spec (or the lease) when a release fails, or reconcile periodically as a backstop?
There was a problem hiding this comment.
Added a periodic reconcile every 5 minutes as a backstop. It drops any lease no spec or in-flight entry records, including after a failed release or a crash. Only a new socket resets auth and drain state, and a failed periodic pass waits for the next period. Keeping the spec wouldn't be enough on its own, because most callers reset the actor dirs right after release.
| if registration != nil { | ||
| s.systemInfoVolumes.DeregisterOwned(registration) | ||
| } | ||
| s.releaseProviderLeases(ctx, actorUID) |
There was a problem hiding this comment.
What happens if RestoreWorkload fails with a deadline after the worker started the sandbox? This defer then releases the leases and deletes the specs, which also unroots the cache layers for GC. Would it be safer to leave release to Terminate or the next reset on the paths after the worker call?
There was a problem hiding this comment.
Good catch. Run and Restore now release in the defer only if they failed before the worker call. After that, the next Run, Restore or Terminate on the node releases, and the specs keep the cache roots meanwhile. Covered by TestActivationFailureAfterWorkerCallKeepsProviderLeases.
| // providerLeaseMu is held for reading while bundles take or return | ||
| // provider leases, and for writing while atelet reconciles the plugin's | ||
| // leases with the overlay specs. | ||
| providerLeaseMu sync.RWMutex |
There was a problem hiding this comment.
Have you considered tracking leases that are taken but not yet persisted in an in-memory map, added before PrepareImage and removed after WriteSpec or release? Reconcile could then send specs plus in-flight leases under a short mutex, with no lock held across pulls or RPCs.
There was a problem hiding this comment.
Yes, done that way. See the reply above.
| if spec == nil { | ||
| continue | ||
| } | ||
| if spec.LeaseID != "" { | ||
| images.release(ctx, spec.LeaseID, spec.ImageDigest) | ||
| } | ||
| for _, v := range spec.ImageVolumes { | ||
| if v.LeaseID != "" { | ||
| images.release(ctx, v.LeaseID, v.ImageDigest) | ||
| } | ||
| } |
There was a problem hiding this comment.
Have you considered skipping specs that have no lease, and for the rest clearing the lease fields or deleting only after every release succeeds? Cache-only actors would keep their GC roots, and a failed release would keep its record.
There was a problem hiding this comment.
Specs without a lease are now skipped, so cache-only bundles keep their GC roots. A spec is removed before the release RPC, under the same mutex, which keeps release ordered against reconcile. If the removal fails, the leases stay. A failed release is dropped by the periodic reconcile. Covered by TestReleaseProviderLeases.
CachedImage returns a digest-pinned image that is complete in the store without contacting the registry, and nil otherwise. A caller can then serve such images locally and send the rest elsewhere.
An image provider plugin will prepare some images' layers under a lease that atelet must release on checkpoint and terminate, also after an atelet restart. The overlay spec now records the image ref and the plugin's lease ID, for the rootfs and for each image volume. Image.LeaseID carries the lease from the image lookup.
The worker derived each lowerdir as <layer>/fs, so only Store layers could be mounted. The overlay spec now records each image's lowerdirs, and its Store layers when it came from the Store. The worker mounts the lowerdirs as they are, and finalizes and repairs only the Store layers. GC roots only Store layers. Image.ProviderDirs holds lowerdirs that an image provider plugin returns. ReadFile reads such lowerdirs directly and treats 0:0 character devices as whiteouts. It cannot see their opaque dirs, since reading trusted.* xattrs needs CAP_SYS_ADMIN. A spec without lowerdirs stays at version 1, so older workers still read it. A spec with lowerdirs is version 2, which older workers reject. atelet writes only Store images for now, so it still writes version 1.
atelet will ask an image provider plugin to prepare image layers and fall back to the image cache when the plugin declines or fails, and will refresh the registry credentials of plugin leases. Add the ate.imageprovider.requests counter and the ate.imageprovider.duration histogram, labeled by provider and outcome, and the ate.imageprovider.auth_refresh.failures counter, labeled by provider, to the registry, ateattr, atelet's instruments and the observability guide.
atelet will talk to image provider plugins through the client in github.com/ai-on-gke/image-provider-plugin. Require v0.1.0 and vendor its API package. RegistryAuth carries registry credentials, so protoredact_test lists the imageprovider proto and pins its debug_redact fields.
A node can run an image provider plugin that prepares image layers itself, for example by lazy loading them. atelet now asks the plugin behind --image-provider-socket for each container and image volume image, and pulls into the image cache when the plugin declines or fails. Digest refs already in the cache skip the plugin. atelet names each lease after the actor, the container and, for an image volume, the volume. The overlay spec records the image ref, the lease ID and the plugin's directories as lowerdirs, so a plugin image gets a version 2 spec. A failed bundle prepare releases the leases it took. A failed PrepareImage releases its lease without a digest, since the plugin may have taken it. Each request records ate.imageprovider.requests and ate.imageprovider.duration.
atelet looks for the node's image provider plugin at /run/ate/image-provider.sock, the --image-provider-socket default. Mount the node's /run/ate into atelet so it can reach the socket.
Document --image-provider-socket, the fallback to the image cache, how atelet releases, reconciles and refreshes leases, and the suspend of actors while the plugin drains. Link to the plugin repository for the API.
The plugin was on whenever its socket existed. It is a preview feature, so atelet now prepares images through it only when the ImageProviderPlugin preview gate is on. With the gate off, atelet pulls every image into the image cache and takes no new plugin leases. It still releases, reconciles and refreshes the leases its actors hold, and suspends them when the plugin drains. ateworker needs no gate. Its version 2 overlay spec reader only runs for specs that a gated atelet writes. The guide says to turn the gate on only after every WorkerPool has rolled, so no older worker sees a version 2 spec, and that ate-setup rolls the WorkerPools when the gate changes. It also says to turn the gate off before rolling atelet back, since an older atelet cannot read version 2 specs.
…estore Each image the image provider plugin prepares holds a lease until atelet releases it. atelet now releases the leases that an actor's overlay specs record when the actor checkpoints or terminates, and when a Run or Restore fails. It removes each spec after releasing it, so a second call releases nothing. Run and Restore release them too before they reset an actor's dirs, since the reset deletes the specs of an earlier activation.
An image provider plugin keeps a lease per image use, and atelet may restart, or the plugin may restart, while actors still use their layers. Whenever the plugin socket appears or is replaced, at atelet startup or after a plugin restart, atelet sends ReconcileImages with the leases that the overlay specs on the node record. A failed reconcile is retried on the next check. An unreadable spec fails the reconcile, because the plugin would otherwise drop its leases and unmount layers that actors use. Bundle prepares and releases hold providerLeaseMu for reading, and the reconcile holds it for writing, so the plugin never learns a lease set that misses a lease taken but not yet recorded in a spec. Each ReconcileImages call is bounded by a 30s timeout, since it holds the lock that bundle prepares wait on.
See the review threads on agent-substrate#4026 through agent-substrate#4031.
69ed4f1 to
e75941d
Compare
|
Rebased onto main to resolve a go.mod conflict. No other changes. The review fixes are still in the last commit. |
The image provider plugin API changed in review. ReleaseImage and ReconcileImages take only lease IDs, ReconcileImages returns the leases the plugin could not restore, and PrepareImage takes an auth key. Release and reconcile leases by ID, and log the leases the plugin lost. Pass the image's repository as the auth key. Vendor the revised API and client.
Part of #4023. Includes #4028. This PR's 2 commits (release, reconcile) are from Nov 19, as first reviewed, the next commit has the review fixes for the whole stack, and the last commit follows the revised plugin API (ai-on-gke/image-provider-plugin#1). To see the final code, use Files changed.
Lands right after #4028, which takes the leases this PR releases and reconciles.
Blocked on
ai-on-gke/image-provider-pluginv0.1.0, which needs the API (ai-on-gke/image-provider-plugin#1) and the client. go-modules and licenses fail until it is tagged. The module is vendored, so build and tests run.run or restore, with the gate on or off. A run or restore that fails after
the worker call keeps its leases until Terminate or the next reset, since
the sandbox may have started.
sends the IDs of the leases its overlay specs record, plus those it is
taking, and the plugin drops the rest. A reconcile may run while a
PrepareImage is in flight, since the leases being taken are in the list.
atelet logs the leases the plugin reports lost, and atelet: suspend actors on a draining image provider plugin #4031 suspends their
actors.
Testing:
go test -race ./cmd/atelet/....I used an AI agent to port these commits from our fork, address review comments, and draft this description. I reviewed the code and commit messages.