diff --git a/pkg/ocicni/ocicni.go b/pkg/ocicni/ocicni.go index c10c4452..497cedee 100644 --- a/pkg/ocicni/ocicni.go +++ b/pkg/ocicni/ocicni.go @@ -16,7 +16,7 @@ import ( "github.com/containernetworking/cni/libcni" cniinvoke "github.com/containernetworking/cni/pkg/invoke" cnitypes "github.com/containernetworking/cni/pkg/types" - cnicurrent "github.com/containernetworking/cni/pkg/types/current" + cniv1 "github.com/containernetworking/cni/pkg/types/100" cniversion "github.com/containernetworking/cni/pkg/version" "github.com/fsnotify/fsnotify" "github.com/sirupsen/logrus" @@ -739,22 +739,21 @@ func (network *cniNetwork) checkNetwork(ctx context.Context, rt *libcni.RuntimeC // result doesn't exist, create one logrus.Infof("Checking CNI network %s (config version=%v) nsManager=%v", network.name, network.config.CNIVersion, nsManager) - var cniInterface *cnicurrent.Interface - ips := []*cnicurrent.IPConfig{} + var cniInterface *cniv1.Interface + ips := []*cniv1.IPConfig{} errs := []error{} for _, version := range []string{"4", "6"} { ip, mac, err := getContainerDetails(nsManager, netns, rt.IfName, "-"+version) if err == nil { if cniInterface == nil { - cniInterface = &cnicurrent.Interface{ + cniInterface = &cniv1.Interface{ Name: rt.IfName, Mac: mac.String(), Sandbox: netns, } } - ips = append(ips, &cnicurrent.IPConfig{ - Version: version, - Interface: cnicurrent.Int(0), + ips = append(ips, &cniv1.IPConfig{ + Interface: cniv1.Int(0), Address: *ip, }) } else { @@ -765,9 +764,9 @@ func (network *cniNetwork) checkNetwork(ctx context.Context, rt *libcni.RuntimeC return nil, fmt.Errorf("neither IPv4 nor IPv6 found when retrieving network status: %v", errs) } - result = &cnicurrent.Result{ + result = &cniv1.Result{ CNIVersion: network.config.CNIVersion, - Interfaces: []*cnicurrent.Interface{cniInterface}, + Interfaces: []*cniv1.Interface{cniInterface}, IPs: ips, } diff --git a/pkg/ocicni/ocicni_test.go b/pkg/ocicni/ocicni_test.go index dce63e6d..ab047128 100644 --- a/pkg/ocicni/ocicni_test.go +++ b/pkg/ocicni/ocicni_test.go @@ -16,7 +16,7 @@ import ( "github.com/containernetworking/cni/libcni" "github.com/containernetworking/cni/pkg/types" - "github.com/containernetworking/cni/pkg/types/current" + cniv04 "github.com/containernetworking/cni/pkg/types/040" "github.com/containernetworking/cni/pkg/version" "github.com/containernetworking/plugins/pkg/ns" "github.com/containernetworking/plugins/pkg/testutils" @@ -78,7 +78,7 @@ type TestConf struct { Type string `json:"type,omitempty"` } -func (f *fakeExec) addPlugin(expectedEnv []string, expectedConf string, result *current.Result, err error) { +func (f *fakeExec) addPlugin(expectedEnv []string, expectedConf string, result types.Result, err error) { f.plugins = append(f.plugins, &fakePlugin{ expectedEnv: expectedEnv, expectedConf: expectedConf, @@ -473,18 +473,18 @@ var _ = Describe("ocicni operations", func() { Expect(err).NotTo(HaveOccurred()) fake := &fakeExec{} - expectedResult := ¤t.Result{ + expectedResult := &cniv04.Result{ CNIVersion: "0.3.1", - Interfaces: []*current.Interface{ + Interfaces: []*cniv04.Interface{ { Name: "eth0", Mac: "01:23:45:67:89:01", Sandbox: networkNS.Path(), }, }, - IPs: []*current.IPConfig{ + IPs: []*cniv04.IPConfig{ { - Interface: current.Int(0), + Interface: cniv04.Int(0), Version: "4", Address: *ensureCIDR("1.1.1.2/24"), }, @@ -505,7 +505,7 @@ var _ = Describe("ocicni operations", func() { Expect(err).NotTo(HaveOccurred()) Expect(fake.addIndex).To(Equal(len(fake.plugins))) Expect(len(results)).To(Equal(1)) - r := results[0].Result.(*current.Result) + r := results[0].Result.(*cniv04.Result) Expect(reflect.DeepEqual(r, expectedResult)).To(BeTrue()) // Make sure loopback device is up @@ -535,18 +535,18 @@ var _ = Describe("ocicni operations", func() { Expect(err).NotTo(HaveOccurred()) fake := &fakeExec{} - expectedResult1 := ¤t.Result{ + expectedResult1 := &cniv04.Result{ CNIVersion: "0.3.1", - Interfaces: []*current.Interface{ + Interfaces: []*cniv04.Interface{ { Name: "eth0", Mac: "01:23:45:67:89:01", Sandbox: networkNS.Path(), }, }, - IPs: []*current.IPConfig{ + IPs: []*cniv04.IPConfig{ { - Interface: current.Int(0), + Interface: cniv04.Int(0), Version: "4", Address: *ensureCIDR("1.1.1.2/24"), }, @@ -554,19 +554,18 @@ var _ = Describe("ocicni operations", func() { } fake.addPlugin(nil, conf1, expectedResult1, nil) - expectedResult2 := ¤t.Result{ + expectedResult2 := &cniv04.Result{ CNIVersion: "0.3.1", - Interfaces: []*current.Interface{ + Interfaces: []*cniv04.Interface{ { Name: "eth1", Mac: "01:23:45:67:89:02", Sandbox: networkNS.Path(), }, }, - IPs: []*current.IPConfig{ + IPs: []*cniv04.IPConfig{ { - Interface: current.Int(0), - Version: "4", + Interface: cniv04.Int(0), Address: *ensureCIDR("1.1.1.3/24"), }, }, @@ -590,9 +589,9 @@ var _ = Describe("ocicni operations", func() { Expect(err).NotTo(HaveOccurred()) Expect(fake.addIndex).To(Equal(len(fake.plugins))) Expect(len(results)).To(Equal(2)) - r := results[0].Result.(*current.Result) + r := results[0].Result.(*cniv04.Result) Expect(reflect.DeepEqual(r, expectedResult1)).To(BeTrue()) - r = results[1].Result.(*current.Result) + r = results[1].Result.(*cniv04.Result) Expect(reflect.DeepEqual(r, expectedResult2)).To(BeTrue()) err = ocicni.TearDownPod(podNet) @@ -612,18 +611,18 @@ var _ = Describe("ocicni operations", func() { Expect(err).NotTo(HaveOccurred()) fake := &fakeExec{} - expectedResult1 := ¤t.Result{ + expectedResult1 := &cniv04.Result{ CNIVersion: "0.4.0", - Interfaces: []*current.Interface{ + Interfaces: []*cniv04.Interface{ { Name: "eth0", Mac: "01:23:45:67:89:01", Sandbox: networkNS.Path(), }, }, - IPs: []*current.IPConfig{ + IPs: []*cniv04.IPConfig{ { - Interface: current.Int(0), + Interface: cniv04.Int(0), Version: "4", Address: *ensureCIDR("1.1.1.2/24"), }, @@ -631,18 +630,18 @@ var _ = Describe("ocicni operations", func() { } fake.addPlugin(nil, conf1, expectedResult1, nil) - expectedResult2 := ¤t.Result{ + expectedResult2 := &cniv04.Result{ CNIVersion: "0.4.0", - Interfaces: []*current.Interface{ + Interfaces: []*cniv04.Interface{ { Name: "eth1", Mac: "01:23:45:67:89:02", Sandbox: networkNS.Path(), }, }, - IPs: []*current.IPConfig{ + IPs: []*cniv04.IPConfig{ { - Interface: current.Int(0), + Interface: cniv04.Int(0), Version: "4", Address: *ensureCIDR("1.1.1.3/24"), }, @@ -667,17 +666,17 @@ var _ = Describe("ocicni operations", func() { Expect(err).NotTo(HaveOccurred()) Expect(fake.addIndex).To(Equal(len(fake.plugins))) Expect(len(results)).To(Equal(2)) - r := results[0].Result.(*current.Result) + r := results[0].Result.(*cniv04.Result) Expect(reflect.DeepEqual(r, expectedResult1)).To(BeTrue()) - r = results[1].Result.(*current.Result) + r = results[1].Result.(*cniv04.Result) Expect(reflect.DeepEqual(r, expectedResult2)).To(BeTrue()) resultsStatus, errStatus := ocicni.GetPodNetworkStatus(podNet) Expect(errStatus).NotTo(HaveOccurred()) Expect(len(resultsStatus)).To(Equal(2)) - r = resultsStatus[0].Result.(*current.Result) + r = resultsStatus[0].Result.(*cniv04.Result) Expect(reflect.DeepEqual(r, expectedResult1)).To(BeTrue()) - r = resultsStatus[1].Result.(*current.Result) + r = resultsStatus[1].Result.(*cniv04.Result) Expect(reflect.DeepEqual(r, expectedResult2)).To(BeTrue()) err = ocicni.TearDownPod(podNet) diff --git a/tools/ocicnitool/ocicnitool.go b/tools/ocicnitool/ocicnitool.go index 780faae0..eaa423fb 100644 --- a/tools/ocicnitool/ocicnitool.go +++ b/tools/ocicnitool/ocicnitool.go @@ -7,7 +7,7 @@ import ( "path/filepath" "strings" - cnicurrent "github.com/containernetworking/cni/pkg/types/current" + cniv1 "github.com/containernetworking/cni/pkg/types/040" "github.com/cri-o/ocicni/pkg/ocicni" ) @@ -25,21 +25,18 @@ const ( func printSandboxResults(results []ocicni.NetResult) { for _, r := range results { - result, _ := cnicurrent.NewResultFromResult(r.Result) + result, _ := cniv1.NewResultFromResult(r.Result) if result != nil { - result030, _ := cnicurrent.GetResult(result) - if result030 != nil { - for _, ip := range result030.IPs { - intfDetails := "" - if ip.Interface != nil && *ip.Interface >= 0 && *ip.Interface < len(result030.Interfaces) { - intf := result030.Interfaces[*ip.Interface] - // Only print container sandbox interfaces (not host ones) - if intf.Sandbox != "" { - intfDetails = fmt.Sprintf(" (%s %s)", intf.Name, intf.Mac) - } + for _, ip := range result.IPs { + intfDetails := "" + if ip.Interface != nil && *ip.Interface >= 0 && *ip.Interface < len(result.Interfaces) { + intf := result.Interfaces[*ip.Interface] + // Only print container sandbox interfaces (not host ones) + if intf.Sandbox != "" { + intfDetails = fmt.Sprintf(" (%s %s)", intf.Name, intf.Mac) } - fmt.Fprintf(os.Stdout, "IP: %s%s\n", ip.Address.String(), intfDetails) } + fmt.Fprintf(os.Stdout, "IP: %s%s\n", ip.Address.String(), intfDetails) } } }