"github.com/containernetworking/cni/pkg/types"
)
-const implementedSpecVersion string = "0.2.0"
+const ImplementedSpecVersion string = "0.2.0"
-var SupportedVersions = []string{"", "0.1.0", implementedSpecVersion}
+var SupportedVersions = []string{"", "0.1.0", ImplementedSpecVersion}
// Compatibility types for CNI version 0.1.0 and 0.2.0
func GetResult(r types.Result) (*Result, error) {
// We expect version 0.1.0/0.2.0 results
- result020, err := r.GetAsVersion(implementedSpecVersion)
+ result020, err := r.GetAsVersion(ImplementedSpecVersion)
if err != nil {
return nil, err
}
// Result is what gets returned from the plugin (via stdout) to the caller
type Result struct {
- IP4 *IPConfig `json:"ip4,omitempty"`
- IP6 *IPConfig `json:"ip6,omitempty"`
- DNS types.DNS `json:"dns,omitempty"`
+ CNIVersion string `json:"cniVersion,omitempty"`
+ IP4 *IPConfig `json:"ip4,omitempty"`
+ IP6 *IPConfig `json:"ip6,omitempty"`
+ DNS types.DNS `json:"dns,omitempty"`
}
func (r *Result) Version() string {
- return implementedSpecVersion
+ return ImplementedSpecVersion
}
func (r *Result) GetAsVersion(version string) (types.Result, error) {
for _, supportedVersion := range SupportedVersions {
if version == supportedVersion {
+ r.CNIVersion = version
return r, nil
}
}
// Set every field of the struct to ensure source compatibility
res := types020.Result{
+ CNIVersion: types020.ImplementedSpecVersion,
IP4: &types020.IPConfig{
IP: *ipv4,
Gateway: net.ParseIP("1.2.3.1"),
Expect(err).NotTo(HaveOccurred())
Expect(string(out)).To(Equal(`{
+ "cniVersion": "0.2.0",
"ip4": {
"ip": "1.2.3.30/24",
"gateway": "1.2.3.1",
}
newResult := &Result{
- DNS: oldResult.DNS,
- Routes: []*types.Route{},
+ CNIVersion: implementedSpecVersion,
+ DNS: oldResult.DNS,
+ Routes: []*types.Route{},
}
if oldResult.IP4 != nil {
if !ok {
return nil, fmt.Errorf("failed to convert result")
}
+ newResult.CNIVersion = implementedSpecVersion
return newResult, 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"`
// Convert to the older 0.2.0 CNI spec Result type
func (r *Result) convertTo020() (*types020.Result, error) {
oldResult := &types020.Result{
- DNS: r.DNS,
+ CNIVersion: types020.ImplementedSpecVersion,
+ DNS: r.DNS,
}
for _, ip := range r.IPs {
func (r *Result) GetAsVersion(version string) (types.Result, error) {
switch version {
case "0.3.0", implementedSpecVersion:
+ r.CNIVersion = version
return r, nil
case types020.SupportedVersions[0], types020.SupportedVersions[1], types020.SupportedVersions[2]:
return r.convertTo020()
// Set every field of the struct to ensure source compatibility
return ¤t.Result{
+ CNIVersion: "0.3.1",
Interfaces: []*current.Interface{
{
Name: "eth0",
Expect(err).NotTo(HaveOccurred())
Expect(string(out)).To(Equal(`{
+ "cniVersion": "0.3.1",
"interfaces": [
{
"name": "eth0",
Expect(err).NotTo(HaveOccurred())
Expect(string(out)).To(Equal(`{
+ "cniVersion": "0.1.0",
"ip4": {
"ip": "1.2.3.30/24",
"gateway": "1.2.3.1",