Skip to content

cri: add streaming RPCs - #13187

Merged
mxpv merged 1 commit into
containerd:mainfrom
bitoku:cri-list-streaming
Jul 23, 2026
Merged

mxpv merged 1 commit into
containerd:mainfrom
bitoku:cri-list-streaming

Conversation

@bitoku

@bitoku bitoku commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

Implements CRI List Streaming

Add server-streaming variants of CRI list RPCs (StreamContainers, StreamPodSandboxes, StreamContainerStats, StreamPodSandboxStats, StreamPodSandboxMetrics, StreamImages) that send results in batches of 5000 items (it's half of the estimated limit https://github.com/kubernetes/enhancements/tree/master/keps/sig-node/5825-cri-pagination#motivation)

Size calculation will slow down the RPCs. See kubernetes/kubernetes#136987 (comment) for the details.

Fixes #12814

cc @samuelkarp @SergeyKanzhelev

@github-project-automation github-project-automation Bot moved this to Needs Triage in Pull Request Review Apr 8, 2026
@dosubot dosubot Bot added area/cri Container Runtime Interface (CRI) kind/feature labels Apr 8, 2026
@bitoku
bitoku force-pushed the cri-list-streaming branch 2 times, most recently from bec4ab9 to 06658ad Compare April 8, 2026 16:05
@SergeyKanzhelev

Copy link
Copy Markdown
Contributor

New tests seems to be failing.

@SergeyKanzhelev

Copy link
Copy Markdown
Contributor

/assign @samuelkarp

(as shepherd from #12814)

@bitoku

bitoku commented May 26, 2026

Copy link
Copy Markdown
Contributor Author

Can anyone take a look?

@bitoku

bitoku commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

Hi @samuelkarp ! Can you please take a look? thanks!

@SergeyKanzhelev

Copy link
Copy Markdown
Contributor

/retest
/cc @mikebrow

@k8s-ci-robot
k8s-ci-robot requested a review from mikebrow June 4, 2026 16:53
@mxpv
mxpv force-pushed the cri-list-streaming branch from 8099d75 to 3129f83 Compare July 1, 2026 16:20
Comment thread internal/cri/server/stream.go Outdated

import "context"

const defaultStreamBatchSize = 5000

@mxpv mxpv Jul 1, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you measure this somehow? (I also noticed that crio did 3000). My understanding of the KEP is that the goal is to avoid gRPC max message failures on large nodes. Fixed 5000 likely mitigates it a lot, but this guarantee is incomplete given that contracts has no fixed size. Would using https://pkg.go.dev/google.golang.org/protobuf/proto#Size make more sense? (e.g. define batch size in bytes and pack messages while remaining size > 0)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the motivation in the CRI pagination KEP, the estimated limit is around 10,000. For context, issue #134750 shows it failing with roughly 18.5k containers. I roughly halved or 1/3 the value.

I avoided using proto.Size() because it was 5–10% slower than using a fixed batch size (see this comment). While that performance hit might be acceptable, a fixed batch size solves the bulk of the problem anyway, which is why I went with this approach.

That said, I'm starting to think it might be better to make this configurable. What do you think?

runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
)

const defaultStreamBatchSize = 5000

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you extract sendInBatches into a common package, so we define this once?
(internal/cri/util or internal/cri/io) ?

return err
}

return errors.Join(errs...)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for my understanding. Do we want to send the whole stream first, and then errors at very end?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah this is wrong. Thanks.

We should return an error as soon as we get the error, like StreamContainerStats.

@bitoku
bitoku force-pushed the cri-list-streaming branch from 3129f83 to 8799415 Compare July 4, 2026 19:55
@bitoku

bitoku commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

@mxpv Can you take another look?


import "context"

const DefaultStreamBatchSize = 5000

@mikebrow mikebrow Jul 12, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the CRI client getting these lists is not the only workload running on the host... and the resource availability over time will vary widely. I agree with your proposal to make this a new config field

@mikebrow mikebrow Jul 12, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as to the performance issue, avoiding "proto.Size() because it was 5–10% slower than using a fixed batch size"

an alternative would be to intermittently, keep a variable calculated from proto.Size(), and use the config as a "min/max" option

essentially auto tuning bytes used based on actuals...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does config has to be part of this PR? It would be great to merge this PR so feature gate can be scheduled for promotion in 1.38

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is fair to do config and further optimization investigations in a follow up to this PR

Add server-streaming variants of CRI list RPCs (StreamContainers,
StreamPodSandboxes, StreamContainerStats, StreamPodSandboxStats,
StreamPodSandboxMetrics, StreamImages) that send results in batches
of 5000 items.

Signed-off-by: Ayato Tokubi <[email protected]>
@mikebrow
mikebrow force-pushed the cri-list-streaming branch from 8799415 to 47c7085 Compare July 23, 2026 14:58

@mikebrow mikebrow left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM on green with a follow-up after merge for configuration and further tuning.

@github-project-automation github-project-automation Bot moved this from Needs Triage to Review In Progress in Pull Request Review Jul 23, 2026
@bitoku

bitoku commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

Sorry I've been busy, and don't have time to look into it. I'll follow it up with the config PR later.

@mikebrow
mikebrow added this pull request to the merge queue Jul 23, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 23, 2026
@mxpv
mxpv added this pull request to the merge queue Jul 23, 2026
Merged via the queue into containerd:main with commit a827063 Jul 23, 2026
89 of 90 checks passed
@github-project-automation github-project-automation Bot moved this from Review In Progress to Done in Pull Request Review Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/cri Container Runtime Interface (CRI) kind/feature size/XXL

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

[SIG-Node]: KEP-5825: CRI List Streaming

6 participants