summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2021-03-01 08:12:48 +0100
committerGitHub <noreply@github.com>2021-03-01 08:12:48 +0100
commit3417703a063cc71de60752836daf2ffec158d2f6 (patch)
treea6a1fe2ce80c30167c4f23850bdd19e474d236f3
parent9600ea6bef8000b0c45407409124c7df21050493 (diff)
parent680dacaea2c7c8150cb2a8c9770a6e981a1f5ebc (diff)
downloadpodman-3417703a063cc71de60752836daf2ffec158d2f6.tar.gz
podman-3417703a063cc71de60752836daf2ffec158d2f6.tar.bz2
podman-3417703a063cc71de60752836daf2ffec158d2f6.zip
Merge pull request #9527 from rhatdan/hosts
Enable no_hosts from containers.conf
-rw-r--r--cmd/podman/common/netflags.go2
-rw-r--r--cmd/podman/containers/create.go6
-rw-r--r--test/e2e/config/containers.conf1
-rw-r--r--test/e2e/containers_conf_test.go22
4 files changed, 29 insertions, 2 deletions
diff --git a/cmd/podman/common/netflags.go b/cmd/podman/common/netflags.go
index bc4d54de0..4d0a554a6 100644
--- a/cmd/podman/common/netflags.go
+++ b/cmd/podman/common/netflags.go
@@ -80,7 +80,7 @@ func DefineNetFlags(cmd *cobra.Command) {
_ = cmd.RegisterFlagCompletionFunc(publishFlagName, completion.AutocompleteNone)
netFlags.Bool(
- "no-hosts", false,
+ "no-hosts", containerConfig.Containers.NoHosts,
"Do not create /etc/hosts within the container, instead use the version from the image",
)
}
diff --git a/cmd/podman/containers/create.go b/cmd/podman/containers/create.go
index d7507775f..af9278ce1 100644
--- a/cmd/podman/containers/create.go
+++ b/cmd/podman/containers/create.go
@@ -166,7 +166,11 @@ func createInit(c *cobra.Command) error {
return errors.Errorf("--cpu-quota and --cpus cannot be set together")
}
- if c.Flag("no-hosts").Changed && c.Flag("add-host").Changed {
+ noHosts, err := c.Flags().GetBool("no-hosts")
+ if err != nil {
+ return err
+ }
+ if noHosts && c.Flag("add-host").Changed {
return errors.Errorf("--no-hosts and --add-host cannot be set together")
}
cliVals.UserNS = c.Flag("userns").Value.String()
diff --git a/test/e2e/config/containers.conf b/test/e2e/config/containers.conf
index fdf679664..bbd712254 100644
--- a/test/e2e/config/containers.conf
+++ b/test/e2e/config/containers.conf
@@ -55,6 +55,7 @@ umask = "0002"
annotations=["run.oci.keep_original_groups=1",]
+no_hosts=true
[engine]
network_cmd_options=["allow_host_loopback=true"]
diff --git a/test/e2e/containers_conf_test.go b/test/e2e/containers_conf_test.go
index 9c2260c5f..6b1a0d16e 100644
--- a/test/e2e/containers_conf_test.go
+++ b/test/e2e/containers_conf_test.go
@@ -331,4 +331,26 @@ var _ = Describe("Podman run", func() {
Expect(inspect.OutputToString()).To(ContainSubstring("run.oci.keep_original_groups:1"))
})
+ It("podman run with --add-host and no-hosts=true fails", func() {
+ session := podmanTest.Podman([]string{"run", "-dt", "--add-host", "test1:127.0.0.1", ALPINE, "top"})
+ session.WaitWithDefaultTimeout()
+ Expect(session).To(ExitWithError())
+ Expect(session.ErrorToString()).To(ContainSubstring("--no-hosts and --add-host cannot be set together"))
+
+ session = podmanTest.Podman([]string{"run", "-dt", "--add-host", "test1:127.0.0.1", "--no-hosts=false", ALPINE, "top"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ })
+
+ It("podman run with no-hosts=true /etc/hosts does not include hostname", func() {
+ session := podmanTest.Podman([]string{"run", "--rm", "--name", "test", ALPINE, "cat", "/etc/hosts"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ Expect(session.OutputToString()).To(Not(ContainSubstring("test")))
+
+ session = podmanTest.Podman([]string{"run", "--rm", "--name", "test", "--no-hosts=false", ALPINE, "cat", "/etc/hosts"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ Expect(session.OutputToString()).To(ContainSubstring("test"))
+ })
})