Skip to content

Commit

Permalink
Merge pull request #967 from squeed/setup-1.1
Browse files Browse the repository at this point in the history
Prepare for spec version v1.1
  • Loading branch information
squeed committed Jul 13, 2023
2 parents 6225376 + a899051 commit ca96f4c
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 58 deletions.
34 changes: 17 additions & 17 deletions SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
- [`CHECK`: Check container's networking is as expected](#check-check-containers-networking-is-as-expected)
- [`VERSION`: probe plugin version support](#version-probe-plugin-version-support)
- [Section 3: Execution of Network Configurations](#section-3-execution-of-network-configurations)
- [Lifecycle & Ordering](#lifecycle--ordering)
- [Lifecycle \& Ordering](#lifecycle--ordering)
- [Attachment Parameters](#attachment-parameters)
- [Adding an attachment](#adding-an-attachment)
- [Deleting an attachment](#deleting-an-attachment)
Expand All @@ -40,7 +40,7 @@

## Version

This is CNI **spec** version **1.0.0**.
This is CNI **spec** version **1.1.0-dev**.

Note that this is **independent from the version of the CNI library and plugins** in this repository (e.g. the versions of [releases](https://github.com/containernetworking/cni/releases)).

Expand Down Expand Up @@ -102,7 +102,7 @@ require this.

A network configuration consists of a JSON object with the following keys:

- `cniVersion` (string): [Semantic Version 2.0](https://semver.org) of CNI specification to which this configuration list and all the individual configurations conform. Currently "1.0.0"
- `cniVersion` (string): [Semantic Version 2.0](https://semver.org) of CNI specification to which this configuration list and all the individual configurations conform. Currently "1.1.0"
- `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 (-).
- `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.
- `plugins` (list): A list of CNI plugins and their configuration, which is a list of plugin configuration objects.
Expand Down Expand Up @@ -142,7 +142,7 @@ Plugins may define additional fields that they accept and may generate an error
#### Example configuration
```jsonc
{
"cniVersion": "1.0.0",
"cniVersion": "1.1.0",
"name": "dbnet",
"plugins": [
{
Expand Down Expand Up @@ -477,7 +477,7 @@ Plugins provided a `prevResult` key as part of their request configuration must

Plugins must output a JSON object with the following keys upon a successful `ADD` operation:

- `cniVersion`: The same version supplied on input - the string "1.0.0"
- `cniVersion`: The same version supplied on input - the string "1.1.0"
- `interfaces`: An array of all interfaces created by the attachment, including any host-level interfaces:
- `name`: The name of the interface.
- `mac`: The hardware address of the interface (if applicable).
Expand Down Expand Up @@ -514,7 +514,7 @@ Example:

```json
{
"cniVersion": "1.0.0",
"cniVersion": "1.1.0",
"code": 7,
"msg": "Invalid Configuration",
"details": "Network 192.168.0.0/31 too small to allocate from."
Expand Down Expand Up @@ -547,8 +547,8 @@ Plugins must output a JSON object with the following keys upon a `VERSION` opera
Example:
```json
{
"cniVersion": "1.0.0",
"supportedVersions": [ "0.1.0", "0.2.0", "0.3.0", "0.3.1", "0.4.0", "1.0.0" ]
"cniVersion": "1.1.0",
"supportedVersions": [ "0.1.0", "0.2.0", "0.3.0", "0.3.1", "0.4.0", "1.0.0", "1.1.0" ]
}
```

Expand All @@ -566,7 +566,7 @@ The container runtime would perform the following steps for the `add` operation.

```json
{
"cniVersion": "1.0.0",
"cniVersion": "1.1.0",
"name": "dbnet",
"type": "bridge",
"bridge": "cni0",
Expand Down Expand Up @@ -646,7 +646,7 @@ The bridge plugin returns the following result, configuring the interface accord

```json
{
"cniVersion": "1.0.0",
"cniVersion": "1.1.0",
"name": "dbnet",
"type": "tuning",
"sysctl": {
Expand Down Expand Up @@ -731,7 +731,7 @@ The plugin returns the following result. Note that the **mac** has changed.

```json
{
"cniVersion": "1.0.0",
"cniVersion": "1.1.0",
"name": "dbnet",
"type": "portmap",
"runtimeConfig": {
Expand Down Expand Up @@ -785,7 +785,7 @@ Given the previous _Add_, the container runtime would perform the following step

```json
{
"cniVersion": "1.0.0",
"cniVersion": "1.1.0",
"name": "dbnet",
"type": "bridge",
"bridge": "cni0",
Expand Down Expand Up @@ -841,7 +841,7 @@ Assuming the `bridge` plugin is satisfied, it produces no output on standard out

```json
{
"cniVersion": "1.0.0",
"cniVersion": "1.1.0",
"name": "dbnet",
"type": "tuning",
"sysctl": {
Expand Down Expand Up @@ -891,7 +891,7 @@ Likewise, the `tuning` plugin exits indicating success.

```json
{
"cniVersion": "1.0.0",
"cniVersion": "1.1.0",
"name": "dbnet",
"type": "portmap",
"runtimeConfig": {
Expand Down Expand Up @@ -944,7 +944,7 @@ Note that plugins are executed in reverse order from the _Add_ and _Check_ actio

```json
{
"cniVersion": "1.0.0",
"cniVersion": "1.1.0",
"name": "dbnet",
"type": "portmap",
"runtimeConfig": {
Expand Down Expand Up @@ -992,7 +992,7 @@ Note that plugins are executed in reverse order from the _Add_ and _Check_ actio

```json
{
"cniVersion": "1.0.0",
"cniVersion": "1.1.0",
"name": "dbnet",
"type": "tuning",
"sysctl": {
Expand Down Expand Up @@ -1040,7 +1040,7 @@ Note that plugins are executed in reverse order from the _Add_ and _Check_ actio

```json
{
"cniVersion": "1.0.0",
"cniVersion": "1.1.0",
"name": "dbnet",
"type": "bridge",
"bridge": "cni0",
Expand Down
31 changes: 16 additions & 15 deletions libcni/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/containernetworking/cni/pkg/skel"
"github.com/containernetworking/cni/pkg/types"
current "github.com/containernetworking/cni/pkg/types/100"
"github.com/containernetworking/cni/pkg/version"
noop_debug "github.com/containernetworking/cni/plugins/test/noop/debug"
)

Expand Down Expand Up @@ -179,7 +180,7 @@ var _ = Describe("Invoking plugins", func() {

debug = &noop_debug.Debug{
ReportResult: `{
"cniVersion": "1.0.0",
"cniVersion": "` + version.Current() + `",
"ips": [{"address": "10.1.2.3/24"}],
"dns": {}
}`,
Expand All @@ -195,7 +196,7 @@ var _ = Describe("Invoking plugins", func() {
"somethingElse": true,
"noCapability": false
}
}`, current.ImplementedSpecVersion))
}`, version.Current()))
netConfig, err = libcni.ConfFromBytes(pluginConfig)
Expect(err).NotTo(HaveOccurred())

Expand Down Expand Up @@ -301,7 +302,7 @@ var _ = Describe("Invoking plugins", func() {

debug = &noop_debug.Debug{
ReportResult: `{
"cniVersion": "1.0.0",
"cniVersion": "` + version.Current() + `",
"ips": [{"address": "10.1.2.3/24"}],
"dns": {}
}`,
Expand All @@ -319,7 +320,7 @@ var _ = Describe("Invoking plugins", func() {
"some-key": "some-value",
"cniVersion": "%s",
"capabilities": { "portMappings": true }
}`, current.ImplementedSpecVersion)
}`, version.Current())
cniConfig = libcni.NewCNIConfigWithCacheDir([]string{cniBinPath}, cacheDirPath, nil)
netConfig, err = libcni.ConfFromBytes([]byte(pluginConfig))
Expect(err).NotTo(HaveOccurred())
Expand Down Expand Up @@ -476,7 +477,7 @@ var _ = Describe("Invoking plugins", func() {
err := os.MkdirAll(filepath.Dir(cacheFile), 0o700)
Expect(err).NotTo(HaveOccurred())
cachedJson := `{
"cniVersion": "1.0.0",
"cniVersion": "` + version.Current() + `",
"ips": [{"address": "10.1.2.3/24"}],
"dns": {}
}`
Expand Down Expand Up @@ -561,7 +562,7 @@ var _ = Describe("Invoking plugins", func() {
Context("containing only a cached result", func() {
It("only passes a prevResult to the plugin", func() {
err := os.WriteFile(cacheFile, []byte(`{
"cniVersion": "1.0.0",
"cniVersion": "`+version.Current()+`",
"ips": [{"address": "10.1.2.3/24"}],
"dns": {}
}`), 0o600)
Expand Down Expand Up @@ -666,7 +667,7 @@ var _ = Describe("Invoking plugins", func() {
err := os.MkdirAll(filepath.Dir(cacheFile), 0o700)
Expect(err).NotTo(HaveOccurred())
cachedJson := `{
"cniVersion": "1.0.0",
"cniVersion": "` + version.Current() + `",
"ips": [{"address": "10.1.2.3/24"}],
"dns": {}
}`
Expand Down Expand Up @@ -874,7 +875,7 @@ var _ = Describe("Invoking plugins", func() {

Expect(versionInfo).NotTo(BeNil())
Expect(versionInfo.SupportedVersions()).To(Equal([]string{
"0.-42.0", "0.1.0", "0.2.0", "0.3.0", "0.3.1", "0.4.0", "1.0.0",
"0.-42.0", "0.1.0", "0.2.0", "0.3.0", "0.3.1", "0.4.0", "1.0.0", "1.1.0",
}))
})

Expand Down Expand Up @@ -962,8 +963,8 @@ var _ = Describe("Invoking plugins", func() {
"otherCapability": capabilityArgs["otherCapability"],
}

ipResult = fmt.Sprintf(`{"cniVersion": "%s", "dns":{},"ips":[{"address": "10.1.2.3/24"}]}`, current.ImplementedSpecVersion)
netConfigList, plugins = makePluginList(current.ImplementedSpecVersion, ipResult, rcMap)
ipResult = fmt.Sprintf(`{"cniVersion": "%s", "dns":{},"ips":[{"address": "10.1.2.3/24"}]}`, version.Current())
netConfigList, plugins = makePluginList(version.Current(), ipResult, rcMap)

ctx = context.TODO()
})
Expand Down Expand Up @@ -1533,7 +1534,7 @@ var _ = Describe("Invoking plugins", func() {
"some-key": "some-value",
"cniVersion": "%s",
"capabilities": { "portMappings": true }
}`, current.ImplementedSpecVersion)
}`, version.Current())

cniBinPath = filepath.Dir(pluginPaths["sleep"])
cniConfig = libcni.NewCNIConfig([]string{cniBinPath}, nil)
Expand All @@ -1560,7 +1561,7 @@ var _ = Describe("Invoking plugins", func() {
"plugins": [
%s
]
}`, current.ImplementedSpecVersion, pluginConfig))
}`, version.Current(), pluginConfig))

netConfigList, err = libcni.ConfListFromBytes(configList)
Expect(err).NotTo(HaveOccurred())
Expand Down Expand Up @@ -1703,7 +1704,7 @@ var _ = Describe("Invoking plugins", func() {
ReportResult: fmt.Sprintf(`{
"cniVersion": "%s",
"ips": [{"version": "4", "address": "%s"}]
}`, current.ImplementedSpecVersion, firstIP),
}`, version.Current(), firstIP),
}
Expect(debug.WriteDebug(debugFilePath)).To(Succeed())

Expand All @@ -1712,7 +1713,7 @@ var _ = Describe("Invoking plugins", func() {
"type": "noop",
"name": "%s",
"cniVersion": "%s"
}`, netName, current.ImplementedSpecVersion)
}`, netName, version.Current())
cniConfig = libcni.NewCNIConfigWithCacheDir([]string{cniBinPath}, cacheDirPath, nil)
netConfig, err = libcni.ConfFromBytes([]byte(pluginConfig))
Expect(err).NotTo(HaveOccurred())
Expand All @@ -1736,7 +1737,7 @@ var _ = Describe("Invoking plugins", func() {
debug.ReportResult = fmt.Sprintf(`{
"cniVersion": "%s",
"ips": [{"version": "4", "address": "%s"}]
}`, current.ImplementedSpecVersion, secondIP)
}`, version.Current(), secondIP)
Expect(debug.WriteDebug(debugFilePath)).To(Succeed())
runtimeConfig.IfName = secondIfname
_, err = cniConfig.AddNetwork(ctx, netConfig, runtimeConfig)
Expand Down
3 changes: 2 additions & 1 deletion pkg/invoke/delegate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"github.com/containernetworking/cni/pkg/invoke"
current "github.com/containernetworking/cni/pkg/types/100"
"github.com/containernetworking/cni/pkg/version"
"github.com/containernetworking/cni/plugins/test/noop/debug"
)

Expand All @@ -42,7 +43,7 @@ var _ = Describe("Delegate", func() {
BeforeEach(func() {
netConf, _ = json.Marshal(map[string]string{
"name": "delegate-test",
"cniVersion": current.ImplementedSpecVersion,
"cniVersion": version.Current(),
})

expectedResult = &current.Result{
Expand Down
5 changes: 2 additions & 3 deletions pkg/skel/skel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
. "github.com/onsi/gomega"

"github.com/containernetworking/cni/pkg/types"
current "github.com/containernetworking/cni/pkg/types/100"
"github.com/containernetworking/cni/pkg/version"
)

Expand Down Expand Up @@ -430,7 +429,7 @@ var _ = Describe("dispatching to the correct callback", func() {
Expect(stdout).To(MatchJSON(fmt.Sprintf(`{
"cniVersion": "%s",
"supportedVersions": ["9.8.7", "10.0.0"]
}`, current.ImplementedSpecVersion)))
}`, version.Current())))
})

It("does not call cmdAdd or cmdDel", func() {
Expand Down Expand Up @@ -461,7 +460,7 @@ var _ = Describe("dispatching to the correct callback", func() {
Expect(stdout).To(MatchJSON(fmt.Sprintf(`{
"cniVersion": "%s",
"supportedVersions": ["9.8.7", "10.0.0"]
}`, current.ImplementedSpecVersion)))
}`, version.Current())))
})
})

Expand Down
25 changes: 22 additions & 3 deletions pkg/types/100/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ import (
convert "github.com/containernetworking/cni/pkg/types/internal"
)

const ImplementedSpecVersion string = "1.0.0"
// The types did not change between v1.0 and v1.1
const ImplementedSpecVersion string = "1.1.0"

var supportedVersions = []string{ImplementedSpecVersion}
var supportedVersions = []string{"1.0.0", "1.1.0"}

// Register converters for all versions less than the implemented spec version
func init() {
Expand All @@ -38,10 +39,14 @@ func init() {
convert.RegisterConverter("0.3.0", supportedVersions, convertFrom04x)
convert.RegisterConverter("0.3.1", supportedVersions, convertFrom04x)
convert.RegisterConverter("0.4.0", supportedVersions, convertFrom04x)
convert.RegisterConverter("1.0.0", []string{"1.1.0"}, convertFrom100)

// Down-converters
convert.RegisterConverter("1.0.0", []string{"0.3.0", "0.3.1", "0.4.0"}, convertTo04x)
convert.RegisterConverter("1.0.0", []string{"0.1.0", "0.2.0"}, convertTo02x)
convert.RegisterConverter("1.1.0", []string{"0.3.0", "0.3.1", "0.4.0"}, convertTo04x)
convert.RegisterConverter("1.1.0", []string{"0.1.0", "0.2.0"}, convertTo02x)
convert.RegisterConverter("1.1.0", []string{"1.0.0"}, convertFrom100)

// Creator
convert.RegisterCreator(supportedVersions, NewResult)
Expand Down Expand Up @@ -90,12 +95,26 @@ type Result struct {
DNS types.DNS `json:"dns,omitempty"`
}

// convertFrom100 does nothing except set the version; the types are the same
func convertFrom100(from types.Result, toVersion string) (types.Result, error) {
fromResult := from.(*Result)

result := &Result{
CNIVersion: toVersion,
Interfaces: fromResult.Interfaces,
IPs: fromResult.IPs,
Routes: fromResult.Routes,
DNS: fromResult.DNS,
}
return result, nil
}

func convertFrom02x(from types.Result, toVersion string) (types.Result, error) {
result040, err := convert.Convert(from, "0.4.0")
if err != nil {
return nil, err
}
result100, err := convertFrom04x(result040, ImplementedSpecVersion)
result100, err := convertFrom04x(result040, toVersion)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit ca96f4c

Please sign in to comment.