mirror of
https://github.com/containers/podman.git
synced 2026-02-05 15:45:08 +01:00
Improve handling of --publish and incompatible NetNS modes
Handling is improved by: - Inverting detection logic so all incompatible NetNS modes that can't be used with the `--publish` option will now print a warning to the user. - Updating the --publish documentation - Extract detection logic out to it's own function with a note to keep docs in sync. Note: path mode was added after this warning logic was added: - https://github.com/containers/podman/pull/8230 - https://github.com/containers/podman/pull/16386 Relates-to: https://github.com/containers/podman/issues/26663 Signed-off-by: Lewis Roy <lewis@redhat.com>
This commit is contained in:
@@ -351,11 +351,13 @@ func CompleteSpec(ctx context.Context, r *libpod.Runtime, s *specgen.SpecGenerat
|
||||
return warnings, err
|
||||
}
|
||||
|
||||
// Warn on net=host/container/pod/none and port mappings.
|
||||
if (s.NetNS.NSMode == specgen.Host || s.NetNS.NSMode == specgen.FromContainer ||
|
||||
s.NetNS.NSMode == specgen.FromPod || s.NetNS.NSMode == specgen.NoNetwork) &&
|
||||
len(s.PortMappings) > 0 {
|
||||
warnings = append(warnings, "Port mappings have been discarded as one of the Host, Container, Pod, and None network modes are in use")
|
||||
// Warn if NetNS mode is not compatible with PorMappings
|
||||
if len(s.PortMappings) > 0 {
|
||||
nsMode := s.NetNS.NSMode
|
||||
if nsMode != "" && !isPortMappingCompatibleNetNSMode(nsMode) {
|
||||
warnings = append(warnings,
|
||||
fmt.Sprintf("Port mappings have been discarded because \"%s\" network namespace mode does not support them", nsMode))
|
||||
}
|
||||
}
|
||||
|
||||
if len(s.ImageVolumeMode) == 0 {
|
||||
@@ -624,3 +626,15 @@ func CheckName(rt *libpod.Runtime, n string, kind bool) string {
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
// isPortMappingCompatibleNetNSMode validates if mode of the provided
|
||||
// Namespace mode is compatible with port mappings.
|
||||
// Note: Update `podman run --publish | -p` docs when modifying this function.
|
||||
func isPortMappingCompatibleNetNSMode(nsMode specgen.NamespaceMode) bool {
|
||||
switch nsMode {
|
||||
case specgen.Bridge, specgen.Slirp, specgen.Pasta:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user