*: store sandbox IP
Don't call into net namespace on every status call Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
parent
8538c4067a
commit
5d637f015d
5 changed files with 30 additions and 18 deletions
|
@ -294,6 +294,8 @@ func (c *ContainerServer) LoadSandbox(id string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ip := m.Annotations[annotations.IP]
|
||||||
|
|
||||||
processLabel, mountLabel, err := label.InitLabels(label.DupSecOpt(m.Process.SelinuxLabel))
|
processLabel, mountLabel, err := label.InitLabels(label.DupSecOpt(m.Process.SelinuxLabel))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -311,6 +313,7 @@ func (c *ContainerServer) LoadSandbox(id string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
sb.AddIP(ip)
|
||||||
|
|
||||||
// We add a netNS only if we can load a permanent one.
|
// We add a netNS only if we can load a permanent one.
|
||||||
// Otherwise, the sandbox will live in the host namespace.
|
// Otherwise, the sandbox will live in the host namespace.
|
||||||
|
|
|
@ -154,6 +154,8 @@ type Sandbox struct {
|
||||||
hostname string
|
hostname string
|
||||||
portMappings []*hostport.PortMapping
|
portMappings []*hostport.PortMapping
|
||||||
stopped bool
|
stopped bool
|
||||||
|
// ipv4 or ipv6 cache
|
||||||
|
ip string
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -202,6 +204,16 @@ func New(id, namespace, name, kubeName, logDir string, labels, annotations map[s
|
||||||
return sb, nil
|
return sb, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddIP stores the ip in the sandbox
|
||||||
|
func (s *Sandbox) AddIP(ip string) {
|
||||||
|
s.ip = ip
|
||||||
|
}
|
||||||
|
|
||||||
|
// IP returns the ip of the sandbox
|
||||||
|
func (s *Sandbox) IP() string {
|
||||||
|
return s.ip
|
||||||
|
}
|
||||||
|
|
||||||
// ID returns the id of the sandbox
|
// ID returns the id of the sandbox
|
||||||
func (s *Sandbox) ID() string {
|
func (s *Sandbox) ID() string {
|
||||||
return s.id
|
return s.id
|
||||||
|
|
|
@ -19,6 +19,9 @@ const (
|
||||||
// HostName is the container host name annotation
|
// HostName is the container host name annotation
|
||||||
HostName = "io.kubernetes.cri-o.HostName"
|
HostName = "io.kubernetes.cri-o.HostName"
|
||||||
|
|
||||||
|
// IP is the container ipv4 or ipv6 address
|
||||||
|
IP = "io.kubernetes.cri-o.IP"
|
||||||
|
|
||||||
// Image is the container image ID annotation
|
// Image is the container image ID annotation
|
||||||
Image = "io.kubernetes.cri-o.Image"
|
Image = "io.kubernetes.cri-o.Image"
|
||||||
|
|
||||||
|
|
|
@ -449,13 +449,6 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
|
||||||
}
|
}
|
||||||
g.AddAnnotation(annotations.MountPoint, mountPoint)
|
g.AddAnnotation(annotations.MountPoint, mountPoint)
|
||||||
g.SetRootPath(mountPoint)
|
g.SetRootPath(mountPoint)
|
||||||
err = g.SaveToFile(filepath.Join(podContainer.Dir, "config.json"), saveOptions)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to save template configuration for pod sandbox %s(%s): %v", sb.Name(), id, err)
|
|
||||||
}
|
|
||||||
if err = g.SaveToFile(filepath.Join(podContainer.RunDir, "config.json"), saveOptions); err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to write runtime configuration for pod sandbox %s(%s): %v", sb.Name(), id, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
container, err := oci.NewContainer(id, containerName, podContainer.RunDir, logPath, sb.NetNs(), labels, kubeAnnotations, "", "", "", nil, id, false, false, false, sb.Privileged(), sb.Trusted(), podContainer.Dir, created, podContainer.Config.Config.StopSignal)
|
container, err := oci.NewContainer(id, containerName, podContainer.RunDir, logPath, sb.NetNs(), labels, kubeAnnotations, "", "", "", nil, id, false, false, false, sb.Privileged(), sb.Trusted(), podContainer.Dir, created, podContainer.Config.Config.StopSignal)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -482,6 +475,9 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
|
||||||
return nil, fmt.Errorf("failed to get valid ipv4 address for container %s in sandbox %s", containerName, id)
|
return nil, fmt.Errorf("failed to get valid ipv4 address for container %s in sandbox %s", containerName, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g.AddAnnotation(annotations.IP, ip)
|
||||||
|
sb.AddIP(ip)
|
||||||
|
|
||||||
if err = s.hostportManager.Add(id, &hostport.PodPortMapping{
|
if err = s.hostportManager.Add(id, &hostport.PodPortMapping{
|
||||||
Name: name,
|
Name: name,
|
||||||
PortMappings: portMappings,
|
PortMappings: portMappings,
|
||||||
|
@ -494,6 +490,14 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = g.SaveToFile(filepath.Join(podContainer.Dir, "config.json"), saveOptions)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to save template configuration for pod sandbox %s(%s): %v", sb.Name(), id, err)
|
||||||
|
}
|
||||||
|
if err = g.SaveToFile(filepath.Join(podContainer.RunDir, "config.json"), saveOptions); err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to write runtime configuration for pod sandbox %s(%s): %v", sb.Name(), id, err)
|
||||||
|
}
|
||||||
|
|
||||||
if err = s.runContainer(container, sb.CgroupParent()); err != nil {
|
if err = s.runContainer(container, sb.CgroupParent()); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,16 +18,6 @@ func (s *Server) PodSandboxStatus(ctx context.Context, req *pb.PodSandboxStatusR
|
||||||
podInfraContainer := sb.InfraContainer()
|
podInfraContainer := sb.InfraContainer()
|
||||||
cState := s.Runtime().ContainerStatus(podInfraContainer)
|
cState := s.Runtime().ContainerStatus(podInfraContainer)
|
||||||
|
|
||||||
netNsPath, err := podInfraContainer.NetNsPath()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
ip, err := s.netPlugin.GetContainerNetworkStatus(netNsPath, sb.Namespace(), sb.KubeName(), sb.ID())
|
|
||||||
if err != nil {
|
|
||||||
// ignore the error on network status
|
|
||||||
ip = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
rStatus := pb.PodSandboxState_SANDBOX_NOTREADY
|
rStatus := pb.PodSandboxState_SANDBOX_NOTREADY
|
||||||
if cState.Status == oci.ContainerStateRunning {
|
if cState.Status == oci.ContainerStateRunning {
|
||||||
rStatus = pb.PodSandboxState_SANDBOX_READY
|
rStatus = pb.PodSandboxState_SANDBOX_READY
|
||||||
|
@ -38,7 +28,7 @@ func (s *Server) PodSandboxStatus(ctx context.Context, req *pb.PodSandboxStatusR
|
||||||
Status: &pb.PodSandboxStatus{
|
Status: &pb.PodSandboxStatus{
|
||||||
Id: sandboxID,
|
Id: sandboxID,
|
||||||
CreatedAt: podInfraContainer.CreatedAt().UnixNano(),
|
CreatedAt: podInfraContainer.CreatedAt().UnixNano(),
|
||||||
Network: &pb.PodSandboxNetworkStatus{Ip: ip},
|
Network: &pb.PodSandboxNetworkStatus{Ip: sb.IP()},
|
||||||
State: rStatus,
|
State: rStatus,
|
||||||
Labels: sb.Labels(),
|
Labels: sb.Labels(),
|
||||||
Annotations: sb.Annotations(),
|
Annotations: sb.Annotations(),
|
||||||
|
|
Loading…
Reference in a new issue