In the arch committee meeting last week, Michael Crosby introduced the containerd shim API v2. After the meeting, read related documents, patches, and discussed with @bergwolf @lifupan and related folks. And I think we could begin to implement the kata shim for containerd v2 API now.
Right now, containerd and runtime work in the following pattern:

Whenever containerd tries to create a container,
runtime=kata flag, and the cli should be compatible with runcThough the containerd-shim designed to be an replaceable component
With the proposed shim v2 API, the most significant change is
As a result
Then the architecture may change to the follows:

And in v2 API, stats function is moved to shim, which makes the shim more self-contained.
This is a good proposal, and simplifies the architecture a lot!
One question: I think we need to keep the compatibility with older containerd-shim, we can't only support containerd-shim V2 because it's so new.
@WeiZhang555 I agree we should keep the runc compatible cli as long as possible. For this new shim, IMO it should have its own repo so that in future we can push it to containerd to be a first class citizen there.
As said during the Arch committee meeting, I would like to see the Kata implementation of the containerd-shim v2 as a separate directory (different repo might come further down the road, but right now, let's keep this simple). The same way we have the cli directory for our OCI implementation (matching runc as much as possible), we would have a new containerd-shim-v2 directory providing the Kata implementation of this shim v2. Most of the implementation will follow what frakti is actually leveraging (stateless Kata API), to be more efficient.
@gnawux let us know who will work on that, and how we can help with this (if there are some areas where the work can be split).
Looks good!
And as @crosbymichael described in the Arch Committee meeting, containerd-shim-v2 isn't aware of POD concept, so the containerd-shim should be one per container, so I think the final arch should be:

Is this right? @gnawux
@WeiZhang555 we investigated the APIs and code in the PR and has the following conclusion -- though containerd will request shim service for every container, it does not expect there is a new shim socket or process for the container. As a result, we think it could be implemented as one shim per pod. Let's just try to prove it with a prototype.
@WeiZhang555 Per discussions in containerd/containerd/issues/2426, containerd-shim-v2 start can return the unix socket address of a previously started shim. That's how one shim per pod is supposed to be implemented.
Oh, cool, this sounds a little hacky but workable.
Yes, that is correct. We updated the v2 API to introduce a start command for the shims. This way the shims can configure and launch new shims how they need to. It also allows this start command to inspect the spec, look at annotations for pods, and return an existing shim instead of creating a new one. If one does not already exist, it can start one.
I pushed an README this morning for shim authoring. Please take a look and provide any feedback if you have questions or if something does not make sense.
https://github.com/containerd/containerd/pull/2434/files#diff-9bb937a499e2e6fdc4536481d6315c50
thank you @crosbymichael. One more question -- is it essential for a v2shim commandline to implement the "no action" behavior
default:
client := NewShimClient(ctx, service, signals)
return client.Serve()
or it's ok to support start and delete only?
If you want to split it into multiple binaries then that is fine, all we care about is that start returns a socket to the API and delete lets us call for a cleanup if a shim dies and we can no longer communicate to it.
[Update] A temporary branch has been created in develop repo here.
Will send out PRs to upstream when core apis are ready so you can set up basic tests.
Nice @resouer . Just for ref, link to branch itself is here I think? (link above goes to closed PRs in that repo afaict).
@grahamwhaley Oh, yes. The link I posted seems to be the merged PRs to that branch :/
Looking forward to the implement !
@Ace-Tang PR #572 has already been there under review. Comments are welcome
Most helpful comment
If you want to split it into multiple binaries then that is fine, all we care about is that
startreturns a socket to the API anddeletelets us call for a cleanup if a shim dies and we can no longer communicate to it.