From 2080744963da8bc7cd75930ea03c04d7e9c8edef Mon Sep 17 00:00:00 2001 From: Dongsu Park Date: Fri, 29 Sep 2017 16:16:38 +0200 Subject: [PATCH] server: fix panic when assigning entry to nil map When running cri-tests with cri-o, I found out that cri-o panicked immediately with the following message. Fix it by accessing to the labels map only if it's non-nil. ``` panic: assignment to entry in nil map goroutine 57 [running]: .../cri-o/server.(*Server).RunPodSandbox(0xc42048e000, 0x7efcad4cd400, 0xc42066ec90, 0xc4201703d0, 0x0, 0x0, 0x0) .../cri-o/server/sandbox_run.go:225 +0xda5 .../cri-o/vendor/k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime ._RuntimeService_RunPodSandbox_Handler(0x21793e0, 0xc42048e000, 0x7efcad4cd400, 0xc42066ec90, 0xc4204fe780, 0x0, 0x0, 0x0, 0x0, 0x0) .../cri-o/vendor/k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime/api.pb.go:3645 +0x279 .../cri-o/vendor/google.golang.org/grpc.(*Server).processUnaryRPC(0xc420 09e3c0, 0x33e79c0, 0xc4203d1950, 0xc42080a000, 0xc4202bb980, 0x33b1d58, 0xc42066ec60, 0x0, 0x0) .../cri-o/vendor/google.golang.org/grpc/server.go:638 +0x99c ``` Signed-off-by: Dongsu Park --- server/sandbox_run.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/server/sandbox_run.go b/server/sandbox_run.go index 4b832843..23e8b7e4 100644 --- a/server/sandbox_run.go +++ b/server/sandbox_run.go @@ -221,10 +221,13 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest labels := req.GetConfig().GetLabels() // Add special container name label for the infra container - labels[types.KubernetesContainerNameLabel] = leaky.PodInfraContainerName - labelsJSON, err := json.Marshal(labels) - if err != nil { - return nil, err + labelsJSON := []byte{} + if labels != nil { + labels[types.KubernetesContainerNameLabel] = leaky.PodInfraContainerName + labelsJSON, err = json.Marshal(labels) + if err != nil { + return nil, err + } } // add annotations