Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions server/container_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,15 +399,6 @@ func setupCapabilities(specgen *generate.Generator, caps *types.Capability, defa
return nil
}

func hostNetwork(containerConfig *types.ContainerConfig) bool {
securityContext := containerConfig.Linux.SecurityContext
if securityContext == nil || securityContext.NamespaceOptions == nil {
return false
}

return securityContext.NamespaceOptions.Network == types.NamespaceModeNODE
}

// CreateContainer creates a new container in specified PodSandbox
func (s *Server) CreateContainer(ctx context.Context, req *types.CreateContainerRequest) (res *types.CreateContainerResponse, retErr error) {
log.Infof(ctx, "Creating container: %s", translateLabelsToDescription(req.Config.Labels))
Expand Down
11 changes: 8 additions & 3 deletions server/container_create_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,19 +434,24 @@ func (s *Server) createSandboxContainer(ctx context.Context, ctr ctrIface.Contai
}

// If the sandbox is configured to run in the host network, do not create a new network namespace
if sb.HostNetwork() {
if hostNet {
if err := specgen.RemoveLinuxNamespace(string(rspec.NetworkNamespace)); err != nil {
return nil, err
}

if !isInCRIMounts("/sys", containerConfig.Mounts) {
specgen.RemoveMount("/sys")
ctr.SpecAddMount(rspec.Mount{
Destination: "/sys",
Type: "sysfs",
Source: "sysfs",
Options: []string{"nosuid", "noexec", "nodev", "ro"},
})
ctr.SpecAddMount(rspec.Mount{
Destination: "/sys/fs/cgroup",
Type: "cgroup",
Source: "cgroup",
Options: []string{"nosuid", "noexec", "nodev", "relatime", "ro"},
})
}
}

Expand Down Expand Up @@ -525,7 +530,7 @@ func (s *Server) createSandboxContainer(ctx context.Context, ctr ctrIface.Contai
})
}

if !isInCRIMounts("/etc/hosts", containerConfig.Mounts) && hostNetwork(containerConfig) {
if !isInCRIMounts("/etc/hosts", containerConfig.Mounts) && hostNet {
// Only bind mount for host netns and when CRI does not give us any hosts file
ctr.SpecAddMount(rspec.Mount{
Destination: "/etc/hosts",
Expand Down