diff --git a/lib/container_server.go b/lib/container_server.go index c073642e..98fffaf7 100644 --- a/lib/container_server.go +++ b/lib/container_server.go @@ -24,6 +24,7 @@ import ( "github.com/pkg/errors" "github.com/sirupsen/logrus" pb "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" + "k8s.io/kubernetes/pkg/kubelet/network/hostport" ) // ContainerServer implements the ImageServer @@ -332,10 +333,15 @@ func (c *ContainerServer) LoadSandbox(id string) error { 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]) 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 { return err } diff --git a/pkg/annotations/annotations.go b/pkg/annotations/annotations.go index c71e435b..02f3c145 100644 --- a/pkg/annotations/annotations.go +++ b/pkg/annotations/annotations.go @@ -40,6 +40,9 @@ const ( // KubeName is the kubernetes name annotation 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 = "io.kubernetes.cri-o.Labels" diff --git a/server/sandbox_run.go b/server/sandbox_run.go index 10a1bd9e..8e25db4c 100644 --- a/server/sandbox_run.go +++ b/server/sandbox_run.go @@ -363,6 +363,11 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest g.AddAnnotation(annotations.Created, created.Format(time.RFC3339Nano)) 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 cgroupParent := req.GetConfig().GetLinux().GetCgroupParent()