Skip to content

Commit 6e39d0c

Browse files
author
Mrunal Patel
authored
Merge pull request cri-o#1748 from amshinde/cni-results
cni: Add CNI result JSON as an annotation
2 parents 2c42334 + 220612d commit 6e39d0c

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

pkg/annotations/annotations.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ const (
9999

100100
// HostNetwork indicates whether the host network namespace is used or not
101101
HostNetwork = "io.kubernetes.cri-o.HostNetwork"
102+
103+
// CNIResult is the JSON string representation of the Result from CNI
104+
CNIResult = "io.kubernetes.cri-o.CNIResult"
102105
)
103106

104107
// ContainerType values

server/sandbox_network.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ import (
44
"fmt"
55
"net"
66

7+
cnitypes "github.com/containernetworking/cni/pkg/types"
78
"github.com/kubernetes-sigs/cri-o/lib/sandbox"
89
"github.com/sirupsen/logrus"
910
"k8s.io/kubernetes/pkg/kubelet/dockershim/network/hostport"
1011
)
1112

1213
// networkStart sets up the sandbox's network and returns the pod IP on success
1314
// or an error
14-
func (s *Server) networkStart(sb *sandbox.Sandbox) (podIP string, err error) {
15+
func (s *Server) networkStart(sb *sandbox.Sandbox) (podIP string, result cnitypes.Result, err error) {
1516
if sb.HostNetwork() {
16-
return s.bindAddress, nil
17+
return s.bindAddress, nil, nil
1718
}
1819

1920
// Ensure network resources are cleaned up if the plugin succeeded
@@ -25,7 +26,7 @@ func (s *Server) networkStart(sb *sandbox.Sandbox) (podIP string, err error) {
2526
}()
2627

2728
podNetwork := newPodNetwork(sb)
28-
result, err := s.netPlugin.SetUpPod(podNetwork)
29+
result, err = s.netPlugin.SetUpPod(podNetwork)
2930
if err != nil {
3031
err = fmt.Errorf("failed to create pod network sandbox %s(%s): %v", sb.Name(), sb.ID(), err)
3132
return

server/sandbox_run_linux.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"strings"
1414
"time"
1515

16+
cnitypes "github.com/containernetworking/cni/pkg/types"
1617
"github.com/containers/storage"
1718
"github.com/kubernetes-sigs/cri-o/lib/sandbox"
1819
"github.com/kubernetes-sigs/cri-o/oci"
@@ -570,11 +571,16 @@ func (s *Server) runPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
570571
sb.SetInfraContainer(container)
571572

572573
var ip string
574+
var result cnitypes.Result
575+
573576
if s.config.Config.ManageNetworkNSLifecycle {
574-
ip, err = s.networkStart(sb)
577+
ip, result, err = s.networkStart(sb)
575578
if err != nil {
576579
return nil, err
577580
}
581+
if result != nil {
582+
g.AddAnnotation(annotations.CNIResult, result.String())
583+
}
578584
defer func() {
579585
if err != nil {
580586
s.networkStop(sb)
@@ -621,7 +627,7 @@ func (s *Server) runPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
621627
s.ContainerStateToDisk(container)
622628

623629
if !s.config.Config.ManageNetworkNSLifecycle {
624-
ip, err = s.networkStart(sb)
630+
ip, _, err = s.networkStart(sb)
625631
if err != nil {
626632
return nil, err
627633
}

0 commit comments

Comments
 (0)