server: container_create: store sandbox's ip in annotations
So it can be later retrieved when needed (cadvisor) Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
parent
5d637f015d
commit
2ac2832686
5 changed files with 21 additions and 10 deletions
|
@ -458,26 +458,23 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
|
|||
|
||||
sb.SetInfraContainer(container)
|
||||
|
||||
var ip string
|
||||
// setup the network
|
||||
if !hostNetwork {
|
||||
if err = s.netPlugin.SetUpPod(netNsPath, namespace, kubeName, id); err != nil {
|
||||
return nil, fmt.Errorf("failed to create network for container %s in sandbox %s: %v", containerName, id, err)
|
||||
}
|
||||
|
||||
if len(portMappings) != 0 {
|
||||
ip, err := s.netPlugin.GetContainerNetworkStatus(netNsPath, namespace, id, containerName)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get network status for container %s in sandbox %s: %v", containerName, id, err)
|
||||
}
|
||||
if ip, err = s.netPlugin.GetContainerNetworkStatus(netNsPath, namespace, id, kubeName); err != nil {
|
||||
return nil, fmt.Errorf("failed to get network status for container %s in sandbox %s: %v", containerName, id, err)
|
||||
}
|
||||
|
||||
if len(portMappings) != 0 {
|
||||
ip4 := net.ParseIP(ip).To4()
|
||||
if ip4 == nil {
|
||||
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{
|
||||
Name: name,
|
||||
PortMappings: portMappings,
|
||||
|
@ -488,8 +485,13 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
|
|||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
ip = s.BindAddress()
|
||||
}
|
||||
|
||||
g.AddAnnotation(annotations.IP, ip)
|
||||
sb.AddIP(ip)
|
||||
|
||||
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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue