Skip to content

NRI: add support for NRI with extended scope. #6019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 30, 2022

Conversation

klihub
Copy link
Member

@klihub klihub commented Sep 16, 2021

This PR is one in a set of 3 PRs, that propose and implement a prototype to extend the scope of NRI to enable common, pluggable runtime extensions. The other related PRs in this set are:

Please refer to the NRI PR for a general description of what this is all about.

@k8s-ci-robot
Copy link

Hi @klihub. Thanks for your PR.

I'm waiting for a containerd member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@theopenlab-ci
Copy link

theopenlab-ci bot commented Sep 16, 2021

Merge Failed.

This change or one of its cross-repo dependencies was unable to be automatically merged with the current state of its repository. Please rebase the change and upload a new patchset.

@theopenlab-ci
Copy link

theopenlab-ci bot commented Sep 16, 2021

Merge Failed.

This change or one of its cross-repo dependencies was unable to be automatically merged with the current state of its repository. Please rebase the change and upload a new patchset.

@thaJeztah
Copy link
Member

Looks like this was opened from a branch that was outdated; can you try rebasing your branch to get rid of the unrelated commits?

@klihub
Copy link
Member Author

klihub commented Sep 16, 2021

Looks like this was opened from a branch that was outdated; can you try rebasing your branch to get rid of the unrelated commits?

Rebased on top of main.

@theopenlab-ci
Copy link

theopenlab-ci bot commented Sep 16, 2021

Build succeeded.

Copy link
Member

@mikebrow mikebrow left a comment

Choose a reason for hiding this comment

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

thanks for the slack chat on this important and interesting project..

first review note: probably needs a couple md files/edits somewhere in the project for setup and use ... e.g. a small README.md in the contrib/nri path and maybe start a stub for a containerd/docs/nri.md file to help reviewers get started

@theopenlab-ci
Copy link

theopenlab-ci bot commented Dec 9, 2021

Merge Failed.

This change or one of its cross-repo dependencies was unable to be automatically merged with the current state of its repository. Please rebase the change and upload a new patchset.

@klihub klihub changed the title RFC: proto integration to add support for (proposed extended scope) NRI plugins. RFC: add support for proposed extended scope NRI. Dec 9, 2021
@theopenlab-ci
Copy link

theopenlab-ci bot commented Dec 9, 2021

Build succeeded.

@klihub klihub force-pushed the pr/proto/nri branch 4 times, most recently from 2352174 to fa82f0e Compare December 17, 2021 13:38
@theopenlab-ci
Copy link

theopenlab-ci bot commented Dec 17, 2021

Build succeeded.

@theopenlab-ci
Copy link

theopenlab-ci bot commented Dec 17, 2021

Build succeeded.

@fuweid
Copy link
Member

fuweid commented Dec 18, 2021

Sorry for so late reply on this pull request.

I like that idea - TTRPC-izes NRI, even if NRI is about binary call.
Currently, the containerd supports NRI hook in RunPodSandbox and StartContainer.
The number of NRI calls for one pod is more than CNI. In some cases,
like resource overcommitted work node, the fork-process pattern might have
performance issue. TTRPC-ized NRI can improve that.

But for stub of CRI, I have questions:

Is the stub used to maintain the state of container?

containerd has integrated NRI with Delete state. Basically, the stateful
daemon process will receive Creation and Delete state from NRI calls to
keep consistent with containerd state.

And currently, with common OCI-Runtime-Spec implementations, the container
process will be setup in two phases: fork(runc-create) and exec(runc start).
containerd setups the stub between two phases, which can make sure that the
resource policy can be applied to container(cgroup) in time. But like ApplyPendingUpdates
and PostCreateContainer stubs, I would like to know what kind of case it is.
If it is just a wrapper of CRI, maybe we can consider to use gRPC middleware
to export proxy plugin functionality.

Thanks,

@klihub
Copy link
Member Author

klihub commented Dec 21, 2021

Sorry for so late reply on this pull request.

No problem. And thanks for the extra effort of taking a look at this. I really appreciate it !

I like that idea - TTRPC-izes NRI, even if NRI is about binary call. Currently, the containerd supports NRI hook in RunPodSandbox and StartContainer. The number of NRI calls for one pod is more than CNI. In some cases, like resource overcommitted work node, the fork-process pattern might have performance issue. TTRPC-ized NRI can improve that.

But for stub of CRI, I have questions:

One thing related to this. Based on our discussion with @mikebrow, we would like to eventually extend our integration/implementation to also handle containers created using other 'frontends' protocols than just CRI (ctr and docker in particular). We rolled our initial implementation this way, partly because the current NRI integration is NRI-only and partly because we'd like to better understand all the implications and problems related to extending it to the rest.

Is the stub used to maintain the state of container?

I assume here that by 'stub of CRI' you mean the code added in this patch set to the CRI plugin for triggering NRI processing and altering containers accordingly. Please let me know if this assumption is wrong.

That stub, the new NRI-related additions/adaptation, does not maintain state of the containers on its own. It basically does the following things:

  • state synchronization with NRI
  • hook NRI into (CRI) request processing/pod and container lifecycle events
  • handle NRI-triggered updates to containers

State synchronization lets NRI know about all existing pods and containers on startup. Additionally, it allows any NRI plugin that establishes a connection to NRI dynamically to synchronize itself. For request processing, the stub gathers all the necessary data for plugins, makes the call to NRI, then takes the response and applies the necessary changes to containers, also making sure that the changes are applied in the correct order. There are slight differences in how containerd and cri-o mangle and store some of the data carried by CRI into an OCI container, for instance the details of how labels and annotations get converted (if at all) to OCI annotations. We want to hide these differences as much as possible from NRI plugins, so we need to have some extra processing/logic for this in the runtime NRI adaptation.

containerd has integrated NRI with Delete state. Basically, the stateful daemon process will receive Creation and Delete state from NRI calls to keep consistent with containerd state.

Yes, I've tried to follow the same pattern. When containers are stopped, hooking in NRI processing is done in a similar fashion as deletion is handled for the original NRI plugins.

And currently, with common OCI-Runtime-Spec implementations, the container process will be setup in two phases: fork(runc-create) and exec(runc start). containerd setups the stub between two phases, which can make sure that the resource policy can be applied to container(cgroup) in time. But like ApplyPendingUpdates and PostCreateContainer stubs, I would like to know what kind of case it is.

ApplyPendingUpdates applies any updates which might have occured after NRI itself has processed the create request (at which point the container being created became visible to NRI plugins) but before the creation of the container has been fully processed by containerd/the runtime itself.

The primary purpose of Post* stub calls is to allow a plugin to perform any extra action outside of the realm of control of OCI if necessary. Additionally, these provide a mechanism for a plugin to acquire the final state a container ended up in, once it has been processed by all NRI plugins.

If it is just a wrapper of CRI, maybe we can consider to use gRPC middleware to export proxy plugin functionality.

They are not just pure wrappers. Many of them, at least the ones that can result in modifications to containers, need to happen at a particular point during the processing of the corresponding CRI request. So I think these can't really be implemented as a pure add-on that would happen in addition to opaque processing of the related CRI request. I guess those requests that can't result in container modifications could in principle be implemented like that (pod-related ones and the Post* ones). But even for those I'm not sure if digging out all the necessary information for hooking in NRI would be really possible from 'outside' of the CRI plugin.

Thanks,

If I misunderstood some aspect of your questions, please let me know.

@fuweid fuweid added this to the 1.7 milestone Feb 20, 2022
@klihub klihub force-pushed the pr/proto/nri branch 2 times, most recently from a258b9e to ea21711 Compare May 10, 2022 08:24
@klihub klihub force-pushed the pr/proto/nri branch 4 times, most recently from f360d32 to 15e6f73 Compare November 21, 2022 10:17
Copy link
Member

@mikebrow mikebrow left a comment

Choose a reason for hiding this comment

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

LGTM with adding the following TODO's:

  • TODO before release: change to default enabled without experimental warning, in order to enable v010 nri plugins this needs to be reconsidered before release, by default should include the v010 adapter in the release - and it should probably be loaded by default not through the ttrpc but as a pre-registered.

  • TODO before release: having two configs to enable nri is confusing /etc/nri/nri.conf vs containerd/config.toml

on bringing down the logging plugin I get an error:

ERRO[2022-11-22T11:57:26.541929641-06:00] error receiving message                       error="failed to read header from trunk: EOF"
INFO[2022-11-22T11:57:26.541953042-06:00] connection to plugin "00-logger" closed      
INFO[2022-11-22T11:57:26.542130540-06:00] ttrpc server for plugin "00-logger" closed (ttrpc: server closed) 

TODO: is there a way to eat that error message and just close?

@klihub
Copy link
Member Author

klihub commented Nov 22, 2022

on bringing down the logging plugin I get an error:

ERRO[2022-11-22T11:57:26.541929641-06:00] error receiving message                       error="failed to read header from trunk: EOF"
INFO[2022-11-22T11:57:26.541953042-06:00] connection to plugin "00-logger" closed      
INFO[2022-11-22T11:57:26.542130540-06:00] ttrpc server for plugin "00-logger" closed (ttrpc: server closed) 

TODO: is there a way to eat that error message and just close?

Yes. I updated it and now if you bring down the plugin it's logged like this:

INFO[2022-11-22T21:08:39.727035268Z] plugin "00-logger" connected
...
INFO[2022-11-22T21:08:41.055532101Z] connection to plugin "00-logger" closed

Copy link
Member

@mikebrow mikebrow left a comment

Choose a reason for hiding this comment

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

LGTM to merge with the following TODO's for follow ups:

  • TODO: after merging this PR and Extend scope to enable common pluggable runtime extensions. nri#16 remove temporary vendor divert to github.com/klihub/nri
  • TODO before release: change to default enabled without experimental warning, in order to enable v010 nri plugins this needs to be reconsidered before release, by default should include the v010 adapter in the release - and it should probably be loaded by default not through the ttrpc but as a pre-registered.
  • TODO before release: having two configs to enable nri is confusing /etc/nri/nri.conf vs containerd/config.toml

@klihub
Copy link
Member Author

klihub commented Nov 22, 2022

  • TODO before release: having two configs to enable nri is confusing /etc/nri/nri.conf vs containerd/config.toml

I can change the initialization code in NRI itself so that the lack of a configuration file is treated as an empty configuration (file) instead of an initialization error (which then results in NRI getting disabled). With that change, NRI could be enabled by simply enabling it in the containerd config.

klihub and others added 5 commits November 28, 2022 21:51
Add a common NRI 'service' plugin. It takes care of relaying
requests and respones to and from NRI (external NRI plugins)
and the high-level containerd namespace-independent logic of
applying NRI container adjustments and updates to actual CRI
and other containers.

The namespace-dependent details of the necessary container
manipulation operations are to be implemented by namespace-
specific adaptations. This NRI plugin defines the API which
such adaptations need to implement.

Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
Implement the adaptation interface required by the NRI
service plugin to handle CRI sandboxes and containers.
Hook the NRI service plugin into CRI request processing.

Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
Remove direct invocation of old v0.1.0 NRI plugins. They
can be enabled using the revised NRI API and the v0.1.0
adapter plugin.

Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
Co-authored-by: Mike Brown <brownwm@us.ibm.com>
Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
Copy link
Member

@mikebrow mikebrow left a comment

Choose a reason for hiding this comment

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

LTGM ready to merge IMO can do TODOs in followups

@mxpv
Copy link
Member

mxpv commented Apr 7, 2023

Removing backport label, added in #7954

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

8 participants