From f8e89f71a93d0c3394101d19687d279a09692324 Mon Sep 17 00:00:00 2001 From: Mike Brown Date: Mon, 26 Nov 2018 15:57:00 -0600 Subject: [PATCH] adds cni results to verbose pod info Signed-off-by: Mike Brown --- pkg/server/sandbox_run.go | 12 ++++++------ pkg/server/sandbox_status.go | 3 +++ pkg/store/sandbox/metadata.go | 3 +++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/pkg/server/sandbox_run.go b/pkg/server/sandbox_run.go index 468a389c5..d5aa700b3 100644 --- a/pkg/server/sandbox_run.go +++ b/pkg/server/sandbox_run.go @@ -126,7 +126,7 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox // In this case however caching the IP will add a subtle performance enhancement by avoiding // calls to network namespace of the pod to query the IP of the veth interface on every // SandboxStatus request. - sandbox.IP, err = c.setupPod(id, sandbox.NetNSPath, config) + sandbox.IP, sandbox.CNIResult, err = c.setupPod(id, sandbox.NetNSPath, config) if err != nil { return nil, errors.Wrapf(err, "failed to setup network for sandbox %q", id) } @@ -530,9 +530,9 @@ func (c *criService) unmountSandboxFiles(id string, config *runtime.PodSandboxCo } // setupPod setups up the network for a pod -func (c *criService) setupPod(id string, path string, config *runtime.PodSandboxConfig) (string, error) { +func (c *criService) setupPod(id string, path string, config *runtime.PodSandboxConfig) (string, *cni.CNIResult, error) { if c.netPlugin == nil { - return "", errors.New("cni config not initialized") + return "", nil, errors.New("cni config not initialized") } labels := getPodCNILabels(id, config) @@ -541,18 +541,18 @@ func (c *criService) setupPod(id string, path string, config *runtime.PodSandbox cni.WithLabels(labels), cni.WithCapabilityPortMap(toCNIPortMappings(config.GetPortMappings()))) if err != nil { - return "", err + return "", nil, err } logDebugCNIResult(id, result) // Check if the default interface has IP config if configs, ok := result.Interfaces[defaultIfName]; ok && len(configs.IPConfigs) > 0 { - return selectPodIP(configs.IPConfigs), nil + return selectPodIP(configs.IPConfigs), result, nil } // If it comes here then the result was invalid so destroy the pod network and return error if err := c.teardownPod(id, path, config); err != nil { logrus.WithError(err).Errorf("Failed to destroy network for sandbox %q", id) } - return "", errors.Errorf("failed to find network info for sandbox %q", id) + return "", result, errors.Errorf("failed to find network info for sandbox %q", id) } // toCNIPortMappings converts CRI port mappings to CNI. diff --git a/pkg/server/sandbox_status.go b/pkg/server/sandbox_status.go index 98a07f838..fb8f3d928 100644 --- a/pkg/server/sandbox_status.go +++ b/pkg/server/sandbox_status.go @@ -21,6 +21,7 @@ import ( "github.com/containerd/containerd" "github.com/containerd/containerd/errdefs" + cni "github.com/containerd/go-cni" runtimespec "github.com/opencontainers/runtime-spec/specs-go" "github.com/pkg/errors" "golang.org/x/net/context" @@ -117,6 +118,7 @@ type SandboxInfo struct { RuntimeOptions interface{} `json:"runtimeOptions"` Config *runtime.PodSandboxConfig `json:"config"` RuntimeSpec *runtimespec.Spec `json:"runtimeSpec"` + CNIResult *cni.CNIResult `json:"cniResult"` } // toCRISandboxInfo converts internal container object information to CRI sandbox status response info map. @@ -142,6 +144,7 @@ func toCRISandboxInfo(ctx context.Context, sandbox sandboxstore.Sandbox) (map[st RuntimeHandler: sandbox.RuntimeHandler, Status: string(processStatus), Config: sandbox.Config, + CNIResult: sandbox.CNIResult, } if si.Status == "" { diff --git a/pkg/store/sandbox/metadata.go b/pkg/store/sandbox/metadata.go index a5c803ca7..3cf46c8d8 100644 --- a/pkg/store/sandbox/metadata.go +++ b/pkg/store/sandbox/metadata.go @@ -19,6 +19,7 @@ package sandbox import ( "encoding/json" + cni "github.com/containerd/go-cni" "github.com/pkg/errors" runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2" ) @@ -56,6 +57,8 @@ type Metadata struct { IP string // RuntimeHandler is the runtime handler name of the pod. RuntimeHandler string + // CNI result + CNIResult *cni.CNIResult } // MarshalJSON encodes Metadata into bytes in json format.