Merge pull request #980 from mikebrow/networking-info
adds cni results to verbose pod info
This commit is contained in:
commit
1dc6ea19dc
@ -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
|
// 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
|
// calls to network namespace of the pod to query the IP of the veth interface on every
|
||||||
// SandboxStatus request.
|
// 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 {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "failed to setup network for sandbox %q", id)
|
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
|
// 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 {
|
if c.netPlugin == nil {
|
||||||
return "", errors.New("cni config not initialized")
|
return "", nil, errors.New("cni config not initialized")
|
||||||
}
|
}
|
||||||
|
|
||||||
labels := getPodCNILabels(id, config)
|
labels := getPodCNILabels(id, config)
|
||||||
@ -541,18 +541,18 @@ func (c *criService) setupPod(id string, path string, config *runtime.PodSandbox
|
|||||||
cni.WithLabels(labels),
|
cni.WithLabels(labels),
|
||||||
cni.WithCapabilityPortMap(toCNIPortMappings(config.GetPortMappings())))
|
cni.WithCapabilityPortMap(toCNIPortMappings(config.GetPortMappings())))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", nil, err
|
||||||
}
|
}
|
||||||
logDebugCNIResult(id, result)
|
logDebugCNIResult(id, result)
|
||||||
// Check if the default interface has IP config
|
// Check if the default interface has IP config
|
||||||
if configs, ok := result.Interfaces[defaultIfName]; ok && len(configs.IPConfigs) > 0 {
|
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 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 {
|
if err := c.teardownPod(id, path, config); err != nil {
|
||||||
logrus.WithError(err).Errorf("Failed to destroy network for sandbox %q", id)
|
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.
|
// toCNIPortMappings converts CRI port mappings to CNI.
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
|
|
||||||
"github.com/containerd/containerd"
|
"github.com/containerd/containerd"
|
||||||
"github.com/containerd/containerd/errdefs"
|
"github.com/containerd/containerd/errdefs"
|
||||||
|
cni "github.com/containerd/go-cni"
|
||||||
runtimespec "github.com/opencontainers/runtime-spec/specs-go"
|
runtimespec "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
@ -117,6 +118,7 @@ type SandboxInfo struct {
|
|||||||
RuntimeOptions interface{} `json:"runtimeOptions"`
|
RuntimeOptions interface{} `json:"runtimeOptions"`
|
||||||
Config *runtime.PodSandboxConfig `json:"config"`
|
Config *runtime.PodSandboxConfig `json:"config"`
|
||||||
RuntimeSpec *runtimespec.Spec `json:"runtimeSpec"`
|
RuntimeSpec *runtimespec.Spec `json:"runtimeSpec"`
|
||||||
|
CNIResult *cni.CNIResult `json:"cniResult"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// toCRISandboxInfo converts internal container object information to CRI sandbox status response info map.
|
// 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,
|
RuntimeHandler: sandbox.RuntimeHandler,
|
||||||
Status: string(processStatus),
|
Status: string(processStatus),
|
||||||
Config: sandbox.Config,
|
Config: sandbox.Config,
|
||||||
|
CNIResult: sandbox.CNIResult,
|
||||||
}
|
}
|
||||||
|
|
||||||
if si.Status == "" {
|
if si.Status == "" {
|
||||||
|
@ -19,6 +19,7 @@ package sandbox
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
|
cni "github.com/containerd/go-cni"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2"
|
runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2"
|
||||||
)
|
)
|
||||||
@ -56,6 +57,8 @@ type Metadata struct {
|
|||||||
IP string
|
IP string
|
||||||
// RuntimeHandler is the runtime handler name of the pod.
|
// RuntimeHandler is the runtime handler name of the pod.
|
||||||
RuntimeHandler string
|
RuntimeHandler string
|
||||||
|
// CNI result
|
||||||
|
CNIResult *cni.CNIResult
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarshalJSON encodes Metadata into bytes in json format.
|
// MarshalJSON encodes Metadata into bytes in json format.
|
||||||
|
Loading…
Reference in New Issue
Block a user