From e4ab8a5bedb48615402231a5aa3a62ca4364c45f Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Thu, 21 Apr 2022 12:29:31 +0200 Subject: shared netns and --add-host should conflict Because /etc/hosts is shared for all containers with a shared network namespace you should not be able to add hosts from a joined container. Only the primary netns container can set the hosts. Signed-off-by: Paul Holzinger --- pkg/specgen/container_validate.go | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'pkg/specgen/container_validate.go') diff --git a/pkg/specgen/container_validate.go b/pkg/specgen/container_validate.go index 42b70e334..e06cd9a29 100644 --- a/pkg/specgen/container_validate.go +++ b/pkg/specgen/container_validate.go @@ -38,6 +38,13 @@ func (s *SpecGenerator) Validate() error { if len(s.PortMappings) > 0 || s.PublishExposedPorts { return errors.Wrap(define.ErrNetworkOnPodContainer, "published or exposed ports must be defined when the pod is created") } + if len(s.HostAdd) > 0 { + return errors.Wrap(define.ErrNetworkOnPodContainer, "extra host entries must be specified on the pod") + } + } + + if s.NetNS.IsContainer() && len(s.HostAdd) > 0 { + return errors.Wrap(ErrInvalidSpecConfig, "cannot set extra host entries when the container is joined to another containers network namespace") } // -- cgit v1.2.3-54-g00ecf