-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add support for latest NRI with extended scope. #5318
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
907f4ed
config,cli: add support for NRI configuration.
klihub 773e6e0
nri: add experimental NRI adaptation interface.
klihub 36305e7
server: hook NRI into request processing.
klihub ab73c1d
test/nri: add a test client with basic NRI tests.
klihub 54b7b5f
test, Makefile: hook NRI tests into localintegration.
klihub File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| TOPDIR="${0%/*}/.." | ||
| NRITEST_BINARY="$TOPDIR/test/nri/nri.test" | ||
| NRI_BATS="$TOPDIR/test/nri.bats" | ||
|
|
||
| status=0 | ||
| for i in $($NRITEST_BINARY -test.list Test); do | ||
| if ! grep -q -e "-test.run $i"' *$' "$NRI_BATS"; then | ||
| echo "NRI test case $i missing from $(realpath --relative-to "$TOPDIR" "$NRI_BATS")" | ||
| status=1 | ||
| fi | ||
| done | ||
| exit "$status" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package nri | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| nri "github.com/containerd/nri/pkg/adaptation" | ||
| ) | ||
|
|
||
| // Config represents the CRI-O NRI configuration. | ||
| type Config struct { | ||
| Enabled bool `toml:"enable_nri"` | ||
| ConfigPath string `toml:"nri_config_file"` | ||
| SocketPath string `toml:"nri_listen"` | ||
| PluginPath string `toml:"nri_plugin_dir"` | ||
| } | ||
|
|
||
| // New returns the default CRI-O NRI configuration. | ||
| func New() *Config { | ||
| return &Config{ | ||
| ConfigPath: nri.DefaultConfigPath, | ||
| SocketPath: nri.DefaultSocketPath, | ||
| PluginPath: nri.DefaultPluginPath, | ||
| } | ||
| } | ||
|
|
||
| // Validate loads and validates the effective runtime NRI configuration. | ||
| func (c *Config) Validate(onExecution bool) error { | ||
| if c.Enabled { | ||
| _, err := nri.ReadConfig(c.ConfigPath) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to load %q: %w", c.ConfigPath, err) | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // ToOptions returns NRI options for this configuration. | ||
| func (c *Config) ToOptions() []nri.Option { | ||
| opts := []nri.Option{} | ||
| if c != nil && c.ConfigPath != "" { | ||
| opts = append(opts, nri.WithConfigPath(c.ConfigPath)) | ||
| } | ||
| if c != nil && c.SocketPath != "" { | ||
| opts = append(opts, nri.WithSocketPath(c.SocketPath)) | ||
| } | ||
| if c != nil && c.PluginPath != "" { | ||
| opts = append(opts, nri.WithPluginPath(c.PluginPath)) | ||
| } | ||
| return opts | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package nri_test | ||
|
|
||
| import ( | ||
| "os" | ||
|
|
||
| "github.com/cri-o/cri-o/internal/config/nri" | ||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
| ) | ||
|
|
||
| func tempFileWithData(data string) string { | ||
| f := t.MustTempFile("") | ||
| Expect(os.WriteFile(f, []byte(data), 0o644)).To(BeNil()) | ||
| return f | ||
| } | ||
|
|
||
| // NRI configuration tests. | ||
| var _ = t.Describe("When parsing NRI config file", func() { | ||
| t.Describe("non-existent file", func() { | ||
| It("should return an error", func() { | ||
| cfg := nri.New() | ||
| cfg.Enabled = true | ||
| cfg.ConfigPath = "non-existent-file" | ||
| err := cfg.Validate(true) | ||
| Expect(err).NotTo(BeNil()) | ||
| }) | ||
| }) | ||
|
|
||
| t.Describe("invalid file format", func() { | ||
| It("should return an error", func() { | ||
| f := tempFileWithData(`fooBar: | ||
| - none | ||
| `) | ||
| cfg := nri.New() | ||
| cfg.Enabled = true | ||
| cfg.ConfigPath = f | ||
| err := cfg.Validate(true) | ||
| Expect(err).NotTo(BeNil()) | ||
| }) | ||
| }) | ||
|
|
||
| t.Describe("correct file format", func() { | ||
| It("should not return an error", func() { | ||
| f := tempFileWithData(`disableConnections: true | ||
| `) | ||
| cfg := nri.New() | ||
| cfg.Enabled = true | ||
| cfg.ConfigPath = f | ||
| err := cfg.Validate(true) | ||
| Expect(err).To(BeNil()) | ||
| }) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package nri_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| . "github.com/cri-o/cri-o/test/framework" | ||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
| ) | ||
|
|
||
| // TestLib runs the created specs | ||
| func TestLibConfig(t *testing.T) { | ||
| RegisterFailHandler(Fail) | ||
| RunFrameworkSpecs(t, "NRIConfig") | ||
| } | ||
|
|
||
| var t *TestFramework | ||
|
|
||
| var _ = BeforeSuite(func() { | ||
| t = NewTestFramework(NilFunc, NilFunc) | ||
| t.Setup() | ||
| }) | ||
|
|
||
| var _ = AfterSuite(func() { | ||
| t.Teardown() | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.