Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
virtcontainers: Set sandbox dns in sandbox request
Browse files Browse the repository at this point in the history
If ociMounts has DNS file /etc/resolv.conf present,
then pass the dns as part of CreateSandboxRequest to
the agent.

Depends-on: github.com/kata-containers/agent#625

Fixes: #1603

Signed-off-by: Nitesh Konkar <[email protected]>
  • Loading branch information
nitkon committed Sep 4, 2019
1 parent af57485 commit 07630b5
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion virtcontainers/kata_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ var (
grpcMaxDataSize = int64(1024 * 1024)
localDirOptions = []string{"mode=0777"}
maxHostnameLen = 64
GuestDNSFile = "/etc/resolv.conf"
)

const (
Expand Down Expand Up @@ -742,6 +743,34 @@ func (k *kataAgent) setProxyFromGrpc(proxy proxy, pid int, url string) {
k.state.URL = url
}

func (k *kataAgent) getDNS(sandbox *Sandbox) ([]string, error) {
ociSpecJSON, ok := sandbox.config.Annotations[vcAnnotations.ConfigJSONKey]
if !ok {
return nil, errorMissingOCISpec
}

ociSpec := &specs.Spec{}
if err := json.Unmarshal([]byte(ociSpecJSON), ociSpec); err != nil {
return nil, err
}

ociMounts := ociSpec.Mounts

for _, m := range ociMounts {
if m.Destination == GuestDNSFile {
content, err := ioutil.ReadFile(m.Source)
if err != nil {
return nil, fmt.Errorf("Could not read file %s: %s", m.Source, err)
}
dns := strings.Split(string(content), "\n")
return dns, nil

}
}
k.Logger().Debug("DNS file not present in ociMounts. Sandbox DNS will not be set.")
return nil, nil
}

func (k *kataAgent) startSandbox(sandbox *Sandbox) error {
span, _ := k.trace("startSandbox")
defer span.Finish()
Expand All @@ -756,12 +785,16 @@ func (k *kataAgent) startSandbox(sandbox *Sandbox) error {
k.proxy.stop(k.state.ProxyPid)
}
}()

hostname := sandbox.config.Hostname
if len(hostname) > maxHostnameLen {
hostname = hostname[:maxHostnameLen]
}

dns, err := k.getDNS(sandbox)
if err != nil {
return err
}

// check grpc server is serving
if err = k.check(); err != nil {
return err
Expand All @@ -787,6 +820,7 @@ func (k *kataAgent) startSandbox(sandbox *Sandbox) error {

req := &grpc.CreateSandboxRequest{
Hostname: hostname,
Dns: dns,
Storages: storages,
SandboxPidns: sandbox.sharePidNs,
SandboxId: sandbox.id,
Expand Down

0 comments on commit 07630b5

Please sign in to comment.