Skip to content

Commit 6eb7cd9

Browse files
helsaawyAbhishek Singh (Manifold)
andauthored
[forwardport]populate resolv conf from right location for multipod (microsoft#2604)
populate resolv conf from right location(virtual pod dir) for virtualpod. issue: resolv.conf not getting populated with dns info incase of multi pod. cause: populating from wrong sandbox location fix: fix the read location (cherry picked from commit e819474) Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com> Co-authored-by: Abhishek Singh (Manifold) <Abhishek.Singh@microsoft.com>
1 parent 6dea86c commit 6eb7cd9

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

internal/guest/spec/spec.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ func networkingMountPaths() []string {
4343
func GenerateWorkloadContainerNetworkMounts(sandboxID string, spec *oci.Spec) []oci.Mount {
4444
var nMounts []oci.Mount
4545

46+
// In multipod mode, the sandbox writes networking files (resolv.conf, hostname, hosts)
47+
// under the virtual pod root directory. Use VirtualPodAwareSandboxRootDir to ensure
48+
// workload containers mount from the correct path.
49+
virtualSandboxID := spec.Annotations[annotations.VirtualPodID]
50+
rootDir := VirtualPodAwareSandboxRootDir(sandboxID, virtualSandboxID)
51+
52+
logrus.WithFields(logrus.Fields{
53+
"sandboxID": sandboxID,
54+
"virtualSandboxID": virtualSandboxID,
55+
"rootDir": rootDir,
56+
}).Info("GenerateWorkloadContainerNetworkMounts: resolved mount source root directory")
57+
4658
for _, mountPath := range networkingMountPaths() {
4759
// Don't override if the mount is present in the spec
4860
if MountPresent(mountPath, spec.Mounts) {
@@ -56,7 +68,7 @@ func GenerateWorkloadContainerNetworkMounts(sandboxID string, spec *oci.Spec) []
5668
mt := oci.Mount{
5769
Destination: mountPath,
5870
Type: "bind",
59-
Source: filepath.Join(SandboxRootDir(sandboxID), trimmedMountPath),
71+
Source: filepath.Join(rootDir, trimmedMountPath),
6072
Options: options,
6173
}
6274
nMounts = append(nMounts, mt)

pkg/securitypolicy/securitypolicy_linux.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ const osType = "linux"
2020

2121
func ExtendPolicyWithNetworkingMounts(sandboxID string, enforcer SecurityPolicyEnforcer, spec *oci.Spec) error {
2222
roSpec := &oci.Spec{
23-
Root: spec.Root,
23+
Root: spec.Root,
24+
Annotations: spec.Annotations,
2425
}
2526
networkingMounts := specInternal.GenerateWorkloadContainerNetworkMounts(sandboxID, roSpec)
2627
if err := enforcer.ExtendDefaultMounts(networkingMounts); err != nil {

0 commit comments

Comments
 (0)