mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-29 00:37:24 +00:00
Merge pull request #1939 from nitkon/DNSFromCreateSandboxReq
virtcontainers: Set sandbox dns in sandbox request
This commit is contained in:
commit
39864c37ff
@ -88,6 +88,7 @@ var (
|
|||||||
grpcMaxDataSize = int64(1024 * 1024)
|
grpcMaxDataSize = int64(1024 * 1024)
|
||||||
localDirOptions = []string{"mode=0777"}
|
localDirOptions = []string{"mode=0777"}
|
||||||
maxHostnameLen = 64
|
maxHostnameLen = 64
|
||||||
|
GuestDNSFile = "/etc/resolv.conf"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -743,6 +744,34 @@ func (k *kataAgent) setProxyFromGrpc(proxy proxy, pid int, url string) {
|
|||||||
k.state.URL = url
|
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 {
|
func (k *kataAgent) startSandbox(sandbox *Sandbox) error {
|
||||||
span, _ := k.trace("startSandbox")
|
span, _ := k.trace("startSandbox")
|
||||||
defer span.Finish()
|
defer span.Finish()
|
||||||
@ -757,12 +786,16 @@ func (k *kataAgent) startSandbox(sandbox *Sandbox) error {
|
|||||||
k.proxy.stop(k.state.ProxyPid)
|
k.proxy.stop(k.state.ProxyPid)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
hostname := sandbox.config.Hostname
|
hostname := sandbox.config.Hostname
|
||||||
if len(hostname) > maxHostnameLen {
|
if len(hostname) > maxHostnameLen {
|
||||||
hostname = hostname[:maxHostnameLen]
|
hostname = hostname[:maxHostnameLen]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dns, err := k.getDNS(sandbox)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// check grpc server is serving
|
// check grpc server is serving
|
||||||
if err = k.check(); err != nil {
|
if err = k.check(); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -788,6 +821,7 @@ func (k *kataAgent) startSandbox(sandbox *Sandbox) error {
|
|||||||
|
|
||||||
req := &grpc.CreateSandboxRequest{
|
req := &grpc.CreateSandboxRequest{
|
||||||
Hostname: hostname,
|
Hostname: hostname,
|
||||||
|
Dns: dns,
|
||||||
Storages: storages,
|
Storages: storages,
|
||||||
SandboxPidns: sandbox.sharePidNs,
|
SandboxPidns: sandbox.sharePidNs,
|
||||||
SandboxId: sandbox.id,
|
SandboxId: sandbox.id,
|
||||||
|
Loading…
Reference in New Issue
Block a user