sandbox: Track and store the pod resolv.conf path

When we get a pod with DNS settings, we need to build
a resolv.conf file and mount it in all pod containers.
In order to do that, we have to track the built resolv.conf
file and store/load it.

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
Samuel Ortiz 2017-03-24 15:28:14 +01:00
parent 673b6e4c51
commit 72129ee3fb
3 changed files with 6 additions and 2 deletions

View file

@ -140,6 +140,7 @@ type sandbox struct {
shmPath string shmPath string
cgroupParent string cgroupParent string
privileged bool privileged bool
resolvPath string
} }
const ( const (

View file

@ -66,7 +66,7 @@ func (s *Server) runContainer(container *oci.Container, cgroupParent string) err
// RunPodSandbox creates and runs a pod-level sandbox. // RunPodSandbox creates and runs a pod-level sandbox.
func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest) (resp *pb.RunPodSandboxResponse, err error) { func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest) (resp *pb.RunPodSandboxResponse, err error) {
logrus.Debugf("RunPodSandboxRequest %+v", req) logrus.Debugf("RunPodSandboxRequest %+v", req)
var processLabel, mountLabel, netNsPath string var processLabel, mountLabel, netNsPath, resolvPath string
// process req.Name // process req.Name
name := req.GetConfig().GetMetadata().Name name := req.GetConfig().GetMetadata().Name
if name == "" { if name == "" {
@ -160,7 +160,7 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
dnsServers := req.GetConfig().GetDnsConfig().Servers dnsServers := req.GetConfig().GetDnsConfig().Servers
dnsSearches := req.GetConfig().GetDnsConfig().Searches dnsSearches := req.GetConfig().GetDnsConfig().Searches
dnsOptions := req.GetConfig().GetDnsConfig().Options dnsOptions := req.GetConfig().GetDnsConfig().Options
resolvPath := fmt.Sprintf("%s/resolv.conf", podContainer.RunDir) resolvPath = fmt.Sprintf("%s/resolv.conf", podContainer.RunDir)
err = parseDNSOptions(dnsServers, dnsSearches, dnsOptions, resolvPath) err = parseDNSOptions(dnsServers, dnsSearches, dnsOptions, resolvPath)
if err != nil { if err != nil {
err1 := removeFile(resolvPath) err1 := removeFile(resolvPath)
@ -258,6 +258,7 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
g.AddAnnotation("ocid/container_id", id) g.AddAnnotation("ocid/container_id", id)
g.AddAnnotation("ocid/shm_path", shmPath) g.AddAnnotation("ocid/shm_path", shmPath)
g.AddAnnotation("ocid/privileged_runtime", fmt.Sprintf("%v", privileged)) g.AddAnnotation("ocid/privileged_runtime", fmt.Sprintf("%v", privileged))
g.AddAnnotation("ocid/resolv_path", resolvPath)
sb := &sandbox{ sb := &sandbox{
id: id, id: id,
@ -271,6 +272,7 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
metadata: metadata, metadata: metadata,
shmPath: shmPath, shmPath: shmPath,
privileged: privileged, privileged: privileged,
resolvPath: resolvPath,
} }
s.addSandbox(sb) s.addSandbox(sb)

View file

@ -187,6 +187,7 @@ func (s *Server) loadSandbox(id string) error {
metadata: &metadata, metadata: &metadata,
shmPath: m.Annotations["ocid/shm_path"], shmPath: m.Annotations["ocid/shm_path"],
privileged: privileged, privileged: privileged,
resolvPath: m.Annotations["ocid/resolv_path"],
} }
// We add a netNS only if we can load a permanent one. // We add a netNS only if we can load a permanent one.