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
|
@ -46,7 +46,7 @@ func logsCmd(c *cli.Context) error {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return errors.Errorf("'kpod logs' requires exactly one container name/ID")
|
return errors.Errorf("'kpod logs' requires exactly one container name/ID")
|
||||||
}
|
}
|
||||||
container := args[0]
|
container := c.Args().First()
|
||||||
var opts libkpod.LogOptions
|
var opts libkpod.LogOptions
|
||||||
opts.Details = c.Bool("details")
|
opts.Details = c.Bool("details")
|
||||||
opts.Follow = c.Bool("follow")
|
opts.Follow = c.Bool("follow")
|
||||||
|
|
|
@ -622,6 +622,7 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
|
||||||
|
|
||||||
specgen.AddAnnotation(annotations.ImageName, imageName)
|
specgen.AddAnnotation(annotations.ImageName, imageName)
|
||||||
specgen.AddAnnotation(annotations.ImageRef, imageRef)
|
specgen.AddAnnotation(annotations.ImageRef, imageRef)
|
||||||
|
specgen.AddAnnotation(annotations.IP, sb.IP())
|
||||||
|
|
||||||
// bind mount the pod shm
|
// bind mount the pod shm
|
||||||
specgen.AddBindMount(sb.ShmPath(), "/dev/shm", []string{"rw"})
|
specgen.AddBindMount(sb.ShmPath(), "/dev/shm", []string{"rw"})
|
||||||
|
|
|
@ -458,26 +458,23 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
|
||||||
|
|
||||||
sb.SetInfraContainer(container)
|
sb.SetInfraContainer(container)
|
||||||
|
|
||||||
|
var ip string
|
||||||
// setup the network
|
// setup the network
|
||||||
if !hostNetwork {
|
if !hostNetwork {
|
||||||
if err = s.netPlugin.SetUpPod(netNsPath, namespace, kubeName, id); err != nil {
|
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)
|
return nil, fmt.Errorf("failed to create network for container %s in sandbox %s: %v", containerName, id, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(portMappings) != 0 {
|
if ip, err = s.netPlugin.GetContainerNetworkStatus(netNsPath, namespace, id, kubeName); err != nil {
|
||||||
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)
|
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()
|
ip4 := net.ParseIP(ip).To4()
|
||||||
if ip4 == nil {
|
if ip4 == nil {
|
||||||
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,
|
||||||
|
@ -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)
|
err = g.SaveToFile(filepath.Join(podContainer.Dir, "config.json"), saveOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to save template configuration for pod sandbox %s(%s): %v", sb.Name(), id, err)
|
return nil, fmt.Errorf("failed to save template configuration for pod sandbox %s(%s): %v", sb.Name(), id, err)
|
||||||
|
|
|
@ -66,6 +66,8 @@ type Server struct {
|
||||||
appArmorProfile string
|
appArmorProfile string
|
||||||
|
|
||||||
stream streamService
|
stream streamService
|
||||||
|
|
||||||
|
bindAddress string
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetExec returns exec stream request
|
// GetExec returns exec stream request
|
||||||
|
@ -233,6 +235,7 @@ func New(config *Config) (*Server, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
s.bindAddress = bindAddress.String()
|
||||||
|
|
||||||
_, err = net.LookupPort("tcp", config.StreamPort)
|
_, err = net.LookupPort("tcp", config.StreamPort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -289,6 +292,11 @@ func (s *Server) getInfraContainer(id string) *oci.Container {
|
||||||
return s.ContainerServer.GetInfraContainer(id)
|
return s.ContainerServer.GetInfraContainer(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BindAddress is used to retrieve host's IP
|
||||||
|
func (s *Server) BindAddress() string {
|
||||||
|
return s.bindAddress
|
||||||
|
}
|
||||||
|
|
||||||
// GetSandboxContainer returns the infra container for a given sandbox
|
// GetSandboxContainer returns the infra container for a given sandbox
|
||||||
func (s *Server) GetSandboxContainer(id string) *oci.Container {
|
func (s *Server) GetSandboxContainer(id string) *oci.Container {
|
||||||
return s.ContainerServer.GetSandboxContainer(id)
|
return s.ContainerServer.GetSandboxContainer(id)
|
||||||
|
|
|
@ -5,7 +5,7 @@ load helpers
|
||||||
IMAGE="alpine:latest"
|
IMAGE="alpine:latest"
|
||||||
ROOT="$TESTDIR/crio"
|
ROOT="$TESTDIR/crio"
|
||||||
RUNROOT="$TESTDIR/crio-run"
|
RUNROOT="$TESTDIR/crio-run"
|
||||||
KPOD_OPTIONS="--root $ROOT --runroot $RUNROOT $STORAGE_OPTS"
|
KPOD_OPTIONS="--root $ROOT --runroot $RUNROOT ${STORAGE_OPTS}"
|
||||||
|
|
||||||
function teardown() {
|
function teardown() {
|
||||||
cleanup_test
|
cleanup_test
|
||||||
|
|
Loading…
Reference in a new issue