cni result: add a debug message
Signed-off-by: JulienBalestra <julien.balestra@datadoghq.com>
This commit is contained in:
		@@ -17,6 +17,7 @@ limitations under the License.
 | 
				
			|||||||
package server
 | 
					package server
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"encoding/json"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
@@ -26,7 +27,7 @@ import (
 | 
				
			|||||||
	"github.com/containerd/containerd/errdefs"
 | 
						"github.com/containerd/containerd/errdefs"
 | 
				
			||||||
	"github.com/containerd/containerd/oci"
 | 
						"github.com/containerd/containerd/oci"
 | 
				
			||||||
	"github.com/containerd/containerd/runtime/linux/runctypes"
 | 
						"github.com/containerd/containerd/runtime/linux/runctypes"
 | 
				
			||||||
	cni "github.com/containerd/go-cni"
 | 
						"github.com/containerd/go-cni"
 | 
				
			||||||
	"github.com/containerd/typeurl"
 | 
						"github.com/containerd/typeurl"
 | 
				
			||||||
	imagespec "github.com/opencontainers/image-spec/specs-go/v1"
 | 
						imagespec "github.com/opencontainers/image-spec/specs-go/v1"
 | 
				
			||||||
	runtimespec "github.com/opencontainers/runtime-spec/specs-go"
 | 
						runtimespec "github.com/opencontainers/runtime-spec/specs-go"
 | 
				
			||||||
@@ -530,7 +531,7 @@ 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, error) {
 | 
				
			||||||
	if c.netPlugin == nil {
 | 
						if c.netPlugin == nil {
 | 
				
			||||||
		return "", errors.New("cni config not intialized")
 | 
							return "", errors.New("cni config not initialized")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	labels := getPodCNILabels(id, config)
 | 
						labels := getPodCNILabels(id, config)
 | 
				
			||||||
@@ -541,6 +542,7 @@ func (c *criService) setupPod(id string, path string, config *runtime.PodSandbox
 | 
				
			|||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return "", err
 | 
							return "", err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						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), nil
 | 
				
			||||||
@@ -639,3 +641,15 @@ func (c *criService) getSandboxRuntime(config *runtime.PodSandboxConfig, runtime
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	return handler, nil
 | 
						return handler, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func logDebugCNIResult(sandboxID string, result *cni.CNIResult) {
 | 
				
			||||||
 | 
						if logrus.GetLevel() < logrus.DebugLevel {
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						cniResult, err := json.Marshal(result)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							logrus.WithError(err).Errorf("Failed to marshal CNI result for sandbox %q: %v", sandboxID, err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						logrus.Debugf("cni result for sandbox %q: %s", sandboxID, string(cniResult))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user