sandbox: restore portMappings on restart

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
Antonio Murdaca 2018-02-12 11:31:56 +01:00
parent c3f1e7aec2
commit e5fc48a3ca
No known key found for this signature in database
GPG key ID: B2BEAD150DE936B9
3 changed files with 15 additions and 1 deletions

View file

@ -24,6 +24,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
pb "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" pb "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
"k8s.io/kubernetes/pkg/kubelet/network/hostport"
) )
// ContainerServer implements the ImageServer // ContainerServer implements the ImageServer
@ -332,10 +333,15 @@ func (c *ContainerServer) LoadSandbox(id string) error {
return err return err
} }
portMappings := []*hostport.PortMapping{}
if err := json.Unmarshal([]byte(m.Annotations[annotations.PortMappings]), &portMappings); err != nil {
return err
}
privileged := isTrue(m.Annotations[annotations.PrivilegedRuntime]) privileged := isTrue(m.Annotations[annotations.PrivilegedRuntime])
trusted := isTrue(m.Annotations[annotations.TrustedSandbox]) trusted := isTrue(m.Annotations[annotations.TrustedSandbox])
sb, err := sandbox.New(id, m.Annotations[annotations.Namespace], name, m.Annotations[annotations.KubeName], filepath.Dir(m.Annotations[annotations.LogPath]), labels, kubeAnnotations, processLabel, mountLabel, &metadata, m.Annotations[annotations.ShmPath], m.Annotations[annotations.CgroupParent], privileged, trusted, m.Annotations[annotations.ResolvPath], m.Annotations[annotations.HostName], nil) sb, err := sandbox.New(id, m.Annotations[annotations.Namespace], name, m.Annotations[annotations.KubeName], filepath.Dir(m.Annotations[annotations.LogPath]), labels, kubeAnnotations, processLabel, mountLabel, &metadata, m.Annotations[annotations.ShmPath], m.Annotations[annotations.CgroupParent], privileged, trusted, m.Annotations[annotations.ResolvPath], m.Annotations[annotations.HostName], portMappings)
if err != nil { if err != nil {
return err return err
} }

View file

@ -40,6 +40,9 @@ const (
// KubeName is the kubernetes name annotation // KubeName is the kubernetes name annotation
KubeName = "io.kubernetes.cri-o.KubeName" KubeName = "io.kubernetes.cri-o.KubeName"
// PortMappings holds the port mappings for the sandbox
PortMappings = "io.kubernetes.cri-o.PortMappings"
// Labels are the kubernetes labels annotation // Labels are the kubernetes labels annotation
Labels = "io.kubernetes.cri-o.Labels" Labels = "io.kubernetes.cri-o.Labels"

View file

@ -363,6 +363,11 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
g.AddAnnotation(annotations.Created, created.Format(time.RFC3339Nano)) g.AddAnnotation(annotations.Created, created.Format(time.RFC3339Nano))
portMappings := convertPortMappings(req.GetConfig().GetPortMappings()) portMappings := convertPortMappings(req.GetConfig().GetPortMappings())
portMappingsJSON, err := json.Marshal(portMappings)
if err != nil {
return nil, err
}
g.AddAnnotation(annotations.PortMappings, string(portMappingsJSON))
// setup cgroup settings // setup cgroup settings
cgroupParent := req.GetConfig().GetLinux().GetCgroupParent() cgroupParent := req.GetConfig().GetLinux().GetCgroupParent()