bump CNI to spec v1.0.0
Signed-off-by: zounengren <zouyee1989@gmail.com>
This commit is contained in:
		
							
								
								
									
										8
									
								
								vendor/github.com/containerd/go-cni/README.md
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										8
									
								
								vendor/github.com/containerd/go-cni/README.md
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -2,7 +2,7 @@ | ||||
|  | ||||
| [](https://pkg.go.dev/github.com/containerd/go-cni) | ||||
| [](https://github.com/containerd/go-cni/actions?query=workflow%3ACI) | ||||
| [](https://codecov.io/gh/containerd/go-cni) | ||||
| [](https://codecov.io/gh/containerd/go-cni) | ||||
| [](https://goreportcard.com/report/github.com/containerd/go-cni) | ||||
|  | ||||
| A generic CNI library to provide APIs for CNI plugin interactions. The library provides APIs to: | ||||
| @@ -88,8 +88,8 @@ func main() { | ||||
| The go-cni is a containerd sub-project, licensed under the [Apache 2.0 license](./LICENSE). | ||||
| As a containerd sub-project, you will find the: | ||||
|  | ||||
|  * [Project governance](https://github.com/containerd/project/blob/master/GOVERNANCE.md), | ||||
|  * [Maintainers](https://github.com/containerd/project/blob/master/MAINTAINERS), | ||||
|  * and [Contributing guidelines](https://github.com/containerd/project/blob/master/CONTRIBUTING.md) | ||||
|  * [Project governance](https://github.com/containerd/project/blob/main/GOVERNANCE.md), | ||||
|  * [Maintainers](https://github.com/containerd/project/blob/main/MAINTAINERS), | ||||
|  * and [Contributing guidelines](https://github.com/containerd/project/blob/main/CONTRIBUTING.md) | ||||
|  | ||||
| information in our [`containerd/project`](https://github.com/containerd/project) repository. | ||||
|   | ||||
							
								
								
									
										9
									
								
								vendor/github.com/containerd/go-cni/cni.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										9
									
								
								vendor/github.com/containerd/go-cni/cni.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -24,8 +24,7 @@ import ( | ||||
|  | ||||
| 	cnilibrary "github.com/containernetworking/cni/libcni" | ||||
| 	"github.com/containernetworking/cni/pkg/types" | ||||
| 	"github.com/containernetworking/cni/pkg/types/current" | ||||
| 	"github.com/pkg/errors" | ||||
| 	types100 "github.com/containernetworking/cni/pkg/types/100" | ||||
| ) | ||||
|  | ||||
| type CNI interface { | ||||
| @@ -115,7 +114,7 @@ func (c *libcni) Load(opts ...Opt) error { | ||||
|  | ||||
| 	for _, o := range opts { | ||||
| 		if err = o(c); err != nil { | ||||
| 			return errors.Wrapf(ErrLoad, fmt.Sprintf("cni config load failed: %v", err)) | ||||
| 			return fmt.Errorf("cni config load failed: %v: %w", err, ErrLoad) | ||||
| 		} | ||||
| 	} | ||||
| 	return nil | ||||
| @@ -155,8 +154,8 @@ func (c *libcni) Setup(ctx context.Context, id string, path string, opts ...Name | ||||
| 	return c.createResult(result) | ||||
| } | ||||
|  | ||||
| func (c *libcni) attachNetworks(ctx context.Context, ns *Namespace) ([]*current.Result, error) { | ||||
| 	var results []*current.Result | ||||
| func (c *libcni) attachNetworks(ctx context.Context, ns *Namespace) ([]*types100.Result, error) { | ||||
| 	var results []*types100.Result | ||||
| 	for _, network := range c.Networks() { | ||||
| 		r, err := network.Attach(ctx, ns) | ||||
| 		if err != nil { | ||||
|   | ||||
							
								
								
									
										6
									
								
								vendor/github.com/containerd/go-cni/deprecated.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								vendor/github.com/containerd/go-cni/deprecated.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -16,7 +16,7 @@ | ||||
|  | ||||
| package cni | ||||
|  | ||||
| import "github.com/containernetworking/cni/pkg/types/current" | ||||
| import types100 "github.com/containernetworking/cni/pkg/types/100" | ||||
|  | ||||
| // Deprecated: use cni.Opt instead | ||||
| type CNIOpt = Opt //nolint: golint // type name will be used as cni.CNIOpt by other packages, and that stutters | ||||
| @@ -24,11 +24,11 @@ type CNIOpt = Opt //nolint: golint // type name will be used as cni.CNIOpt by ot | ||||
| // Deprecated: use cni.Result instead | ||||
| type CNIResult = Result //nolint: golint // type name will be used as cni.CNIResult by other packages, and that stutters | ||||
|  | ||||
| // GetCNIResultFromResults creates a Result from the given slice of current.Result, | ||||
| // GetCNIResultFromResults creates a Result from the given slice of types100.Result, | ||||
| // adding structured data containing the interface configuration for each of the | ||||
| // interfaces created in the namespace. It returns an error if validation of | ||||
| // results fails, or if a network could not be found. | ||||
| // Deprecated: do not use | ||||
| func (c *libcni) GetCNIResultFromResults(results []*current.Result) (*Result, error) { | ||||
| func (c *libcni) GetCNIResultFromResults(results []*types100.Result) (*Result, error) { | ||||
| 	return c.createResult(results) | ||||
| } | ||||
|   | ||||
							
								
								
									
										2
									
								
								vendor/github.com/containerd/go-cni/errors.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								vendor/github.com/containerd/go-cni/errors.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -17,7 +17,7 @@ | ||||
| package cni | ||||
|  | ||||
| import ( | ||||
| 	"github.com/pkg/errors" | ||||
| 	"errors" | ||||
| ) | ||||
|  | ||||
| var ( | ||||
|   | ||||
							
								
								
									
										5
									
								
								vendor/github.com/containerd/go-cni/go.mod
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										5
									
								
								vendor/github.com/containerd/go-cni/go.mod
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -1,11 +1,8 @@ | ||||
| module github.com/containerd/go-cni | ||||
|  | ||||
| require ( | ||||
| 	github.com/containernetworking/cni v0.8.0 | ||||
| 	github.com/containernetworking/cni v1.0.1 | ||||
| 	github.com/davecgh/go-spew v1.1.1 // indirect | ||||
| 	github.com/onsi/ginkgo v1.10.3 // indirect | ||||
| 	github.com/onsi/gomega v1.7.1 // indirect | ||||
| 	github.com/pkg/errors v0.9.1 | ||||
| 	github.com/stretchr/testify v1.6.1 | ||||
| ) | ||||
|  | ||||
|   | ||||
							
								
								
									
										63
									
								
								vendor/github.com/containerd/go-cni/go.sum
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										63
									
								
								vendor/github.com/containerd/go-cni/go.sum
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -1,42 +1,73 @@ | ||||
| github.com/containernetworking/cni v0.8.0 h1:BT9lpgGoH4jw3lFC7Odz2prU5ruiYKcgAjMCbgybcKI= | ||||
| github.com/containernetworking/cni v0.8.0/go.mod h1:LGwApLUm2FpoOfxTDEeq8T9ipbpZ61X79hmU3w8FmsY= | ||||
| github.com/containernetworking/cni v1.0.1 h1:9OIL/sZmMYDBe+G8svzILAlulUpaDTUjeAbtH/JNLBo= | ||||
| github.com/containernetworking/cni v1.0.1/go.mod h1:AKuhXbN5EzmD4yTNtfSsX3tPcmtrBI6QcRV0NiNt15Y= | ||||
| github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||||
| github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||||
| github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||||
| github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= | ||||
| github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= | ||||
| github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= | ||||
| github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= | ||||
| github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= | ||||
| github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= | ||||
| github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= | ||||
| github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= | ||||
| github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= | ||||
| github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= | ||||
| github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= | ||||
| github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= | ||||
| github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0= | ||||
| github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= | ||||
| github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= | ||||
| github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= | ||||
| github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= | ||||
| github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= | ||||
| github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= | ||||
| github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78= | ||||
| github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= | ||||
| github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= | ||||
| github.com/onsi/ginkgo v1.10.3 h1:OoxbjfXVZyod1fmWYhI7SEyaD8B00ynP3T+D5GiyHOY= | ||||
| github.com/onsi/ginkgo v1.10.3/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= | ||||
| github.com/onsi/gomega v1.7.1 h1:K0jcRCwNQM3vFGh1ppMtDh/+7ApJrjldlX8fA0jDTLQ= | ||||
| github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= | ||||
| github.com/onsi/ginkgo v1.13.0 h1:M76yO2HkZASFjXL0HSoZJ1AYEmQxNJmY41Jx1zNUq1Y= | ||||
| github.com/onsi/ginkgo v1.13.0/go.mod h1:+REjRxOmWfHCjfv9TTWB1jD1Frx4XydAD3zm1lskyM0= | ||||
| github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= | ||||
| github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= | ||||
| github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= | ||||
| github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE= | ||||
| github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= | ||||
| github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||||
| github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||||
| github.com/sclevine/agouti v3.0.0+incompatible/go.mod h1:b4WX9W9L1sfQKXeJf1mUTLZKJ48R1S7H23Ji7oFO5Bw= | ||||
| github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= | ||||
| github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||||
| github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= | ||||
| github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||||
| golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA= | ||||
| golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= | ||||
| golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= | ||||
| golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA= | ||||
| golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7 h1:AeiKBIuRw3UomYXSbLy0Mc2dDLfdtbT/IVn4keq83P0= | ||||
| golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= | ||||
| golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||||
| golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e h1:o3PsSEY8E4eXWkXrIP9YJALUkVZqzHJT5DOasTyn8Vs= | ||||
| golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||||
| golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= | ||||
| golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||||
| golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||
| golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||
| golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||
| golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||
| golang.org/x/sys v0.0.0-20200519105757-fe76b779f299 h1:DYfZAGf2WMFjMxbgTjaC+2HC7NkNAQs+6Q8b9WEB/F4= | ||||
| golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||
| golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | ||||
| golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= | ||||
| golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= | ||||
| golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= | ||||
| golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= | ||||
| golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | ||||
| google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= | ||||
| google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= | ||||
| google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= | ||||
| google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= | ||||
| google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= | ||||
| google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM= | ||||
| google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= | ||||
| gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||||
| gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||||
| gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= | ||||
| gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= | ||||
| gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= | ||||
| gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= | ||||
| gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I= | ||||
| gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= | ||||
| gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= | ||||
| gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= | ||||
| gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= | ||||
| gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= | ||||
|   | ||||
							
								
								
									
										4
									
								
								vendor/github.com/containerd/go-cni/helper.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								vendor/github.com/containerd/go-cni/helper.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -19,10 +19,10 @@ package cni | ||||
| import ( | ||||
| 	"fmt" | ||||
|  | ||||
| 	"github.com/containernetworking/cni/pkg/types/current" | ||||
| 	types100 "github.com/containernetworking/cni/pkg/types/100" | ||||
| ) | ||||
|  | ||||
| func validateInterfaceConfig(ipConf *current.IPConfig, ifs int) error { | ||||
| func validateInterfaceConfig(ipConf *types100.IPConfig, ifs int) error { | ||||
| 	if ipConf == nil { | ||||
| 		return fmt.Errorf("invalid IP configuration (nil)") | ||||
| 	} | ||||
|   | ||||
							
								
								
									
										6
									
								
								vendor/github.com/containerd/go-cni/namespace.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								vendor/github.com/containerd/go-cni/namespace.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -20,7 +20,7 @@ import ( | ||||
| 	"context" | ||||
|  | ||||
| 	cnilibrary "github.com/containernetworking/cni/libcni" | ||||
| 	"github.com/containernetworking/cni/pkg/types/current" | ||||
| 	types100 "github.com/containernetworking/cni/pkg/types/100" | ||||
| ) | ||||
|  | ||||
| type Network struct { | ||||
| @@ -29,12 +29,12 @@ type Network struct { | ||||
| 	ifName string | ||||
| } | ||||
|  | ||||
| func (n *Network) Attach(ctx context.Context, ns *Namespace) (*current.Result, error) { | ||||
| func (n *Network) Attach(ctx context.Context, ns *Namespace) (*types100.Result, error) { | ||||
| 	r, err := n.cni.AddNetworkList(ctx, n.config, ns.config(n.ifName)) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	return current.NewResultFromResult(r) | ||||
| 	return types100.NewResultFromResult(r) | ||||
| } | ||||
|  | ||||
| func (n *Network) Remove(ctx context.Context, ns *Namespace) error { | ||||
|   | ||||
							
								
								
									
										18
									
								
								vendor/github.com/containerd/go-cni/opts.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										18
									
								
								vendor/github.com/containerd/go-cni/opts.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -17,11 +17,11 @@ | ||||
| package cni | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"sort" | ||||
| 	"strings" | ||||
|  | ||||
| 	cnilibrary "github.com/containernetworking/cni/libcni" | ||||
| 	"github.com/pkg/errors" | ||||
| ) | ||||
|  | ||||
| // Opt sets options for a CNI instance | ||||
| @@ -204,9 +204,9 @@ func loadFromConfDir(c *libcni, max int) error { | ||||
| 	files, err := cnilibrary.ConfFiles(c.pluginConfDir, []string{".conf", ".conflist", ".json"}) | ||||
| 	switch { | ||||
| 	case err != nil: | ||||
| 		return errors.Wrapf(ErrRead, "failed to read config file: %v", err) | ||||
| 		return fmt.Errorf("failed to read config file: %v: %w", err, ErrRead) | ||||
| 	case len(files) == 0: | ||||
| 		return errors.Wrapf(ErrCNINotInitialized, "no network config found in %s", c.pluginConfDir) | ||||
| 		return fmt.Errorf("no network config found in %s: %w", c.pluginConfDir, ErrCNINotInitialized) | ||||
| 	} | ||||
|  | ||||
| 	// files contains the network config files associated with cni network. | ||||
| @@ -224,26 +224,26 @@ func loadFromConfDir(c *libcni, max int) error { | ||||
| 		if strings.HasSuffix(confFile, ".conflist") { | ||||
| 			confList, err = cnilibrary.ConfListFromFile(confFile) | ||||
| 			if err != nil { | ||||
| 				return errors.Wrapf(ErrInvalidConfig, "failed to load CNI config list file %s: %v", confFile, err) | ||||
| 				return fmt.Errorf("failed to load CNI config list file %s: %v: %w", confFile, err, ErrInvalidConfig) | ||||
| 			} | ||||
| 		} else { | ||||
| 			conf, err := cnilibrary.ConfFromFile(confFile) | ||||
| 			if err != nil { | ||||
| 				return errors.Wrapf(ErrInvalidConfig, "failed to load CNI config file %s: %v", confFile, err) | ||||
| 				return fmt.Errorf("failed to load CNI config file %s: %v: %w", confFile, err, ErrInvalidConfig) | ||||
| 			} | ||||
| 			// Ensure the config has a "type" so we know what plugin to run. | ||||
| 			// Also catches the case where somebody put a conflist into a conf file. | ||||
| 			if conf.Network.Type == "" { | ||||
| 				return errors.Wrapf(ErrInvalidConfig, "network type not found in %s", confFile) | ||||
| 				return fmt.Errorf("network type not found in %s: %w", confFile, ErrInvalidConfig) | ||||
| 			} | ||||
|  | ||||
| 			confList, err = cnilibrary.ConfListFromConf(conf) | ||||
| 			if err != nil { | ||||
| 				return errors.Wrapf(ErrInvalidConfig, "failed to convert CNI config file %s to CNI config list: %v", confFile, err) | ||||
| 				return fmt.Errorf("failed to convert CNI config file %s to CNI config list: %v: %w", confFile, err, ErrInvalidConfig) | ||||
| 			} | ||||
| 		} | ||||
| 		if len(confList.Plugins) == 0 { | ||||
| 			return errors.Wrapf(ErrInvalidConfig, "CNI config list in config file %s has no networks, skipping", confFile) | ||||
| 			return fmt.Errorf("CNI config list in config file %s has no networks, skipping: %w", confFile, ErrInvalidConfig) | ||||
|  | ||||
| 		} | ||||
| 		networks = append(networks, &Network{ | ||||
| @@ -257,7 +257,7 @@ func loadFromConfDir(c *libcni, max int) error { | ||||
| 		} | ||||
| 	} | ||||
| 	if len(networks) == 0 { | ||||
| 		return errors.Wrapf(ErrCNINotInitialized, "no valid networks found in %s", c.pluginDirs) | ||||
| 		return fmt.Errorf("no valid networks found in %s: %w", c.pluginDirs, ErrCNINotInitialized) | ||||
| 	} | ||||
| 	c.networks = append(c.networks, networks...) | ||||
| 	return nil | ||||
|   | ||||
							
								
								
									
										23
									
								
								vendor/github.com/containerd/go-cni/result.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										23
									
								
								vendor/github.com/containerd/go-cni/result.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -17,11 +17,11 @@ | ||||
| package cni | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"net" | ||||
|  | ||||
| 	"github.com/containernetworking/cni/pkg/types" | ||||
| 	"github.com/containernetworking/cni/pkg/types/current" | ||||
| 	"github.com/pkg/errors" | ||||
| 	types100 "github.com/containernetworking/cni/pkg/types/100" | ||||
| ) | ||||
|  | ||||
| type IPConfig struct { | ||||
| @@ -43,6 +43,12 @@ type Result struct { | ||||
| 	Interfaces map[string]*Config | ||||
| 	DNS        []types.DNS | ||||
| 	Routes     []*types.Route | ||||
| 	raw        []*types100.Result | ||||
| } | ||||
|  | ||||
| // Raw returns the raw CNI results of multiple networks. | ||||
| func (r *Result) Raw() []*types100.Result { | ||||
| 	return r.raw | ||||
| } | ||||
|  | ||||
| type Config struct { | ||||
| @@ -51,15 +57,16 @@ type Config struct { | ||||
| 	Sandbox   string | ||||
| } | ||||
|  | ||||
| // createResult creates a Result from the given slice of current.Result, adding | ||||
| // createResult creates a Result from the given slice of types100.Result, adding | ||||
| // structured data containing the interface configuration for each of the | ||||
| // interfaces created in the namespace. It returns an error if validation of | ||||
| // results fails, or if a network could not be found. | ||||
| func (c *libcni) createResult(results []*current.Result) (*Result, error) { | ||||
| func (c *libcni) createResult(results []*types100.Result) (*Result, error) { | ||||
| 	c.RLock() | ||||
| 	defer c.RUnlock() | ||||
| 	r := &Result{ | ||||
| 		Interfaces: make(map[string]*Config), | ||||
| 		raw:        results, | ||||
| 	} | ||||
|  | ||||
| 	// Plugins may not need to return Interfaces in result if | ||||
| @@ -80,7 +87,7 @@ func (c *libcni) createResult(results []*current.Result) (*Result, error) { | ||||
| 		// interfaces | ||||
| 		for _, ipConf := range result.IPs { | ||||
| 			if err := validateInterfaceConfig(ipConf, len(result.Interfaces)); err != nil { | ||||
| 				return nil, errors.Wrapf(ErrInvalidResult, "invalid interface config: %v", err) | ||||
| 				return nil, fmt.Errorf("invalid interface config: %v: %w", err, ErrInvalidResult) | ||||
| 			} | ||||
| 			name := c.getInterfaceName(result.Interfaces, ipConf) | ||||
| 			r.Interfaces[name].IPConfigs = append(r.Interfaces[name].IPConfigs, | ||||
| @@ -90,7 +97,7 @@ func (c *libcni) createResult(results []*current.Result) (*Result, error) { | ||||
| 		r.Routes = append(r.Routes, result.Routes...) | ||||
| 	} | ||||
| 	if _, ok := r.Interfaces[defaultInterface(c.prefix)]; !ok { | ||||
| 		return nil, errors.Wrapf(ErrNotFound, "default network not found for: %s", defaultInterface(c.prefix)) | ||||
| 		return nil, fmt.Errorf("default network not found for: %s: %w", defaultInterface(c.prefix), ErrNotFound) | ||||
| 	} | ||||
| 	return r, nil | ||||
| } | ||||
| @@ -98,8 +105,8 @@ func (c *libcni) createResult(results []*current.Result) (*Result, error) { | ||||
| // getInterfaceName returns the interface name if the plugins | ||||
| // return the result with associated interfaces. If interface | ||||
| // is not present then default interface name is used | ||||
| func (c *libcni) getInterfaceName(interfaces []*current.Interface, | ||||
| 	ipConf *current.IPConfig) string { | ||||
| func (c *libcni) getInterfaceName(interfaces []*types100.Interface, | ||||
| 	ipConf *types100.IPConfig) string { | ||||
| 	if ipConf.Interface != nil { | ||||
| 		return interfaces[*ipConf.Interface].Name | ||||
| 	} | ||||
|   | ||||
							
								
								
									
										74
									
								
								vendor/github.com/containernetworking/cni/libcni/api.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										74
									
								
								vendor/github.com/containernetworking/cni/libcni/api.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -14,6 +14,12 @@ | ||||
|  | ||||
| package libcni | ||||
|  | ||||
| // Note this is the actual implementation of the CNI specification, which | ||||
| // is reflected in the https://github.com/containernetworking/cni/blob/master/SPEC.md file | ||||
| // it is typically bundled into runtime providers (i.e. containerd or cri-o would use this | ||||
| // before calling runc or hcsshim).  It is also bundled into CNI providers as well, for example, | ||||
| // to add an IP to a container, to parse the configuration of the CNI and so on. | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"encoding/json" | ||||
| @@ -25,6 +31,7 @@ import ( | ||||
|  | ||||
| 	"github.com/containernetworking/cni/pkg/invoke" | ||||
| 	"github.com/containernetworking/cni/pkg/types" | ||||
| 	"github.com/containernetworking/cni/pkg/types/create" | ||||
| 	"github.com/containernetworking/cni/pkg/utils" | ||||
| 	"github.com/containernetworking/cni/pkg/version" | ||||
| ) | ||||
| @@ -278,7 +285,7 @@ func (c *CNIConfig) getCachedConfig(netName string, rt *RuntimeConf) ([]byte, *R | ||||
|  | ||||
| 	unmarshaled := cachedInfo{} | ||||
| 	if err := json.Unmarshal(bytes, &unmarshaled); err != nil { | ||||
| 		return nil, nil, fmt.Errorf("failed to unmarshal cached network %q config: %v", netName, err) | ||||
| 		return nil, nil, fmt.Errorf("failed to unmarshal cached network %q config: %w", netName, err) | ||||
| 	} | ||||
| 	if unmarshaled.Kind != CNICacheV1 { | ||||
| 		return nil, nil, fmt.Errorf("read cached network %q config has wrong kind: %v", netName, unmarshaled.Kind) | ||||
| @@ -304,15 +311,8 @@ func (c *CNIConfig) getLegacyCachedResult(netName, cniVersion string, rt *Runtim | ||||
| 		return nil, nil | ||||
| 	} | ||||
|  | ||||
| 	// Read the version of the cached result | ||||
| 	decoder := version.ConfigDecoder{} | ||||
| 	resultCniVersion, err := decoder.Decode(data) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	// Ensure we can understand the result | ||||
| 	result, err := version.NewResult(resultCniVersion, data) | ||||
| 	// Load the cached result | ||||
| 	result, err := create.CreateFromBytes(data) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| @@ -322,10 +322,10 @@ func (c *CNIConfig) getLegacyCachedResult(netName, cniVersion string, rt *Runtim | ||||
| 	// should match the config version unless the config was changed | ||||
| 	// while the container was running. | ||||
| 	result, err = result.GetAsVersion(cniVersion) | ||||
| 	if err != nil && resultCniVersion != cniVersion { | ||||
| 		return nil, fmt.Errorf("failed to convert cached result version %q to config version %q: %v", resultCniVersion, cniVersion, err) | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("failed to convert cached result to config version %q: %w", cniVersion, err) | ||||
| 	} | ||||
| 	return result, err | ||||
| 	return result, nil | ||||
| } | ||||
|  | ||||
| func (c *CNIConfig) getCachedResult(netName, cniVersion string, rt *RuntimeConf) (types.Result, error) { | ||||
| @@ -346,18 +346,11 @@ func (c *CNIConfig) getCachedResult(netName, cniVersion string, rt *RuntimeConf) | ||||
|  | ||||
| 	newBytes, err := json.Marshal(&cachedInfo.RawResult) | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("failed to marshal cached network %q config: %v", netName, err) | ||||
| 		return nil, fmt.Errorf("failed to marshal cached network %q config: %w", netName, err) | ||||
| 	} | ||||
|  | ||||
| 	// Read the version of the cached result | ||||
| 	decoder := version.ConfigDecoder{} | ||||
| 	resultCniVersion, err := decoder.Decode(newBytes) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	// Ensure we can understand the result | ||||
| 	result, err := version.NewResult(resultCniVersion, newBytes) | ||||
| 	// Load the cached result | ||||
| 	result, err := create.CreateFromBytes(newBytes) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| @@ -367,10 +360,10 @@ func (c *CNIConfig) getCachedResult(netName, cniVersion string, rt *RuntimeConf) | ||||
| 	// should match the config version unless the config was changed | ||||
| 	// while the container was running. | ||||
| 	result, err = result.GetAsVersion(cniVersion) | ||||
| 	if err != nil && resultCniVersion != cniVersion { | ||||
| 		return nil, fmt.Errorf("failed to convert cached result version %q to config version %q: %v", resultCniVersion, cniVersion, err) | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("failed to convert cached result to config version %q: %w", cniVersion, err) | ||||
| 	} | ||||
| 	return result, err | ||||
| 	return result, nil | ||||
| } | ||||
|  | ||||
| // GetNetworkListCachedResult returns the cached Result of the previous | ||||
| @@ -428,12 +421,12 @@ func (c *CNIConfig) AddNetworkList(ctx context.Context, list *NetworkConfigList, | ||||
| 	for _, net := range list.Plugins { | ||||
| 		result, err = c.addNetwork(ctx, list.Name, list.CNIVersion, net, result, rt) | ||||
| 		if err != nil { | ||||
| 			return nil, err | ||||
| 			return nil, fmt.Errorf("plugin %s failed (add): %w", pluginDescription(net.Network), err) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	if err = c.cacheAdd(result, list.Bytes, list.Name, rt); err != nil { | ||||
| 		return nil, fmt.Errorf("failed to set network %q cached result: %v", list.Name, err) | ||||
| 		return nil, fmt.Errorf("failed to set network %q cached result: %w", list.Name, err) | ||||
| 	} | ||||
|  | ||||
| 	return result, nil | ||||
| @@ -469,7 +462,7 @@ func (c *CNIConfig) CheckNetworkList(ctx context.Context, list *NetworkConfigLis | ||||
|  | ||||
| 	cachedResult, err := c.getCachedResult(list.Name, list.CNIVersion, rt) | ||||
| 	if err != nil { | ||||
| 		return fmt.Errorf("failed to get network %q cached result: %v", list.Name, err) | ||||
| 		return fmt.Errorf("failed to get network %q cached result: %w", list.Name, err) | ||||
| 	} | ||||
|  | ||||
| 	for _, net := range list.Plugins { | ||||
| @@ -506,14 +499,14 @@ func (c *CNIConfig) DelNetworkList(ctx context.Context, list *NetworkConfigList, | ||||
| 	} else if gtet { | ||||
| 		cachedResult, err = c.getCachedResult(list.Name, list.CNIVersion, rt) | ||||
| 		if err != nil { | ||||
| 			return fmt.Errorf("failed to get network %q cached result: %v", list.Name, err) | ||||
| 			return fmt.Errorf("failed to get network %q cached result: %w", list.Name, err) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	for i := len(list.Plugins) - 1; i >= 0; i-- { | ||||
| 		net := list.Plugins[i] | ||||
| 		if err := c.delNetwork(ctx, list.Name, list.CNIVersion, net, cachedResult, rt); err != nil { | ||||
| 			return err | ||||
| 			return fmt.Errorf("plugin %s failed (delete): %w", pluginDescription(net.Network), err) | ||||
| 		} | ||||
| 	} | ||||
| 	_ = c.cacheDel(list.Name, rt) | ||||
| @@ -521,6 +514,19 @@ func (c *CNIConfig) DelNetworkList(ctx context.Context, list *NetworkConfigList, | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func pluginDescription(net *types.NetConf) string { | ||||
| 	if net == nil { | ||||
| 		return "<missing>" | ||||
| 	} | ||||
| 	pluginType := net.Type | ||||
| 	out := fmt.Sprintf("type=%q", pluginType) | ||||
| 	name := net.Name | ||||
| 	if name != "" { | ||||
| 		out += fmt.Sprintf(" name=%q", name) | ||||
| 	} | ||||
| 	return out | ||||
| } | ||||
|  | ||||
| // AddNetwork executes the plugin with the ADD command | ||||
| func (c *CNIConfig) AddNetwork(ctx context.Context, net *NetworkConfig, rt *RuntimeConf) (types.Result, error) { | ||||
| 	result, err := c.addNetwork(ctx, net.Network.Name, net.Network.CNIVersion, net, nil, rt) | ||||
| @@ -529,7 +535,7 @@ func (c *CNIConfig) AddNetwork(ctx context.Context, net *NetworkConfig, rt *Runt | ||||
| 	} | ||||
|  | ||||
| 	if err = c.cacheAdd(result, net.Bytes, net.Network.Name, rt); err != nil { | ||||
| 		return nil, fmt.Errorf("failed to set network %q cached result: %v", net.Network.Name, err) | ||||
| 		return nil, fmt.Errorf("failed to set network %q cached result: %w", net.Network.Name, err) | ||||
| 	} | ||||
|  | ||||
| 	return result, nil | ||||
| @@ -546,7 +552,7 @@ func (c *CNIConfig) CheckNetwork(ctx context.Context, net *NetworkConfig, rt *Ru | ||||
|  | ||||
| 	cachedResult, err := c.getCachedResult(net.Network.Name, net.Network.CNIVersion, rt) | ||||
| 	if err != nil { | ||||
| 		return fmt.Errorf("failed to get network %q cached result: %v", net.Network.Name, err) | ||||
| 		return fmt.Errorf("failed to get network %q cached result: %w", net.Network.Name, err) | ||||
| 	} | ||||
| 	return c.checkNetwork(ctx, net.Network.Name, net.Network.CNIVersion, net, cachedResult, rt) | ||||
| } | ||||
| @@ -561,7 +567,7 @@ func (c *CNIConfig) DelNetwork(ctx context.Context, net *NetworkConfig, rt *Runt | ||||
| 	} else if gtet { | ||||
| 		cachedResult, err = c.getCachedResult(net.Network.Name, net.Network.CNIVersion, rt) | ||||
| 		if err != nil { | ||||
| 			return fmt.Errorf("failed to get network %q cached result: %v", net.Network.Name, err) | ||||
| 			return fmt.Errorf("failed to get network %q cached result: %w", net.Network.Name, err) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
|   | ||||
							
								
								
									
										14
									
								
								vendor/github.com/containernetworking/cni/libcni/conf.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										14
									
								
								vendor/github.com/containernetworking/cni/libcni/conf.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -43,7 +43,7 @@ func (e NoConfigsFoundError) Error() string { | ||||
| func ConfFromBytes(bytes []byte) (*NetworkConfig, error) { | ||||
| 	conf := &NetworkConfig{Bytes: bytes} | ||||
| 	if err := json.Unmarshal(bytes, &conf.Network); err != nil { | ||||
| 		return nil, fmt.Errorf("error parsing configuration: %s", err) | ||||
| 		return nil, fmt.Errorf("error parsing configuration: %w", err) | ||||
| 	} | ||||
| 	if conf.Network.Type == "" { | ||||
| 		return nil, fmt.Errorf("error parsing configuration: missing 'type'") | ||||
| @@ -54,7 +54,7 @@ func ConfFromBytes(bytes []byte) (*NetworkConfig, error) { | ||||
| func ConfFromFile(filename string) (*NetworkConfig, error) { | ||||
| 	bytes, err := ioutil.ReadFile(filename) | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("error reading %s: %s", filename, err) | ||||
| 		return nil, fmt.Errorf("error reading %s: %w", filename, err) | ||||
| 	} | ||||
| 	return ConfFromBytes(bytes) | ||||
| } | ||||
| @@ -62,7 +62,7 @@ func ConfFromFile(filename string) (*NetworkConfig, error) { | ||||
| func ConfListFromBytes(bytes []byte) (*NetworkConfigList, error) { | ||||
| 	rawList := make(map[string]interface{}) | ||||
| 	if err := json.Unmarshal(bytes, &rawList); err != nil { | ||||
| 		return nil, fmt.Errorf("error parsing configuration list: %s", err) | ||||
| 		return nil, fmt.Errorf("error parsing configuration list: %w", err) | ||||
| 	} | ||||
|  | ||||
| 	rawName, ok := rawList["name"] | ||||
| @@ -114,11 +114,11 @@ func ConfListFromBytes(bytes []byte) (*NetworkConfigList, error) { | ||||
| 	for i, conf := range plugins { | ||||
| 		newBytes, err := json.Marshal(conf) | ||||
| 		if err != nil { | ||||
| 			return nil, fmt.Errorf("failed to marshal plugin config %d: %v", i, err) | ||||
| 			return nil, fmt.Errorf("failed to marshal plugin config %d: %w", i, err) | ||||
| 		} | ||||
| 		netConf, err := ConfFromBytes(newBytes) | ||||
| 		if err != nil { | ||||
| 			return nil, fmt.Errorf("failed to parse plugin config %d: %v", i, err) | ||||
| 			return nil, fmt.Errorf("failed to parse plugin config %d: %w", i, err) | ||||
| 		} | ||||
| 		list.Plugins = append(list.Plugins, netConf) | ||||
| 	} | ||||
| @@ -129,7 +129,7 @@ func ConfListFromBytes(bytes []byte) (*NetworkConfigList, error) { | ||||
| func ConfListFromFile(filename string) (*NetworkConfigList, error) { | ||||
| 	bytes, err := ioutil.ReadFile(filename) | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("error reading %s: %s", filename, err) | ||||
| 		return nil, fmt.Errorf("error reading %s: %w", filename, err) | ||||
| 	} | ||||
| 	return ConfListFromBytes(bytes) | ||||
| } | ||||
| @@ -218,7 +218,7 @@ func InjectConf(original *NetworkConfig, newValues map[string]interface{}) (*Net | ||||
| 	config := make(map[string]interface{}) | ||||
| 	err := json.Unmarshal(original.Bytes, &config) | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("unmarshal existing network bytes: %s", err) | ||||
| 		return nil, fmt.Errorf("unmarshal existing network bytes: %w", err) | ||||
| 	} | ||||
|  | ||||
| 	for key, value := range newValues { | ||||
|   | ||||
							
								
								
									
										10
									
								
								vendor/github.com/containernetworking/cni/pkg/invoke/exec.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										10
									
								
								vendor/github.com/containernetworking/cni/pkg/invoke/exec.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -20,6 +20,7 @@ import ( | ||||
| 	"os" | ||||
|  | ||||
| 	"github.com/containernetworking/cni/pkg/types" | ||||
| 	"github.com/containernetworking/cni/pkg/types/create" | ||||
| 	"github.com/containernetworking/cni/pkg/version" | ||||
| ) | ||||
|  | ||||
| @@ -83,14 +84,7 @@ func ExecPluginWithResult(ctx context.Context, pluginPath string, netconf []byte | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	// Plugin must return result in same version as specified in netconf | ||||
| 	versionDecoder := &version.ConfigDecoder{} | ||||
| 	confVersion, err := versionDecoder.Decode(netconf) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	return version.NewResult(confVersion, stdoutBytes) | ||||
| 	return create.CreateFromBytes(stdoutBytes) | ||||
| } | ||||
|  | ||||
| func ExecPluginWithoutResult(ctx context.Context, pluginPath string, netconf []byte, args CNIArgs, exec Exec) error { | ||||
|   | ||||
							
								
								
									
										85
									
								
								vendor/github.com/containernetworking/cni/pkg/types/020/types.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										85
									
								
								vendor/github.com/containernetworking/cni/pkg/types/020/types.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -22,25 +22,47 @@ import ( | ||||
| 	"os" | ||||
|  | ||||
| 	"github.com/containernetworking/cni/pkg/types" | ||||
| 	convert "github.com/containernetworking/cni/pkg/types/internal" | ||||
| ) | ||||
|  | ||||
| const ImplementedSpecVersion string = "0.2.0" | ||||
|  | ||||
| var SupportedVersions = []string{"", "0.1.0", ImplementedSpecVersion} | ||||
| var supportedVersions = []string{"", "0.1.0", ImplementedSpecVersion} | ||||
|  | ||||
| // Register converters for all versions less than the implemented spec version | ||||
| func init() { | ||||
| 	convert.RegisterConverter("0.1.0", []string{ImplementedSpecVersion}, convertFrom010) | ||||
| 	convert.RegisterConverter(ImplementedSpecVersion, []string{"0.1.0"}, convertTo010) | ||||
|  | ||||
| 	// Creator | ||||
| 	convert.RegisterCreator(supportedVersions, NewResult) | ||||
| } | ||||
|  | ||||
| // Compatibility types for CNI version 0.1.0 and 0.2.0 | ||||
|  | ||||
| // NewResult creates a new Result object from JSON data. The JSON data | ||||
| // must be compatible with the CNI versions implemented by this type. | ||||
| func NewResult(data []byte) (types.Result, error) { | ||||
| 	result := &Result{} | ||||
| 	if err := json.Unmarshal(data, result); err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	return result, nil | ||||
| 	for _, v := range supportedVersions { | ||||
| 		if result.CNIVersion == v { | ||||
| 			if result.CNIVersion == "" { | ||||
| 				result.CNIVersion = "0.1.0" | ||||
| 			} | ||||
| 			return result, nil | ||||
| 		} | ||||
| 	} | ||||
| 	return nil, fmt.Errorf("result type supports %v but unmarshalled CNIVersion is %q", | ||||
| 		supportedVersions, result.CNIVersion) | ||||
| } | ||||
|  | ||||
| // GetResult converts the given Result object to the ImplementedSpecVersion | ||||
| // and returns the concrete type or an error | ||||
| func GetResult(r types.Result) (*Result, error) { | ||||
| 	// We expect version 0.1.0/0.2.0 results | ||||
| 	result020, err := r.GetAsVersion(ImplementedSpecVersion) | ||||
| 	result020, err := convert.Convert(r, ImplementedSpecVersion) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| @@ -51,6 +73,32 @@ func GetResult(r types.Result) (*Result, error) { | ||||
| 	return result, nil | ||||
| } | ||||
|  | ||||
| func convertFrom010(from types.Result, toVersion string) (types.Result, error) { | ||||
| 	if toVersion != "0.2.0" { | ||||
| 		panic("only converts to version 0.2.0") | ||||
| 	} | ||||
| 	fromResult := from.(*Result) | ||||
| 	return &Result{ | ||||
| 		CNIVersion: ImplementedSpecVersion, | ||||
| 		IP4:        fromResult.IP4.Copy(), | ||||
| 		IP6:        fromResult.IP6.Copy(), | ||||
| 		DNS:        *fromResult.DNS.Copy(), | ||||
| 	}, nil | ||||
| } | ||||
|  | ||||
| func convertTo010(from types.Result, toVersion string) (types.Result, error) { | ||||
| 	if toVersion != "0.1.0" { | ||||
| 		panic("only converts to version 0.1.0") | ||||
| 	} | ||||
| 	fromResult := from.(*Result) | ||||
| 	return &Result{ | ||||
| 		CNIVersion: "0.1.0", | ||||
| 		IP4:        fromResult.IP4.Copy(), | ||||
| 		IP6:        fromResult.IP6.Copy(), | ||||
| 		DNS:        *fromResult.DNS.Copy(), | ||||
| 	}, nil | ||||
| } | ||||
|  | ||||
| // Result is what gets returned from the plugin (via stdout) to the caller | ||||
| type Result struct { | ||||
| 	CNIVersion string    `json:"cniVersion,omitempty"` | ||||
| @@ -60,17 +108,16 @@ type Result struct { | ||||
| } | ||||
|  | ||||
| func (r *Result) Version() string { | ||||
| 	return ImplementedSpecVersion | ||||
| 	return r.CNIVersion | ||||
| } | ||||
|  | ||||
| func (r *Result) GetAsVersion(version string) (types.Result, error) { | ||||
| 	for _, supportedVersion := range SupportedVersions { | ||||
| 		if version == supportedVersion { | ||||
| 			r.CNIVersion = version | ||||
| 			return r, nil | ||||
| 		} | ||||
| 	// If the creator of the result did not set the CNIVersion, assume it | ||||
| 	// should be the highest spec version implemented by this Result | ||||
| 	if r.CNIVersion == "" { | ||||
| 		r.CNIVersion = ImplementedSpecVersion | ||||
| 	} | ||||
| 	return nil, fmt.Errorf("cannot convert version %q to %s", SupportedVersions, version) | ||||
| 	return convert.Convert(r, version) | ||||
| } | ||||
|  | ||||
| func (r *Result) Print() error { | ||||
| @@ -93,6 +140,22 @@ type IPConfig struct { | ||||
| 	Routes  []types.Route | ||||
| } | ||||
|  | ||||
| func (i *IPConfig) Copy() *IPConfig { | ||||
| 	if i == nil { | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| 	var routes []types.Route | ||||
| 	for _, fromRoute := range i.Routes { | ||||
| 		routes = append(routes, *fromRoute.Copy()) | ||||
| 	} | ||||
| 	return &IPConfig{ | ||||
| 		IP:      i.IP, | ||||
| 		Gateway: i.Gateway, | ||||
| 		Routes:  routes, | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // net.IPNet is not JSON (un)marshallable so this duality is needed | ||||
| // for our custom IPNet type | ||||
|  | ||||
|   | ||||
							
								
								
									
										306
									
								
								vendor/github.com/containernetworking/cni/pkg/types/040/types.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										306
									
								
								vendor/github.com/containernetworking/cni/pkg/types/040/types.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,306 @@ | ||||
| // Copyright 2016 CNI authors | ||||
| // | ||||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| // you may not use this file except in compliance with the License. | ||||
| // You may obtain a copy of the License at | ||||
| // | ||||
| //     http://www.apache.org/licenses/LICENSE-2.0 | ||||
| // | ||||
| // Unless required by applicable law or agreed to in writing, software | ||||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
|  | ||||
| package types040 | ||||
|  | ||||
| import ( | ||||
| 	"encoding/json" | ||||
| 	"fmt" | ||||
| 	"io" | ||||
| 	"net" | ||||
| 	"os" | ||||
|  | ||||
| 	"github.com/containernetworking/cni/pkg/types" | ||||
| 	types020 "github.com/containernetworking/cni/pkg/types/020" | ||||
| 	convert "github.com/containernetworking/cni/pkg/types/internal" | ||||
| ) | ||||
|  | ||||
| const ImplementedSpecVersion string = "0.4.0" | ||||
|  | ||||
| var supportedVersions = []string{"0.3.0", "0.3.1", ImplementedSpecVersion} | ||||
|  | ||||
| // Register converters for all versions less than the implemented spec version | ||||
| func init() { | ||||
| 	// Up-converters | ||||
| 	convert.RegisterConverter("0.1.0", supportedVersions, convertFrom02x) | ||||
| 	convert.RegisterConverter("0.2.0", supportedVersions, convertFrom02x) | ||||
| 	convert.RegisterConverter("0.3.0", supportedVersions, convertInternal) | ||||
| 	convert.RegisterConverter("0.3.1", supportedVersions, convertInternal) | ||||
|  | ||||
| 	// Down-converters | ||||
| 	convert.RegisterConverter("0.4.0", []string{"0.3.0", "0.3.1"}, convertInternal) | ||||
| 	convert.RegisterConverter("0.4.0", []string{"0.1.0", "0.2.0"}, convertTo02x) | ||||
| 	convert.RegisterConverter("0.3.1", []string{"0.1.0", "0.2.0"}, convertTo02x) | ||||
| 	convert.RegisterConverter("0.3.0", []string{"0.1.0", "0.2.0"}, convertTo02x) | ||||
|  | ||||
| 	// Creator | ||||
| 	convert.RegisterCreator(supportedVersions, NewResult) | ||||
| } | ||||
|  | ||||
| func NewResult(data []byte) (types.Result, error) { | ||||
| 	result := &Result{} | ||||
| 	if err := json.Unmarshal(data, result); err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	for _, v := range supportedVersions { | ||||
| 		if result.CNIVersion == v { | ||||
| 			return result, nil | ||||
| 		} | ||||
| 	} | ||||
| 	return nil, fmt.Errorf("result type supports %v but unmarshalled CNIVersion is %q", | ||||
| 		supportedVersions, result.CNIVersion) | ||||
| } | ||||
|  | ||||
| func GetResult(r types.Result) (*Result, error) { | ||||
| 	resultCurrent, err := r.GetAsVersion(ImplementedSpecVersion) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	result, ok := resultCurrent.(*Result) | ||||
| 	if !ok { | ||||
| 		return nil, fmt.Errorf("failed to convert result") | ||||
| 	} | ||||
| 	return result, nil | ||||
| } | ||||
|  | ||||
| func NewResultFromResult(result types.Result) (*Result, error) { | ||||
| 	newResult, err := convert.Convert(result, ImplementedSpecVersion) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	return newResult.(*Result), nil | ||||
| } | ||||
|  | ||||
| // Result is what gets returned from the plugin (via stdout) to the caller | ||||
| type Result struct { | ||||
| 	CNIVersion string         `json:"cniVersion,omitempty"` | ||||
| 	Interfaces []*Interface   `json:"interfaces,omitempty"` | ||||
| 	IPs        []*IPConfig    `json:"ips,omitempty"` | ||||
| 	Routes     []*types.Route `json:"routes,omitempty"` | ||||
| 	DNS        types.DNS      `json:"dns,omitempty"` | ||||
| } | ||||
|  | ||||
| func convert020IPConfig(from *types020.IPConfig, ipVersion string) *IPConfig { | ||||
| 	return &IPConfig{ | ||||
| 		Version: ipVersion, | ||||
| 		Address: from.IP, | ||||
| 		Gateway: from.Gateway, | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func convertFrom02x(from types.Result, toVersion string) (types.Result, error) { | ||||
| 	fromResult := from.(*types020.Result) | ||||
| 	toResult := &Result{ | ||||
| 		CNIVersion: toVersion, | ||||
| 		DNS:        *fromResult.DNS.Copy(), | ||||
| 		Routes:     []*types.Route{}, | ||||
| 	} | ||||
| 	if fromResult.IP4 != nil { | ||||
| 		toResult.IPs = append(toResult.IPs, convert020IPConfig(fromResult.IP4, "4")) | ||||
| 		for _, fromRoute := range fromResult.IP4.Routes { | ||||
| 			toResult.Routes = append(toResult.Routes, fromRoute.Copy()) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	if fromResult.IP6 != nil { | ||||
| 		toResult.IPs = append(toResult.IPs, convert020IPConfig(fromResult.IP6, "6")) | ||||
| 		for _, fromRoute := range fromResult.IP6.Routes { | ||||
| 			toResult.Routes = append(toResult.Routes, fromRoute.Copy()) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return toResult, nil | ||||
| } | ||||
|  | ||||
| func convertInternal(from types.Result, toVersion string) (types.Result, error) { | ||||
| 	fromResult := from.(*Result) | ||||
| 	toResult := &Result{ | ||||
| 		CNIVersion: toVersion, | ||||
| 		DNS:        *fromResult.DNS.Copy(), | ||||
| 		Routes:     []*types.Route{}, | ||||
| 	} | ||||
| 	for _, fromIntf := range fromResult.Interfaces { | ||||
| 		toResult.Interfaces = append(toResult.Interfaces, fromIntf.Copy()) | ||||
| 	} | ||||
| 	for _, fromIPC := range fromResult.IPs { | ||||
| 		toResult.IPs = append(toResult.IPs, fromIPC.Copy()) | ||||
| 	} | ||||
| 	for _, fromRoute := range fromResult.Routes { | ||||
| 		toResult.Routes = append(toResult.Routes, fromRoute.Copy()) | ||||
| 	} | ||||
| 	return toResult, nil | ||||
| } | ||||
|  | ||||
| func convertTo02x(from types.Result, toVersion string) (types.Result, error) { | ||||
| 	fromResult := from.(*Result) | ||||
| 	toResult := &types020.Result{ | ||||
| 		CNIVersion: toVersion, | ||||
| 		DNS:        *fromResult.DNS.Copy(), | ||||
| 	} | ||||
|  | ||||
| 	for _, fromIP := range fromResult.IPs { | ||||
| 		// Only convert the first IP address of each version as 0.2.0 | ||||
| 		// and earlier cannot handle multiple IP addresses | ||||
| 		if fromIP.Version == "4" && toResult.IP4 == nil { | ||||
| 			toResult.IP4 = &types020.IPConfig{ | ||||
| 				IP:      fromIP.Address, | ||||
| 				Gateway: fromIP.Gateway, | ||||
| 			} | ||||
| 		} else if fromIP.Version == "6" && toResult.IP6 == nil { | ||||
| 			toResult.IP6 = &types020.IPConfig{ | ||||
| 				IP:      fromIP.Address, | ||||
| 				Gateway: fromIP.Gateway, | ||||
| 			} | ||||
| 		} | ||||
| 		if toResult.IP4 != nil && toResult.IP6 != nil { | ||||
| 			break | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	for _, fromRoute := range fromResult.Routes { | ||||
| 		is4 := fromRoute.Dst.IP.To4() != nil | ||||
| 		if is4 && toResult.IP4 != nil { | ||||
| 			toResult.IP4.Routes = append(toResult.IP4.Routes, types.Route{ | ||||
| 				Dst: fromRoute.Dst, | ||||
| 				GW:  fromRoute.GW, | ||||
| 			}) | ||||
| 		} else if !is4 && toResult.IP6 != nil { | ||||
| 			toResult.IP6.Routes = append(toResult.IP6.Routes, types.Route{ | ||||
| 				Dst: fromRoute.Dst, | ||||
| 				GW:  fromRoute.GW, | ||||
| 			}) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	// 0.2.0 and earlier require at least one IP address in the Result | ||||
| 	if toResult.IP4 == nil && toResult.IP6 == nil { | ||||
| 		return nil, fmt.Errorf("cannot convert: no valid IP addresses") | ||||
| 	} | ||||
|  | ||||
| 	return toResult, nil | ||||
| } | ||||
|  | ||||
| func (r *Result) Version() string { | ||||
| 	return r.CNIVersion | ||||
| } | ||||
|  | ||||
| func (r *Result) GetAsVersion(version string) (types.Result, error) { | ||||
| 	// If the creator of the result did not set the CNIVersion, assume it | ||||
| 	// should be the highest spec version implemented by this Result | ||||
| 	if r.CNIVersion == "" { | ||||
| 		r.CNIVersion = ImplementedSpecVersion | ||||
| 	} | ||||
| 	return convert.Convert(r, version) | ||||
| } | ||||
|  | ||||
| func (r *Result) Print() error { | ||||
| 	return r.PrintTo(os.Stdout) | ||||
| } | ||||
|  | ||||
| func (r *Result) PrintTo(writer io.Writer) error { | ||||
| 	data, err := json.MarshalIndent(r, "", "    ") | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	_, err = writer.Write(data) | ||||
| 	return err | ||||
| } | ||||
|  | ||||
| // Interface contains values about the created interfaces | ||||
| type Interface struct { | ||||
| 	Name    string `json:"name"` | ||||
| 	Mac     string `json:"mac,omitempty"` | ||||
| 	Sandbox string `json:"sandbox,omitempty"` | ||||
| } | ||||
|  | ||||
| func (i *Interface) String() string { | ||||
| 	return fmt.Sprintf("%+v", *i) | ||||
| } | ||||
|  | ||||
| func (i *Interface) Copy() *Interface { | ||||
| 	if i == nil { | ||||
| 		return nil | ||||
| 	} | ||||
| 	newIntf := *i | ||||
| 	return &newIntf | ||||
| } | ||||
|  | ||||
| // Int returns a pointer to the int value passed in.  Used to | ||||
| // set the IPConfig.Interface field. | ||||
| func Int(v int) *int { | ||||
| 	return &v | ||||
| } | ||||
|  | ||||
| // IPConfig contains values necessary to configure an IP address on an interface | ||||
| type IPConfig struct { | ||||
| 	// IP version, either "4" or "6" | ||||
| 	Version string | ||||
| 	// Index into Result structs Interfaces list | ||||
| 	Interface *int | ||||
| 	Address   net.IPNet | ||||
| 	Gateway   net.IP | ||||
| } | ||||
|  | ||||
| func (i *IPConfig) String() string { | ||||
| 	return fmt.Sprintf("%+v", *i) | ||||
| } | ||||
|  | ||||
| func (i *IPConfig) Copy() *IPConfig { | ||||
| 	if i == nil { | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| 	ipc := &IPConfig{ | ||||
| 		Version: i.Version, | ||||
| 		Address: i.Address, | ||||
| 		Gateway: i.Gateway, | ||||
| 	} | ||||
| 	if i.Interface != nil { | ||||
| 		intf := *i.Interface | ||||
| 		ipc.Interface = &intf | ||||
| 	} | ||||
| 	return ipc | ||||
| } | ||||
|  | ||||
| // JSON (un)marshallable types | ||||
| type ipConfig struct { | ||||
| 	Version   string      `json:"version"` | ||||
| 	Interface *int        `json:"interface,omitempty"` | ||||
| 	Address   types.IPNet `json:"address"` | ||||
| 	Gateway   net.IP      `json:"gateway,omitempty"` | ||||
| } | ||||
|  | ||||
| func (c *IPConfig) MarshalJSON() ([]byte, error) { | ||||
| 	ipc := ipConfig{ | ||||
| 		Version:   c.Version, | ||||
| 		Interface: c.Interface, | ||||
| 		Address:   types.IPNet(c.Address), | ||||
| 		Gateway:   c.Gateway, | ||||
| 	} | ||||
|  | ||||
| 	return json.Marshal(ipc) | ||||
| } | ||||
|  | ||||
| func (c *IPConfig) UnmarshalJSON(data []byte) error { | ||||
| 	ipc := ipConfig{} | ||||
| 	if err := json.Unmarshal(data, &ipc); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	c.Version = ipc.Version | ||||
| 	c.Interface = ipc.Interface | ||||
| 	c.Address = net.IPNet(ipc.Address) | ||||
| 	c.Gateway = ipc.Gateway | ||||
| 	return nil | ||||
| } | ||||
							
								
								
									
										307
									
								
								vendor/github.com/containernetworking/cni/pkg/types/100/types.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										307
									
								
								vendor/github.com/containernetworking/cni/pkg/types/100/types.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,307 @@ | ||||
| // Copyright 2016 CNI authors | ||||
| // | ||||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| // you may not use this file except in compliance with the License. | ||||
| // You may obtain a copy of the License at | ||||
| // | ||||
| //     http://www.apache.org/licenses/LICENSE-2.0 | ||||
| // | ||||
| // Unless required by applicable law or agreed to in writing, software | ||||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
|  | ||||
| package types100 | ||||
|  | ||||
| import ( | ||||
| 	"encoding/json" | ||||
| 	"fmt" | ||||
| 	"io" | ||||
| 	"net" | ||||
| 	"os" | ||||
|  | ||||
| 	"github.com/containernetworking/cni/pkg/types" | ||||
| 	types040 "github.com/containernetworking/cni/pkg/types/040" | ||||
| 	convert "github.com/containernetworking/cni/pkg/types/internal" | ||||
| ) | ||||
|  | ||||
| const ImplementedSpecVersion string = "1.0.0" | ||||
|  | ||||
| var supportedVersions = []string{ImplementedSpecVersion} | ||||
|  | ||||
| // Register converters for all versions less than the implemented spec version | ||||
| func init() { | ||||
| 	// Up-converters | ||||
| 	convert.RegisterConverter("0.1.0", supportedVersions, convertFrom02x) | ||||
| 	convert.RegisterConverter("0.2.0", supportedVersions, convertFrom02x) | ||||
| 	convert.RegisterConverter("0.3.0", supportedVersions, convertFrom04x) | ||||
| 	convert.RegisterConverter("0.3.1", supportedVersions, convertFrom04x) | ||||
| 	convert.RegisterConverter("0.4.0", supportedVersions, convertFrom04x) | ||||
|  | ||||
| 	// 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) | ||||
|  | ||||
| 	// Creator | ||||
| 	convert.RegisterCreator(supportedVersions, NewResult) | ||||
| } | ||||
|  | ||||
| func NewResult(data []byte) (types.Result, error) { | ||||
| 	result := &Result{} | ||||
| 	if err := json.Unmarshal(data, result); err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	for _, v := range supportedVersions { | ||||
| 		if result.CNIVersion == v { | ||||
| 			return result, nil | ||||
| 		} | ||||
| 	} | ||||
| 	return nil, fmt.Errorf("result type supports %v but unmarshalled CNIVersion is %q", | ||||
| 		supportedVersions, result.CNIVersion) | ||||
| } | ||||
|  | ||||
| func GetResult(r types.Result) (*Result, error) { | ||||
| 	resultCurrent, err := r.GetAsVersion(ImplementedSpecVersion) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	result, ok := resultCurrent.(*Result) | ||||
| 	if !ok { | ||||
| 		return nil, fmt.Errorf("failed to convert result") | ||||
| 	} | ||||
| 	return result, nil | ||||
| } | ||||
|  | ||||
| func NewResultFromResult(result types.Result) (*Result, error) { | ||||
| 	newResult, err := convert.Convert(result, ImplementedSpecVersion) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	return newResult.(*Result), nil | ||||
| } | ||||
|  | ||||
| // Result is what gets returned from the plugin (via stdout) to the caller | ||||
| type Result struct { | ||||
| 	CNIVersion string         `json:"cniVersion,omitempty"` | ||||
| 	Interfaces []*Interface   `json:"interfaces,omitempty"` | ||||
| 	IPs        []*IPConfig    `json:"ips,omitempty"` | ||||
| 	Routes     []*types.Route `json:"routes,omitempty"` | ||||
| 	DNS        types.DNS      `json:"dns,omitempty"` | ||||
| } | ||||
|  | ||||
| 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) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	return result100, nil | ||||
| } | ||||
|  | ||||
| func convertIPConfigFrom040(from *types040.IPConfig) *IPConfig { | ||||
| 	to := &IPConfig{ | ||||
| 		Address: from.Address, | ||||
| 		Gateway: from.Gateway, | ||||
| 	} | ||||
| 	if from.Interface != nil { | ||||
| 		intf := *from.Interface | ||||
| 		to.Interface = &intf | ||||
| 	} | ||||
| 	return to | ||||
| } | ||||
|  | ||||
| func convertInterfaceFrom040(from *types040.Interface) *Interface { | ||||
| 	return &Interface{ | ||||
| 		Name:    from.Name, | ||||
| 		Mac:     from.Mac, | ||||
| 		Sandbox: from.Sandbox, | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func convertFrom04x(from types.Result, toVersion string) (types.Result, error) { | ||||
| 	fromResult := from.(*types040.Result) | ||||
| 	toResult := &Result{ | ||||
| 		CNIVersion: toVersion, | ||||
| 		DNS:        *fromResult.DNS.Copy(), | ||||
| 		Routes:     []*types.Route{}, | ||||
| 	} | ||||
| 	for _, fromIntf := range fromResult.Interfaces { | ||||
| 		toResult.Interfaces = append(toResult.Interfaces, convertInterfaceFrom040(fromIntf)) | ||||
| 	} | ||||
| 	for _, fromIPC := range fromResult.IPs { | ||||
| 		toResult.IPs = append(toResult.IPs, convertIPConfigFrom040(fromIPC)) | ||||
| 	} | ||||
| 	for _, fromRoute := range fromResult.Routes { | ||||
| 		toResult.Routes = append(toResult.Routes, fromRoute.Copy()) | ||||
| 	} | ||||
| 	return toResult, nil | ||||
| } | ||||
|  | ||||
| func convertIPConfigTo040(from *IPConfig) *types040.IPConfig { | ||||
| 	version := "6" | ||||
| 	if from.Address.IP.To4() != nil { | ||||
| 		version = "4" | ||||
| 	} | ||||
| 	to := &types040.IPConfig{ | ||||
| 		Version: version, | ||||
| 		Address: from.Address, | ||||
| 		Gateway: from.Gateway, | ||||
| 	} | ||||
| 	if from.Interface != nil { | ||||
| 		intf := *from.Interface | ||||
| 		to.Interface = &intf | ||||
| 	} | ||||
| 	return to | ||||
| } | ||||
|  | ||||
| func convertInterfaceTo040(from *Interface) *types040.Interface { | ||||
| 	return &types040.Interface{ | ||||
| 		Name:    from.Name, | ||||
| 		Mac:     from.Mac, | ||||
| 		Sandbox: from.Sandbox, | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func convertTo04x(from types.Result, toVersion string) (types.Result, error) { | ||||
| 	fromResult := from.(*Result) | ||||
| 	toResult := &types040.Result{ | ||||
| 		CNIVersion: toVersion, | ||||
| 		DNS:        *fromResult.DNS.Copy(), | ||||
| 		Routes:     []*types.Route{}, | ||||
| 	} | ||||
| 	for _, fromIntf := range fromResult.Interfaces { | ||||
| 		toResult.Interfaces = append(toResult.Interfaces, convertInterfaceTo040(fromIntf)) | ||||
| 	} | ||||
| 	for _, fromIPC := range fromResult.IPs { | ||||
| 		toResult.IPs = append(toResult.IPs, convertIPConfigTo040(fromIPC)) | ||||
| 	} | ||||
| 	for _, fromRoute := range fromResult.Routes { | ||||
| 		toResult.Routes = append(toResult.Routes, fromRoute.Copy()) | ||||
| 	} | ||||
| 	return toResult, nil | ||||
| } | ||||
|  | ||||
| func convertTo02x(from types.Result, toVersion string) (types.Result, error) { | ||||
| 	// First convert to 0.4.0 | ||||
| 	result040, err := convertTo04x(from, "0.4.0") | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	result02x, err := convert.Convert(result040, toVersion) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	return result02x, nil | ||||
| } | ||||
|  | ||||
| func (r *Result) Version() string { | ||||
| 	return r.CNIVersion | ||||
| } | ||||
|  | ||||
| func (r *Result) GetAsVersion(version string) (types.Result, error) { | ||||
| 	// If the creator of the result did not set the CNIVersion, assume it | ||||
| 	// should be the highest spec version implemented by this Result | ||||
| 	if r.CNIVersion == "" { | ||||
| 		r.CNIVersion = ImplementedSpecVersion | ||||
| 	} | ||||
| 	return convert.Convert(r, version) | ||||
| } | ||||
|  | ||||
| func (r *Result) Print() error { | ||||
| 	return r.PrintTo(os.Stdout) | ||||
| } | ||||
|  | ||||
| func (r *Result) PrintTo(writer io.Writer) error { | ||||
| 	data, err := json.MarshalIndent(r, "", "    ") | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	_, err = writer.Write(data) | ||||
| 	return err | ||||
| } | ||||
|  | ||||
| // Interface contains values about the created interfaces | ||||
| type Interface struct { | ||||
| 	Name    string `json:"name"` | ||||
| 	Mac     string `json:"mac,omitempty"` | ||||
| 	Sandbox string `json:"sandbox,omitempty"` | ||||
| } | ||||
|  | ||||
| func (i *Interface) String() string { | ||||
| 	return fmt.Sprintf("%+v", *i) | ||||
| } | ||||
|  | ||||
| func (i *Interface) Copy() *Interface { | ||||
| 	if i == nil { | ||||
| 		return nil | ||||
| 	} | ||||
| 	newIntf := *i | ||||
| 	return &newIntf | ||||
| } | ||||
|  | ||||
| // Int returns a pointer to the int value passed in.  Used to | ||||
| // set the IPConfig.Interface field. | ||||
| func Int(v int) *int { | ||||
| 	return &v | ||||
| } | ||||
|  | ||||
| // IPConfig contains values necessary to configure an IP address on an interface | ||||
| type IPConfig struct { | ||||
| 	// Index into Result structs Interfaces list | ||||
| 	Interface *int | ||||
| 	Address   net.IPNet | ||||
| 	Gateway   net.IP | ||||
| } | ||||
|  | ||||
| func (i *IPConfig) String() string { | ||||
| 	return fmt.Sprintf("%+v", *i) | ||||
| } | ||||
|  | ||||
| func (i *IPConfig) Copy() *IPConfig { | ||||
| 	if i == nil { | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| 	ipc := &IPConfig{ | ||||
| 		Address: i.Address, | ||||
| 		Gateway: i.Gateway, | ||||
| 	} | ||||
| 	if i.Interface != nil { | ||||
| 		intf := *i.Interface | ||||
| 		ipc.Interface = &intf | ||||
| 	} | ||||
| 	return ipc | ||||
| } | ||||
|  | ||||
| // JSON (un)marshallable types | ||||
| type ipConfig struct { | ||||
| 	Interface *int        `json:"interface,omitempty"` | ||||
| 	Address   types.IPNet `json:"address"` | ||||
| 	Gateway   net.IP      `json:"gateway,omitempty"` | ||||
| } | ||||
|  | ||||
| func (c *IPConfig) MarshalJSON() ([]byte, error) { | ||||
| 	ipc := ipConfig{ | ||||
| 		Interface: c.Interface, | ||||
| 		Address:   types.IPNet(c.Address), | ||||
| 		Gateway:   c.Gateway, | ||||
| 	} | ||||
|  | ||||
| 	return json.Marshal(ipc) | ||||
| } | ||||
|  | ||||
| func (c *IPConfig) UnmarshalJSON(data []byte) error { | ||||
| 	ipc := ipConfig{} | ||||
| 	if err := json.Unmarshal(data, &ipc); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	c.Interface = ipc.Interface | ||||
| 	c.Address = net.IPNet(ipc.Address) | ||||
| 	c.Gateway = ipc.Gateway | ||||
| 	return nil | ||||
| } | ||||
							
								
								
									
										18
									
								
								vendor/github.com/containernetworking/cni/pkg/types/args.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										18
									
								
								vendor/github.com/containernetworking/cni/pkg/types/args.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -91,16 +91,26 @@ func LoadArgs(args string, container interface{}) error { | ||||
| 			unknownArgs = append(unknownArgs, pair) | ||||
| 			continue | ||||
| 		} | ||||
| 		keyFieldIface := keyField.Addr().Interface() | ||||
| 		u, ok := keyFieldIface.(encoding.TextUnmarshaler) | ||||
|  | ||||
| 		var keyFieldInterface interface{} | ||||
| 		switch { | ||||
| 		case keyField.Kind() == reflect.Ptr: | ||||
| 			keyField.Set(reflect.New(keyField.Type().Elem())) | ||||
| 			keyFieldInterface = keyField.Interface() | ||||
| 		case keyField.CanAddr() && keyField.Addr().CanInterface(): | ||||
| 			keyFieldInterface = keyField.Addr().Interface() | ||||
| 		default: | ||||
| 			return UnmarshalableArgsError{fmt.Errorf("field '%s' has no valid interface", keyString)} | ||||
| 		} | ||||
| 		u, ok := keyFieldInterface.(encoding.TextUnmarshaler) | ||||
| 		if !ok { | ||||
| 			return UnmarshalableArgsError{fmt.Errorf( | ||||
| 				"ARGS: cannot unmarshal into field '%s' - type '%s' does not implement encoding.TextUnmarshaler", | ||||
| 				keyString, reflect.TypeOf(keyFieldIface))} | ||||
| 				keyString, reflect.TypeOf(keyFieldInterface))} | ||||
| 		} | ||||
| 		err := u.UnmarshalText([]byte(valueString)) | ||||
| 		if err != nil { | ||||
| 			return fmt.Errorf("ARGS: error parsing value of pair %q: %v)", pair, err) | ||||
| 			return fmt.Errorf("ARGS: error parsing value of pair %q: %w", pair, err) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
|   | ||||
							
								
								
									
										56
									
								
								vendor/github.com/containernetworking/cni/pkg/types/create/create.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								vendor/github.com/containernetworking/cni/pkg/types/create/create.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,56 @@ | ||||
| // Copyright 2016 CNI authors | ||||
| // | ||||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| // you may not use this file except in compliance with the License. | ||||
| // You may obtain a copy of the License at | ||||
| // | ||||
| //     http://www.apache.org/licenses/LICENSE-2.0 | ||||
| // | ||||
| // Unless required by applicable law or agreed to in writing, software | ||||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
|  | ||||
| package create | ||||
|  | ||||
| import ( | ||||
| 	"encoding/json" | ||||
| 	"fmt" | ||||
|  | ||||
| 	"github.com/containernetworking/cni/pkg/types" | ||||
| 	convert "github.com/containernetworking/cni/pkg/types/internal" | ||||
| ) | ||||
|  | ||||
| // DecodeVersion returns the CNI version from CNI configuration or result JSON, | ||||
| // or an error if the operation could not be performed. | ||||
| func DecodeVersion(jsonBytes []byte) (string, error) { | ||||
| 	var conf struct { | ||||
| 		CNIVersion string `json:"cniVersion"` | ||||
| 	} | ||||
| 	err := json.Unmarshal(jsonBytes, &conf) | ||||
| 	if err != nil { | ||||
| 		return "", fmt.Errorf("decoding version from network config: %w", err) | ||||
| 	} | ||||
| 	if conf.CNIVersion == "" { | ||||
| 		return "0.1.0", nil | ||||
| 	} | ||||
| 	return conf.CNIVersion, nil | ||||
| } | ||||
|  | ||||
| // Create creates a CNI Result using the given JSON with the expected | ||||
| // version, or an error if the creation could not be performed | ||||
| func Create(version string, bytes []byte) (types.Result, error) { | ||||
| 	return convert.Create(version, bytes) | ||||
| } | ||||
|  | ||||
| // CreateFromBytes creates a CNI Result from the given JSON, automatically | ||||
| // detecting the CNI spec version of the result. An error is returned if the | ||||
| // operation could not be performed. | ||||
| func CreateFromBytes(bytes []byte) (types.Result, error) { | ||||
| 	version, err := DecodeVersion(bytes) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	return convert.Create(version, bytes) | ||||
| } | ||||
							
								
								
									
										276
									
								
								vendor/github.com/containernetworking/cni/pkg/types/current/types.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										276
									
								
								vendor/github.com/containernetworking/cni/pkg/types/current/types.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -1,276 +0,0 @@ | ||||
| // Copyright 2016 CNI authors | ||||
| // | ||||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| // you may not use this file except in compliance with the License. | ||||
| // You may obtain a copy of the License at | ||||
| // | ||||
| //     http://www.apache.org/licenses/LICENSE-2.0 | ||||
| // | ||||
| // Unless required by applicable law or agreed to in writing, software | ||||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
|  | ||||
| package current | ||||
|  | ||||
| import ( | ||||
| 	"encoding/json" | ||||
| 	"fmt" | ||||
| 	"io" | ||||
| 	"net" | ||||
| 	"os" | ||||
|  | ||||
| 	"github.com/containernetworking/cni/pkg/types" | ||||
| 	"github.com/containernetworking/cni/pkg/types/020" | ||||
| ) | ||||
|  | ||||
| const ImplementedSpecVersion string = "0.4.0" | ||||
|  | ||||
| var SupportedVersions = []string{"0.3.0", "0.3.1", ImplementedSpecVersion} | ||||
|  | ||||
| func NewResult(data []byte) (types.Result, error) { | ||||
| 	result := &Result{} | ||||
| 	if err := json.Unmarshal(data, result); err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	return result, nil | ||||
| } | ||||
|  | ||||
| func GetResult(r types.Result) (*Result, error) { | ||||
| 	resultCurrent, err := r.GetAsVersion(ImplementedSpecVersion) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	result, ok := resultCurrent.(*Result) | ||||
| 	if !ok { | ||||
| 		return nil, fmt.Errorf("failed to convert result") | ||||
| 	} | ||||
| 	return result, nil | ||||
| } | ||||
|  | ||||
| var resultConverters = []struct { | ||||
| 	versions []string | ||||
| 	convert  func(types.Result) (*Result, error) | ||||
| }{ | ||||
| 	{types020.SupportedVersions, convertFrom020}, | ||||
| 	{SupportedVersions, convertFrom030}, | ||||
| } | ||||
|  | ||||
| func convertFrom020(result types.Result) (*Result, error) { | ||||
| 	oldResult, err := types020.GetResult(result) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	newResult := &Result{ | ||||
| 		CNIVersion: ImplementedSpecVersion, | ||||
| 		DNS:        oldResult.DNS, | ||||
| 		Routes:     []*types.Route{}, | ||||
| 	} | ||||
|  | ||||
| 	if oldResult.IP4 != nil { | ||||
| 		newResult.IPs = append(newResult.IPs, &IPConfig{ | ||||
| 			Version: "4", | ||||
| 			Address: oldResult.IP4.IP, | ||||
| 			Gateway: oldResult.IP4.Gateway, | ||||
| 		}) | ||||
| 		for _, route := range oldResult.IP4.Routes { | ||||
| 			newResult.Routes = append(newResult.Routes, &types.Route{ | ||||
| 				Dst: route.Dst, | ||||
| 				GW:  route.GW, | ||||
| 			}) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	if oldResult.IP6 != nil { | ||||
| 		newResult.IPs = append(newResult.IPs, &IPConfig{ | ||||
| 			Version: "6", | ||||
| 			Address: oldResult.IP6.IP, | ||||
| 			Gateway: oldResult.IP6.Gateway, | ||||
| 		}) | ||||
| 		for _, route := range oldResult.IP6.Routes { | ||||
| 			newResult.Routes = append(newResult.Routes, &types.Route{ | ||||
| 				Dst: route.Dst, | ||||
| 				GW:  route.GW, | ||||
| 			}) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return newResult, nil | ||||
| } | ||||
|  | ||||
| func convertFrom030(result types.Result) (*Result, error) { | ||||
| 	newResult, ok := result.(*Result) | ||||
| 	if !ok { | ||||
| 		return nil, fmt.Errorf("failed to convert result") | ||||
| 	} | ||||
| 	newResult.CNIVersion = ImplementedSpecVersion | ||||
| 	return newResult, nil | ||||
| } | ||||
|  | ||||
| func NewResultFromResult(result types.Result) (*Result, error) { | ||||
| 	version := result.Version() | ||||
| 	for _, converter := range resultConverters { | ||||
| 		for _, supportedVersion := range converter.versions { | ||||
| 			if version == supportedVersion { | ||||
| 				return converter.convert(result) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	return nil, fmt.Errorf("unsupported CNI result22 version %q", version) | ||||
| } | ||||
|  | ||||
| // Result is what gets returned from the plugin (via stdout) to the caller | ||||
| type Result struct { | ||||
| 	CNIVersion string         `json:"cniVersion,omitempty"` | ||||
| 	Interfaces []*Interface   `json:"interfaces,omitempty"` | ||||
| 	IPs        []*IPConfig    `json:"ips,omitempty"` | ||||
| 	Routes     []*types.Route `json:"routes,omitempty"` | ||||
| 	DNS        types.DNS      `json:"dns,omitempty"` | ||||
| } | ||||
|  | ||||
| // Convert to the older 0.2.0 CNI spec Result type | ||||
| func (r *Result) convertTo020() (*types020.Result, error) { | ||||
| 	oldResult := &types020.Result{ | ||||
| 		CNIVersion: types020.ImplementedSpecVersion, | ||||
| 		DNS:        r.DNS, | ||||
| 	} | ||||
|  | ||||
| 	for _, ip := range r.IPs { | ||||
| 		// Only convert the first IP address of each version as 0.2.0 | ||||
| 		// and earlier cannot handle multiple IP addresses | ||||
| 		if ip.Version == "4" && oldResult.IP4 == nil { | ||||
| 			oldResult.IP4 = &types020.IPConfig{ | ||||
| 				IP:      ip.Address, | ||||
| 				Gateway: ip.Gateway, | ||||
| 			} | ||||
| 		} else if ip.Version == "6" && oldResult.IP6 == nil { | ||||
| 			oldResult.IP6 = &types020.IPConfig{ | ||||
| 				IP:      ip.Address, | ||||
| 				Gateway: ip.Gateway, | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		if oldResult.IP4 != nil && oldResult.IP6 != nil { | ||||
| 			break | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	for _, route := range r.Routes { | ||||
| 		is4 := route.Dst.IP.To4() != nil | ||||
| 		if is4 && oldResult.IP4 != nil { | ||||
| 			oldResult.IP4.Routes = append(oldResult.IP4.Routes, types.Route{ | ||||
| 				Dst: route.Dst, | ||||
| 				GW:  route.GW, | ||||
| 			}) | ||||
| 		} else if !is4 && oldResult.IP6 != nil { | ||||
| 			oldResult.IP6.Routes = append(oldResult.IP6.Routes, types.Route{ | ||||
| 				Dst: route.Dst, | ||||
| 				GW:  route.GW, | ||||
| 			}) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	if oldResult.IP4 == nil && oldResult.IP6 == nil { | ||||
| 		return nil, fmt.Errorf("cannot convert: no valid IP addresses") | ||||
| 	} | ||||
|  | ||||
| 	return oldResult, nil | ||||
| } | ||||
|  | ||||
| func (r *Result) Version() string { | ||||
| 	return ImplementedSpecVersion | ||||
| } | ||||
|  | ||||
| func (r *Result) GetAsVersion(version string) (types.Result, error) { | ||||
| 	switch version { | ||||
| 	case "0.3.0", "0.3.1", ImplementedSpecVersion: | ||||
| 		r.CNIVersion = version | ||||
| 		return r, nil | ||||
| 	case types020.SupportedVersions[0], types020.SupportedVersions[1], types020.SupportedVersions[2]: | ||||
| 		return r.convertTo020() | ||||
| 	} | ||||
| 	return nil, fmt.Errorf("cannot convert version 0.3.x to %q", version) | ||||
| } | ||||
|  | ||||
| func (r *Result) Print() error { | ||||
| 	return r.PrintTo(os.Stdout) | ||||
| } | ||||
|  | ||||
| func (r *Result) PrintTo(writer io.Writer) error { | ||||
| 	data, err := json.MarshalIndent(r, "", "    ") | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	_, err = writer.Write(data) | ||||
| 	return err | ||||
| } | ||||
|  | ||||
| // Convert this old version result to the current CNI version result | ||||
| func (r *Result) Convert() (*Result, error) { | ||||
| 	return r, nil | ||||
| } | ||||
|  | ||||
| // Interface contains values about the created interfaces | ||||
| type Interface struct { | ||||
| 	Name    string `json:"name"` | ||||
| 	Mac     string `json:"mac,omitempty"` | ||||
| 	Sandbox string `json:"sandbox,omitempty"` | ||||
| } | ||||
|  | ||||
| func (i *Interface) String() string { | ||||
| 	return fmt.Sprintf("%+v", *i) | ||||
| } | ||||
|  | ||||
| // Int returns a pointer to the int value passed in.  Used to | ||||
| // set the IPConfig.Interface field. | ||||
| func Int(v int) *int { | ||||
| 	return &v | ||||
| } | ||||
|  | ||||
| // IPConfig contains values necessary to configure an IP address on an interface | ||||
| type IPConfig struct { | ||||
| 	// IP version, either "4" or "6" | ||||
| 	Version string | ||||
| 	// Index into Result structs Interfaces list | ||||
| 	Interface *int | ||||
| 	Address   net.IPNet | ||||
| 	Gateway   net.IP | ||||
| } | ||||
|  | ||||
| func (i *IPConfig) String() string { | ||||
| 	return fmt.Sprintf("%+v", *i) | ||||
| } | ||||
|  | ||||
| // JSON (un)marshallable types | ||||
| type ipConfig struct { | ||||
| 	Version   string      `json:"version"` | ||||
| 	Interface *int        `json:"interface,omitempty"` | ||||
| 	Address   types.IPNet `json:"address"` | ||||
| 	Gateway   net.IP      `json:"gateway,omitempty"` | ||||
| } | ||||
|  | ||||
| func (c *IPConfig) MarshalJSON() ([]byte, error) { | ||||
| 	ipc := ipConfig{ | ||||
| 		Version:   c.Version, | ||||
| 		Interface: c.Interface, | ||||
| 		Address:   types.IPNet(c.Address), | ||||
| 		Gateway:   c.Gateway, | ||||
| 	} | ||||
|  | ||||
| 	return json.Marshal(ipc) | ||||
| } | ||||
|  | ||||
| func (c *IPConfig) UnmarshalJSON(data []byte) error { | ||||
| 	ipc := ipConfig{} | ||||
| 	if err := json.Unmarshal(data, &ipc); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	c.Version = ipc.Version | ||||
| 	c.Interface = ipc.Interface | ||||
| 	c.Address = net.IPNet(ipc.Address) | ||||
| 	c.Gateway = ipc.Gateway | ||||
| 	return nil | ||||
| } | ||||
							
								
								
									
										92
									
								
								vendor/github.com/containernetworking/cni/pkg/types/internal/convert.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										92
									
								
								vendor/github.com/containernetworking/cni/pkg/types/internal/convert.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,92 @@ | ||||
| // Copyright 2016 CNI authors | ||||
| // | ||||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| // you may not use this file except in compliance with the License. | ||||
| // You may obtain a copy of the License at | ||||
| // | ||||
| //     http://www.apache.org/licenses/LICENSE-2.0 | ||||
| // | ||||
| // Unless required by applicable law or agreed to in writing, software | ||||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
|  | ||||
| package convert | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
|  | ||||
| 	"github.com/containernetworking/cni/pkg/types" | ||||
| ) | ||||
|  | ||||
| // ConvertFn should convert from the given arbitrary Result type into a | ||||
| // Result implementing CNI specification version passed in toVersion. | ||||
| // The function is guaranteed to be passed a Result type matching the | ||||
| // fromVersion it was registered with, and is guaranteed to be | ||||
| // passed a toVersion matching one of the toVersions it was registered with. | ||||
| type ConvertFn func(from types.Result, toVersion string) (types.Result, error) | ||||
|  | ||||
| type converter struct { | ||||
| 	// fromVersion is the CNI Result spec version that convertFn accepts | ||||
| 	fromVersion string | ||||
| 	// toVersions is a list of versions that convertFn can convert to | ||||
| 	toVersions []string | ||||
| 	convertFn  ConvertFn | ||||
| } | ||||
|  | ||||
| var converters []*converter | ||||
|  | ||||
| func findConverter(fromVersion, toVersion string) *converter { | ||||
| 	for _, c := range converters { | ||||
| 		if c.fromVersion == fromVersion { | ||||
| 			for _, v := range c.toVersions { | ||||
| 				if v == toVersion { | ||||
| 					return c | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // Convert converts a CNI Result to the requested CNI specification version, | ||||
| // or returns an error if the conversion could not be performed or failed | ||||
| func Convert(from types.Result, toVersion string) (types.Result, error) { | ||||
| 	if toVersion == "" { | ||||
| 		toVersion = "0.1.0" | ||||
| 	} | ||||
|  | ||||
| 	fromVersion := from.Version() | ||||
|  | ||||
| 	// Shortcut for same version | ||||
| 	if fromVersion == toVersion { | ||||
| 		return from, nil | ||||
| 	} | ||||
|  | ||||
| 	// Otherwise find the right converter | ||||
| 	c := findConverter(fromVersion, toVersion) | ||||
| 	if c == nil { | ||||
| 		return nil, fmt.Errorf("no converter for CNI result version %s to %s", | ||||
| 			fromVersion, toVersion) | ||||
| 	} | ||||
| 	return c.convertFn(from, toVersion) | ||||
| } | ||||
|  | ||||
| // RegisterConverter registers a CNI Result converter. SHOULD NOT BE CALLED | ||||
| // EXCEPT FROM CNI ITSELF. | ||||
| func RegisterConverter(fromVersion string, toVersions []string, convertFn ConvertFn) { | ||||
| 	// Make sure there is no converter already registered for these | ||||
| 	// from and to versions | ||||
| 	for _, v := range toVersions { | ||||
| 		if findConverter(fromVersion, v) != nil { | ||||
| 			panic(fmt.Sprintf("converter already registered for %s to %s", | ||||
| 				fromVersion, v)) | ||||
| 		} | ||||
| 	} | ||||
| 	converters = append(converters, &converter{ | ||||
| 		fromVersion: fromVersion, | ||||
| 		toVersions:  toVersions, | ||||
| 		convertFn:   convertFn, | ||||
| 	}) | ||||
| } | ||||
							
								
								
									
										66
									
								
								vendor/github.com/containernetworking/cni/pkg/types/internal/create.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								vendor/github.com/containernetworking/cni/pkg/types/internal/create.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,66 @@ | ||||
| // Copyright 2016 CNI authors | ||||
| // | ||||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| // you may not use this file except in compliance with the License. | ||||
| // You may obtain a copy of the License at | ||||
| // | ||||
| //     http://www.apache.org/licenses/LICENSE-2.0 | ||||
| // | ||||
| // Unless required by applicable law or agreed to in writing, software | ||||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
|  | ||||
| package convert | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
|  | ||||
| 	"github.com/containernetworking/cni/pkg/types" | ||||
| ) | ||||
|  | ||||
| type ResultFactoryFunc func([]byte) (types.Result, error) | ||||
|  | ||||
| type creator struct { | ||||
| 	// CNI Result spec versions that createFn can create a Result for | ||||
| 	versions []string | ||||
| 	createFn ResultFactoryFunc | ||||
| } | ||||
|  | ||||
| var creators []*creator | ||||
|  | ||||
| func findCreator(version string) *creator { | ||||
| 	for _, c := range creators { | ||||
| 		for _, v := range c.versions { | ||||
| 			if v == version { | ||||
| 				return c | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // Create creates a CNI Result using the given JSON, or an error if the creation | ||||
| // could not be performed | ||||
| func Create(version string, bytes []byte) (types.Result, error) { | ||||
| 	if c := findCreator(version); c != nil { | ||||
| 		return c.createFn(bytes) | ||||
| 	} | ||||
| 	return nil, fmt.Errorf("unsupported CNI result version %q", version) | ||||
| } | ||||
|  | ||||
| // RegisterCreator registers a CNI Result creator. SHOULD NOT BE CALLED | ||||
| // EXCEPT FROM CNI ITSELF. | ||||
| func RegisterCreator(versions []string, createFn ResultFactoryFunc) { | ||||
| 	// Make sure there is no creator already registered for these versions | ||||
| 	for _, v := range versions { | ||||
| 		if findCreator(v) != nil { | ||||
| 			panic(fmt.Sprintf("creator already registered for %s", v)) | ||||
| 		} | ||||
| 	} | ||||
| 	creators = append(creators, &creator{ | ||||
| 		versions: versions, | ||||
| 		createFn: createFn, | ||||
| 	}) | ||||
| } | ||||
							
								
								
									
										31
									
								
								vendor/github.com/containernetworking/cni/pkg/types/types.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										31
									
								
								vendor/github.com/containernetworking/cni/pkg/types/types.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -83,8 +83,6 @@ type NetConfList struct { | ||||
| 	Plugins      []*NetConf `json:"plugins,omitempty"` | ||||
| } | ||||
|  | ||||
| type ResultFactoryFunc func([]byte) (Result, error) | ||||
|  | ||||
| // Result is an interface that provides the result of plugin execution | ||||
| type Result interface { | ||||
| 	// The highest CNI specification result version the result supports | ||||
| @@ -118,6 +116,24 @@ type DNS struct { | ||||
| 	Options     []string `json:"options,omitempty"` | ||||
| } | ||||
|  | ||||
| func (d *DNS) Copy() *DNS { | ||||
| 	if d == nil { | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| 	to := &DNS{Domain: d.Domain} | ||||
| 	for _, ns := range d.Nameservers { | ||||
| 		to.Nameservers = append(to.Nameservers, ns) | ||||
| 	} | ||||
| 	for _, s := range d.Search { | ||||
| 		to.Search = append(to.Search, s) | ||||
| 	} | ||||
| 	for _, o := range d.Options { | ||||
| 		to.Options = append(to.Options, o) | ||||
| 	} | ||||
| 	return to | ||||
| } | ||||
|  | ||||
| type Route struct { | ||||
| 	Dst net.IPNet | ||||
| 	GW  net.IP | ||||
| @@ -127,6 +143,17 @@ func (r *Route) String() string { | ||||
| 	return fmt.Sprintf("%+v", *r) | ||||
| } | ||||
|  | ||||
| func (r *Route) Copy() *Route { | ||||
| 	if r == nil { | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| 	return &Route{ | ||||
| 		Dst: r.Dst, | ||||
| 		GW:  r.GW, | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // Well known error codes | ||||
| // see https://github.com/containernetworking/cni/blob/master/SPEC.md#well-known-error-codes | ||||
| const ( | ||||
|   | ||||
							
								
								
									
										15
									
								
								vendor/github.com/containernetworking/cni/pkg/version/conf.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										15
									
								
								vendor/github.com/containernetworking/cni/pkg/version/conf.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -15,23 +15,12 @@ | ||||
| package version | ||||
|  | ||||
| import ( | ||||
| 	"encoding/json" | ||||
| 	"fmt" | ||||
| 	"github.com/containernetworking/cni/pkg/types/create" | ||||
| ) | ||||
|  | ||||
| // ConfigDecoder can decode the CNI version available in network config data | ||||
| type ConfigDecoder struct{} | ||||
|  | ||||
| func (*ConfigDecoder) Decode(jsonBytes []byte) (string, error) { | ||||
| 	var conf struct { | ||||
| 		CNIVersion string `json:"cniVersion"` | ||||
| 	} | ||||
| 	err := json.Unmarshal(jsonBytes, &conf) | ||||
| 	if err != nil { | ||||
| 		return "", fmt.Errorf("decoding version from network config: %s", err) | ||||
| 	} | ||||
| 	if conf.CNIVersion == "" { | ||||
| 		return "0.1.0", nil | ||||
| 	} | ||||
| 	return conf.CNIVersion, nil | ||||
| 	return create.DecodeVersion(jsonBytes) | ||||
| } | ||||
|   | ||||
							
								
								
									
										8
									
								
								vendor/github.com/containernetworking/cni/pkg/version/plugin.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										8
									
								
								vendor/github.com/containernetworking/cni/pkg/version/plugin.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -68,7 +68,7 @@ func (*PluginDecoder) Decode(jsonBytes []byte) (PluginInfo, error) { | ||||
| 	var info pluginInfo | ||||
| 	err := json.Unmarshal(jsonBytes, &info) | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("decoding version info: %s", err) | ||||
| 		return nil, fmt.Errorf("decoding version info: %w", err) | ||||
| 	} | ||||
| 	if info.CNIVersion_ == "" { | ||||
| 		return nil, fmt.Errorf("decoding version info: missing field cniVersion") | ||||
| @@ -97,20 +97,20 @@ func ParseVersion(version string) (int, int, int, error) { | ||||
|  | ||||
| 	major, err := strconv.Atoi(parts[0]) | ||||
| 	if err != nil { | ||||
| 		return -1, -1, -1, fmt.Errorf("failed to convert major version part %q: %v", parts[0], err) | ||||
| 		return -1, -1, -1, fmt.Errorf("failed to convert major version part %q: %w", parts[0], err) | ||||
| 	} | ||||
|  | ||||
| 	if len(parts) >= 2 { | ||||
| 		minor, err = strconv.Atoi(parts[1]) | ||||
| 		if err != nil { | ||||
| 			return -1, -1, -1, fmt.Errorf("failed to convert minor version part %q: %v", parts[1], err) | ||||
| 			return -1, -1, -1, fmt.Errorf("failed to convert minor version part %q: %w", parts[1], err) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	if len(parts) >= 3 { | ||||
| 		micro, err = strconv.Atoi(parts[2]) | ||||
| 		if err != nil { | ||||
| 			return -1, -1, -1, fmt.Errorf("failed to convert micro version part %q: %v", parts[2], err) | ||||
| 			return -1, -1, -1, fmt.Errorf("failed to convert micro version part %q: %w", parts[2], err) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
|   | ||||
							
								
								
									
										52
									
								
								vendor/github.com/containernetworking/cni/pkg/version/version.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										52
									
								
								vendor/github.com/containernetworking/cni/pkg/version/version.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -19,13 +19,13 @@ import ( | ||||
| 	"fmt" | ||||
|  | ||||
| 	"github.com/containernetworking/cni/pkg/types" | ||||
| 	"github.com/containernetworking/cni/pkg/types/020" | ||||
| 	"github.com/containernetworking/cni/pkg/types/current" | ||||
| 	types100 "github.com/containernetworking/cni/pkg/types/100" | ||||
| 	"github.com/containernetworking/cni/pkg/types/create" | ||||
| ) | ||||
|  | ||||
| // Current reports the version of the CNI spec implemented by this library | ||||
| func Current() string { | ||||
| 	return "0.4.0" | ||||
| 	return types100.ImplementedSpecVersion | ||||
| } | ||||
|  | ||||
| // Legacy PluginInfo describes a plugin that is backwards compatible with the | ||||
| @@ -36,29 +36,28 @@ func Current() string { | ||||
| // Any future CNI spec versions which meet this definition should be added to | ||||
| // this list. | ||||
| var Legacy = PluginSupports("0.1.0", "0.2.0") | ||||
| var All = PluginSupports("0.1.0", "0.2.0", "0.3.0", "0.3.1", "0.4.0") | ||||
| var All = PluginSupports("0.1.0", "0.2.0", "0.3.0", "0.3.1", "0.4.0", "1.0.0") | ||||
|  | ||||
| var resultFactories = []struct { | ||||
| 	supportedVersions []string | ||||
| 	newResult         types.ResultFactoryFunc | ||||
| }{ | ||||
| 	{current.SupportedVersions, current.NewResult}, | ||||
| 	{types020.SupportedVersions, types020.NewResult}, | ||||
| // VersionsFrom returns a list of versions starting from min, inclusive | ||||
| func VersionsStartingFrom(min string) PluginInfo { | ||||
| 	out := []string{} | ||||
| 	// cheat, just assume ordered | ||||
| 	ok := false | ||||
| 	for _, v := range All.SupportedVersions() { | ||||
| 		if !ok && v == min { | ||||
| 			ok = true | ||||
| 		} | ||||
| 		if ok { | ||||
| 			out = append(out, v) | ||||
| 		} | ||||
| 	} | ||||
| 	return PluginSupports(out...) | ||||
| } | ||||
|  | ||||
| // Finds a Result object matching the requested version (if any) and asks | ||||
| // that object to parse the plugin result, returning an error if parsing failed. | ||||
| func NewResult(version string, resultBytes []byte) (types.Result, error) { | ||||
| 	reconciler := &Reconciler{} | ||||
| 	for _, resultFactory := range resultFactories { | ||||
| 		err := reconciler.CheckRaw(version, resultFactory.supportedVersions) | ||||
| 		if err == nil { | ||||
| 			// Result supports this version | ||||
| 			return resultFactory.newResult(resultBytes) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return nil, fmt.Errorf("unsupported CNI result version %q", version) | ||||
| 	return create.Create(version, resultBytes) | ||||
| } | ||||
|  | ||||
| // ParsePrevResult parses a prevResult in a NetConf structure and sets | ||||
| @@ -68,15 +67,22 @@ func ParsePrevResult(conf *types.NetConf) error { | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| 	// Prior to 1.0.0, Result types may not marshal a CNIVersion. Since the | ||||
| 	// result version must match the config version, if the Result's version | ||||
| 	// is empty, inject the config version. | ||||
| 	if ver, ok := conf.RawPrevResult["CNIVersion"]; !ok || ver == "" { | ||||
| 		conf.RawPrevResult["CNIVersion"] = conf.CNIVersion | ||||
| 	} | ||||
|  | ||||
| 	resultBytes, err := json.Marshal(conf.RawPrevResult) | ||||
| 	if err != nil { | ||||
| 		return fmt.Errorf("could not serialize prevResult: %v", err) | ||||
| 		return fmt.Errorf("could not serialize prevResult: %w", err) | ||||
| 	} | ||||
|  | ||||
| 	conf.RawPrevResult = nil | ||||
| 	conf.PrevResult, err = NewResult(conf.CNIVersion, resultBytes) | ||||
| 	conf.PrevResult, err = create.Create(conf.CNIVersion, resultBytes) | ||||
| 	if err != nil { | ||||
| 		return fmt.Errorf("could not parse prevResult: %v", err) | ||||
| 		return fmt.Errorf("could not parse prevResult: %w", err) | ||||
| 	} | ||||
|  | ||||
| 	return nil | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 zounengren
					zounengren