File 0001-cni-Add-cniVersion-to-Result.patch of Package weave

From ef8fa923030d9b6da3ca014689871b0108486e31 Mon Sep 17 00:00:00 2001
From: Fabian Vogt <fvogt@suse.de>
Date: Tue, 29 Mar 2022 15:24:49 +0200
Subject: [PATCH] cni: Add cniVersion to Result

Backport of https://github.com/containernetworking/cni/commit/27a5b994c2a55d1fceca08ec88139b61d4ad55fd
---
 .../cni/pkg/types/020/types.go                   | 16 +++++++++-------
 .../cni/pkg/types/current/types.go               | 11 ++++++++---
 2 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/vendor/github.com/containernetworking/cni/pkg/types/020/types.go b/vendor/github.com/containernetworking/cni/pkg/types/020/types.go
index 666cfe93..2833aba7 100644
--- a/vendor/github.com/containernetworking/cni/pkg/types/020/types.go
+++ b/vendor/github.com/containernetworking/cni/pkg/types/020/types.go
@@ -23,9 +23,9 @@ import (
 	"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
 
@@ -39,7 +39,7 @@ func NewResult(data []byte) (types.Result, 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 := r.GetAsVersion(ImplementedSpecVersion)
 	if err != nil {
 		return nil, err
 	}
@@ -52,18 +52,20 @@ func GetResult(r types.Result) (*Result, error) {
 
 // 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
 		}
 	}
diff --git a/vendor/github.com/containernetworking/cni/pkg/types/current/types.go b/vendor/github.com/containernetworking/cni/pkg/types/current/types.go
index b89a5d3a..26e1dd96 100644
--- a/vendor/github.com/containernetworking/cni/pkg/types/current/types.go
+++ b/vendor/github.com/containernetworking/cni/pkg/types/current/types.go
@@ -63,8 +63,9 @@ func convertFrom020(result types.Result) (*Result, error) {
 	}
 
 	newResult := &Result{
-		DNS:    oldResult.DNS,
-		Routes: []*types.Route{},
+		CNIVersion: implementedSpecVersion,
+		DNS:        oldResult.DNS,
+		Routes:     []*types.Route{},
 	}
 
 	if oldResult.IP4 != nil {
@@ -117,6 +118,7 @@ func convertFrom030(result types.Result) (*Result, error) {
 	if !ok {
 		return nil, fmt.Errorf("failed to convert result")
 	}
+	newResult.CNIVersion = implementedSpecVersion
 	return newResult, nil
 }
 
@@ -134,6 +136,7 @@ func NewResultFromResult(result types.Result) (*Result, error) {
 
 // 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"`
@@ -143,7 +146,8 @@ type Result struct {
 // 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 {
@@ -195,6 +199,7 @@ func (r *Result) Version() string {
 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()
-- 
2.34.1

openSUSE Build Service is sponsored by