From 23ffb6f781c654dad51014b048e470d542fc42ca Mon Sep 17 00:00:00 2001 From: Benjamin Leggett Date: Mon, 8 Apr 2024 12:02:23 -0400 Subject: [PATCH] Change `disableLoadPluginsFromPath` -> `loadOnlyInlinedPlugins` Signed-off-by: Benjamin Leggett --- SPEC.md | 10 +++++----- libcni/api.go | 2 +- libcni/conf.go | 24 ++++++++++++------------ libcni/conf_test.go | 40 ++++++++++++++++++++-------------------- 4 files changed, 38 insertions(+), 38 deletions(-) diff --git a/SPEC.md b/SPEC.md index b0632758..e0ee2034 100644 --- a/SPEC.md +++ b/SPEC.md @@ -111,8 +111,8 @@ A network configuration consists of a JSON object with the following keys: - `cniVersions` (string list): List of all CNI versions which this configuration supports. See [version selection](#version-selection) below. - `name` (string): Network name. This should be unique across all network configurations on a host (or other administrative domain). Must start with an alphanumeric character, optionally followed by any combination of one or more alphanumeric characters, underscore, dot (.) or hyphen (-). Must not contain characters disallowed in file paths. - `disableCheck` (boolean): Either `true` or `false`. If `disableCheck` is `true`, runtimes must not call `CHECK` for this network configuration list. This allows an administrator to prevent `CHECK`ing where a combination of plugins is known to return spurious errors. -- `disableLoadPluginsFromPath` (boolean): Either `true` or `false`. If `false` (default), indicates [plugin configuration objects](#plugin-configuration-objects) should be loaded from a sibling directory with the same name as the network `name` field. These sibling directories should exist at the same path as the network configuration itself. Any valid plugin configuration objects within a named sibling directory will be appended to the final list of `plugins` for that network name. If set to `true`, plugin configuration objects in sibling directories will be ignored. If `plugins` is not present in the network configuration, `disableLoadPluginsFromPath` cannot be set to `true`. -- `plugins` (list): A list of inlined [plugin configuration objects](#plugin-configuration-objects). If this key is populated with inlined plugin objects, and `disableLoadPluginsFromPath` is true, the final set of plugins for a network must consist of all the plugin objects in this list, merged with all the plugins loaded from the sibling folder with the same name as the network. +- `loadOnlyInlinedPlugins` (boolean): Either `true` or `false`. If `false` (default), indicates [plugin configuration objects](#plugin-configuration-objects) should be loaded from a sibling directory with the same name as the network `name` field. These sibling directories should exist at the same path as the network configuration itself. Any valid plugin configuration objects within a named sibling directory will be appended to the final list of `plugins` for that network name. If set to `true`, plugin configuration objects in sibling directories will be ignored. If `plugins` is not present in the network configuration, `loadOnlyInlinedPlugins` cannot be set to `true`. +- `plugins` (list): A list of inlined [plugin configuration objects](#plugin-configuration-objects). If this key is populated with inlined plugin objects, and `loadOnlyInlinedPlugins` is true, the final set of plugins for a network must consist of all the plugin objects in this list, merged with all the plugins loaded from the sibling folder with the same name as the network. #### Plugin configuration objects: Runtimes may aggregate plugin configuration objects from multiple sources, and must unambiguously associate each loaded plugin configuration object with a single, valid network configuration. All aggregated plugin configuration objects must be parsed, and each plugin with a parsable configuration object must be invoked. @@ -155,7 +155,7 @@ Network configuration with no inlined plugin confs, and two loaded plugin confs: "cniVersion": "1.1.0", "cniVersions": ["0.3.1", "0.4.0", "1.0.0", "1.1.0"], "name": "dbnet", - "disableLoadPluginsFromPath": false, + "loadOnlyInlinedPlugins": false, } ``` @@ -202,7 +202,7 @@ Network configuration with one inlined plugin conf, and one loaded plugin conf: "cniVersion": "1.1.0", "cniVersions": ["0.3.1", "0.4.0", "1.0.0", "1.1.0"], "name": "dbnet", - "disableLoadPluginsFromPath": false, + "loadOnlyInlinedPlugins": false, plugins: [ { "type": "bridge", @@ -247,7 +247,7 @@ Network configuration with one inlined plugin conf, and no loaded plugin conf: "cniVersion": "1.1.0", "cniVersions": ["0.3.1", "0.4.0", "1.0.0", "1.1.0"], "name": "dbnet", - "disableLoadPluginsFromPath": true, + "loadOnlyInlinedPlugins": true, "plugins": [ { "type": "bridge", diff --git a/libcni/api.go b/libcni/api.go index 869b81cd..9ae02e1f 100644 --- a/libcni/api.go +++ b/libcni/api.go @@ -80,7 +80,7 @@ type NetworkConfigList struct { Name string CNIVersion string DisableCheck bool - DisableLoadPluginsFromPath bool + LoadOnlyInlinedPlugins bool Plugins []*PluginConfig Bytes []byte } diff --git a/libcni/conf.go b/libcni/conf.go index e7ca2d62..8aa9831e 100644 --- a/libcni/conf.go +++ b/libcni/conf.go @@ -174,18 +174,18 @@ func NetworkConfFromBytes(confBytes []byte) (*NetworkConfigList, error) { } } - disableLoadPluginsFromPath := false - if rawLoadCheck, ok := rawList["disableLoadPluginsFromPath"]; ok { - disableLoadPluginsFromPath, ok = rawLoadCheck.(bool) + loadOnlyInlinedPlugins := false + if rawLoadCheck, ok := rawList["loadOnlyInlinedPlugins"]; ok { + loadOnlyInlinedPlugins, ok = rawLoadCheck.(bool) if !ok { - return nil, fmt.Errorf("error parsing configuration list: invalid disableLoadPluginsFromPath type %T", rawLoadCheck) + return nil, fmt.Errorf("error parsing configuration list: invalid loadOnlyInlinedPlugins type %T", rawLoadCheck) } } list := &NetworkConfigList{ Name: name, DisableCheck: disableCheck, - DisableLoadPluginsFromPath: disableLoadPluginsFromPath, + LoadOnlyInlinedPlugins: loadOnlyInlinedPlugins, CNIVersion: cniVersion, Bytes: confBytes, } @@ -193,16 +193,16 @@ func NetworkConfFromBytes(confBytes []byte) (*NetworkConfigList, error) { var plugins []interface{} plug, ok := rawList["plugins"] // We can have a `plugins` list key in the main conf, - // We can also have `disableLoadPluginsFromPath == true` + // We can also have `loadOnlyInlinedPlugins == true` // - // If `plugins` is there, then `disableLoadPluginsFromPath` can be true + // If `plugins` is there, then `loadOnlyInlinedPlugins` can be true // - // If plugins is NOT there, then `disableLoadPluginsFromPath` cannot be true + // If plugins is NOT there, then `loadOnlyInlinedPlugins` cannot be true // // We have to have at least some plugins. - if !ok && disableLoadPluginsFromPath { - return nil, fmt.Errorf("error parsing configuration list: `disableLoadPluginsFromPath` is true, and no 'plugins' key") - } else if !ok && !disableLoadPluginsFromPath { + if !ok && loadOnlyInlinedPlugins { + return nil, fmt.Errorf("error parsing configuration list: `loadOnlyInlinedPlugins` is true, and no 'plugins' key") + } else if !ok && !loadOnlyInlinedPlugins { return list, nil } @@ -239,7 +239,7 @@ func NetworkConfFromFile(filename string) (*NetworkConfigList, error) { return nil, err } - if !conf.DisableLoadPluginsFromPath { + if !conf.LoadOnlyInlinedPlugins { plugins, err := NetworkPluginConfsFromFiles(filepath.Dir(filename), conf.Name) if err != nil { return nil, err diff --git a/libcni/conf_test.go b/libcni/conf_test.go index f2f7b3a9..a6dde84c 100644 --- a/libcni/conf_test.go +++ b/libcni/conf_test.go @@ -390,12 +390,12 @@ var _ = Describe("Loading configuration from disk", func() { }) }) - Context("for disableLoadPluginsFromPath", func() { + Context("for loadOnlyInlinedPlugins", func() { It("the value will be parsed", func() { configList = []byte(`{ "name": "some-network", "cniVersion": "0.4.0", - "disableLoadPluginsFromPath": true, + "loadOnlyInlinedPlugins": true, "plugins": [ { "type": "host-local", @@ -416,7 +416,7 @@ var _ = Describe("Loading configuration from disk", func() { netConfigList, err := libcni.LoadNetworkConf(configDir, "some-network") Expect(err).NotTo(HaveOccurred()) - Expect(netConfigList.DisableLoadPluginsFromPath).To(BeTrue()) + Expect(netConfigList.LoadOnlyInlinedPlugins).To(BeTrue()) }) It("the value will be false if not in config", func() { @@ -434,7 +434,7 @@ var _ = Describe("Loading configuration from disk", func() { netConfigList, err := libcni.LoadNetworkConf(configDir, "some-network") Expect(err).NotTo(HaveOccurred()) - Expect(netConfigList.DisableLoadPluginsFromPath).To(BeFalse()) + Expect(netConfigList.LoadOnlyInlinedPlugins).To(BeFalse()) }) It("will return an error on an unrecognized value", func() { @@ -442,7 +442,7 @@ var _ = Describe("Loading configuration from disk", func() { configList = []byte(fmt.Sprintf(`{ "name": "some-network", "cniVersion": "0.4.0", - "disableLoadPluginsFromPath": "%s", + "loadOnlyInlinedPlugins": "%s", "plugins": [ { "type": "host-local", @@ -453,26 +453,26 @@ var _ = Describe("Loading configuration from disk", func() { Expect(os.WriteFile(filepath.Join(configDir, "50-whatever.conflist"), configList, 0o600)).To(Succeed()) _, err := libcni.LoadNetworkConf(configDir, "some-network") - Expect(err).To(MatchError("error parsing configuration list: invalid disableLoadPluginsFromPath type string")) + Expect(err).To(MatchError("error parsing configuration list: invalid loadOnlyInlinedPlugins type string")) }) - It("will return an error if `plugins` is missing and `disableLoadPluginsFromPath` is `true`", func() { + It("will return an error if `plugins` is missing and `loadOnlyInlinedPlugins` is `true`", func() { configList = []byte(`{ "name": "some-network", "cniVersion": "0.4.0", - "disableLoadPluginsFromPath": true + "loadOnlyInlinedPlugins": true }`) Expect(os.WriteFile(filepath.Join(configDir, "50-whatever.conflist"), configList, 0o600)).To(Succeed()) _, err := libcni.LoadNetworkConf(configDir, "some-network") - Expect(err).To(MatchError("error parsing configuration list: `disableLoadPluginsFromPath` is true, and no 'plugins' key")) + Expect(err).To(MatchError("error parsing configuration list: `loadOnlyInlinedPlugins` is true, and no 'plugins' key")) }) - It("will return no error if `plugins` is missing and `disableLoadPluginsFromPath` is false", func() { + It("will return no error if `plugins` is missing and `loadOnlyInlinedPlugins` is false", func() { configList = []byte(`{ "name": "some-network", "cniVersion": "0.4.0", - "disableLoadPluginsFromPath": false + "loadOnlyInlinedPlugins": false }`) Expect(os.WriteFile(filepath.Join(configDir, "50-whatever.conflist"), configList, 0o600)).To(Succeed()) @@ -487,11 +487,11 @@ var _ = Describe("Loading configuration from disk", func() { netConfigList, err := libcni.LoadNetworkConf(configDir, "some-network") Expect(err).NotTo(HaveOccurred()) - Expect(netConfigList.DisableLoadPluginsFromPath).To(BeFalse()) + Expect(netConfigList.LoadOnlyInlinedPlugins).To(BeFalse()) Expect(netConfigList.Plugins).To(HaveLen(1)) }) - It("will return error if `disableLoadPluginsFromPath` is implicitly false + no conf plugin is defined, but no plugins subfolder with network name exists", func() { + It("will return error if `loadOnlyInlinedPlugins` is implicitly false + no conf plugin is defined, but no plugins subfolder with network name exists", func() { configList = []byte(`{ "name": "some-network", "cniVersion": "0.4.0" @@ -502,7 +502,7 @@ var _ = Describe("Loading configuration from disk", func() { Expect(err).To(MatchError("no plugin configs found")) }) - It("will return NO error if `disableLoadPluginsFromPath` is implicitly false + at least 1 conf plugin is defined, but no plugins subfolder with network name exists", func() { + It("will return NO error if `loadOnlyInlinedPlugins` is implicitly false + at least 1 conf plugin is defined, but no plugins subfolder with network name exists", func() { configList = []byte(`{ "name": "some-network", "cniVersion": "0.4.0", @@ -519,7 +519,7 @@ var _ = Describe("Loading configuration from disk", func() { Expect(err).NotTo(HaveOccurred()) }) - It("will return NO error if `disableLoadPluginsFromPath` is implicitly false + at least 1 conf plugin is defined and network name subfolder exists, but is empty/unreadable", func() { + It("will return NO error if `loadOnlyInlinedPlugins` is implicitly false + at least 1 conf plugin is defined and network name subfolder exists, but is empty/unreadable", func() { configList = []byte(`{ "name": "some-network", "cniVersion": "0.4.0", @@ -539,7 +539,7 @@ var _ = Describe("Loading configuration from disk", func() { Expect(err).NotTo(HaveOccurred()) }) - It("will merge loaded and inlined plugin lists if both `plugins` is set and `disableLoadPluginsFromPath` is false", func() { + It("will merge loaded and inlined plugin lists if both `plugins` is set and `loadOnlyInlinedPlugins` is false", func() { configList = []byte(`{ "name": "some-network", "cniVersion": "0.4.0", @@ -564,15 +564,15 @@ var _ = Describe("Loading configuration from disk", func() { netConfigList, err := libcni.LoadNetworkConf(configDir, "some-network") Expect(err).NotTo(HaveOccurred()) - Expect(netConfigList.DisableLoadPluginsFromPath).To(BeFalse()) + Expect(netConfigList.LoadOnlyInlinedPlugins).To(BeFalse()) Expect(netConfigList.Plugins).To(HaveLen(2)) }) - It("will ignore loaded plugins if `plugins` is set and `disableLoadPluginsFromPath` is true", func() { + It("will ignore loaded plugins if `plugins` is set and `loadOnlyInlinedPlugins` is true", func() { configList = []byte(`{ "name": "some-network", "cniVersion": "0.4.0", - "disableLoadPluginsFromPath": true, + "loadOnlyInlinedPlugins": true, "plugins": [ { "type": "host-local", @@ -593,7 +593,7 @@ var _ = Describe("Loading configuration from disk", func() { netConfigList, err := libcni.LoadNetworkConf(configDir, "some-network") Expect(err).NotTo(HaveOccurred()) - Expect(netConfigList.DisableLoadPluginsFromPath).To(BeTrue()) + Expect(netConfigList.LoadOnlyInlinedPlugins).To(BeTrue()) Expect(netConfigList.Plugins).To(HaveLen(1)) Expect(netConfigList.Plugins[0].Network.Type).To(Equal("host-local")) })