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 <dongsu@kinvolk.io>
This commit is contained in:
parent
7d5d652f65
commit
2080744963
1 changed files with 7 additions and 4 deletions
|
@ -221,11 +221,14 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
|
|||
labels := req.GetConfig().GetLabels()
|
||||
|
||||
// Add special container name label for the infra container
|
||||
labelsJSON := []byte{}
|
||||
if labels != nil {
|
||||
labels[types.KubernetesContainerNameLabel] = leaky.PodInfraContainerName
|
||||
labelsJSON, err := json.Marshal(labels)
|
||||
labelsJSON, err = json.Marshal(labels)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// add annotations
|
||||
kubeAnnotations := req.GetConfig().GetAnnotations()
|
||||
|
|
Loading…
Reference in a new issue