Repository navigation
Conversation
| ok, err := s.provider.CanProvide(ctx, req) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if !ok { | ||
| return nil, errProviderDeclined | ||
| } | ||
| res, err := s.provider.PrepareImage(ctx, req) |
There was a problem hiding this comment.
CanProvide and PrepareImage run on the caller's ctx with no deadline of their own, and the fallback EnsureImage reuses that same ctx. If the plugin hangs, the activation times out instead of falling back to the cache. Have you considered bounding the plugin calls, like providerReleaseTimeout does for release, so the cache pull still has budget?
There was a problem hiding this comment.
Agreed. CanProvide and PrepareImage now have their own timeouts, 5 seconds and 1 minute, derived from the caller's ctx. When either expires, atelet releases any lease the plugin took and falls back to the image cache with the rest of the caller's budget. Covered by TestImageSourceEnsure.
| // serve ref. | ||
| func (s imageSource) prepare(ctx context.Context, ref, leaseID string) (*imagecache.Image, error) { | ||
| if s.keychain != nil { | ||
| ctx = providerclient.WithKeychainContext(ctx, s.keychain) |
There was a problem hiding this comment.
Since CanProvide gets the keychain too, the plugin receives registry creds for every image, even the ones it declines. Have you considered attaching the keychain only for PrepareImage?
There was a problem hiding this comment.
Agreed. atelet attaches the keychain only for PrepareImage. No plugin used the credentials in CanProvide, so I also dropped auth from CanProvideRequest in the v1alpha1 API.
| digest, err := v1.NewHash(res.ImageDigest) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("the image provider plugin returned image digest %q: %w", res.ImageDigest, err) | ||
| } | ||
| return &imagecache.Image{Digest: digest, Config: *res.Config, ProviderDirs: res.LayerDirs, LeaseID: leaseID}, nil |
There was a problem hiding this comment.
Should streamedImage reject layer dirs outside /var/lib/ate, and a digest that doesn't match a pinned ref? That way a bad plugin result falls back to the cache here instead of failing the overlay mount in the worker.
There was a problem hiding this comment.
The rootfs check already exists: the client rejects a rootfs outside the mount root, /var/lib/ate/image-provider. The LayerDirs field is gone since the API moved to one rootfs per image. I added the digest check: a digest that doesn't match the pinned ref fails prepare, the lease is released, and atelet falls back to the cache.
| defer func() { | ||
| if err == nil { | ||
| return | ||
| } | ||
| if img != nil && img.LeaseID != "" { | ||
| images.release(ctx, img.LeaseID, img.Digest.String()) | ||
| } | ||
| for _, v := range imageVolumes { | ||
| if v.LeaseID != "" { | ||
| images.release(ctx, v.LeaseID, v.ImageDigest) | ||
| } | ||
| } | ||
| }() |
There was a problem hiding this comment.
There was a problem hiding this comment.
Right, release and reconcile come in #4029. The two are stacked and will land back to back. The ImageProviderPlugin gate is off by default meanwhile, and I've noted the dependency in both descriptions.
| - name: image-provider | ||
| mountPath: /run/ate |
There was a problem hiding this comment.
Does atelet need write access to all of /run/ate? A readOnly mount of a dedicated image-provider subdir looks like enough to dial the socket.
There was a problem hiding this comment.
Agreed. Plugins now listen on /run/ate/image-provider/plugin.sock, and atelet mounts only /run/ate/image-provider, read-only. It's a directory mount so that a restarted plugin's new socket file shows up.
| cloud.google.com/go/compute/metadata v0.9.0 | ||
| cloud.google.com/go/storage v1.62.1 | ||
| github.com/Masterminds/squirrel v1.5.4 | ||
| github.com/ai-on-gke/image-provider-plugin v0.1.0 |
There was a problem hiding this comment.
What's the skew policy between atelet and the plugin while the API is v1alpha1? A version check that declines on mismatch would keep the fallback safe across independent rollouts.
There was a problem hiding this comment.
atelet and the plugin roll out independently. Within v1alpha1, changes only add fields and enum values. A breaking change gets a new proto package, and a plugin on another package answers Unimplemented, so atelet falls back to the image cache. The service name works as the version check. I wrote this down in the guide and the library overview, and added a client test for the fallback.
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.
See the review threads on agent-substrate#4026 through agent-substrate#4031.
9697ce8 to
ad08f8a
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 takes only a lease ID, and PrepareImage takes an auth key that names the registry credentials. Pass the image's repository as the auth key, so leases from one repository share credentials. Release leases by ID. Vendor the revised API and client.
Part of #4023. Includes #4025 (CachedImage) and #4026 (mount the lowerdirs). The commits from Nov 19 are as first reviewed, the next commit has the review fixes for this 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. #4027 was closed. Its metrics commit is here, so each metric lands with the code that records it.
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. Once it is tagged, go mod tidy adds its go.sum entries.Stacked with #4029: this PR takes image provider leases, and #4029 releases and reconciles them. The two land back to back. The ImageProviderPlugin gate stays off by default until then.
go.mod depends on github.com/ai-on-gke/image-provider-plugin.
atelet asks the plugin on --image-provider-socket (default /run/ate/image-provider/plugin.sock) to prepare each image that the cache does not hold, and pulls into the cache when the plugin declines or fails. CanProvide times out after 5s and PrepareImage after 1 minute. Only PrepareImage gets registry credentials, and only node-level ones. Each lease's auth key is the image's repository, so leases from one repository share credentials. atelet rejects a prepared image whose digest does not match a digest-pinned ref.
The overlay spec records the image ref and the provider lease, so atelet can release leases after a restart.
ate.imageprovider.requests counts plugin requests by outcome (success, declined, error, with error.type). A node without a plugin socket records nothing.
The atelet DaemonSet mounts the node's /run/ate/image-provider read-only for the socket.
docs/guides/image-provider.md describes the plugin, including version skew. There is no version RPC.
All of it is behind the ImageProviderPlugin preview gate, off by default.
Testing: go test -race ./cmd/atelet/... against the client mock. E2E coverage needs a plugin; see the umbrella issue.
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.