diff options
-rw-r--r-- | cmd/podman/common.go | 4 | ||||
-rw-r--r-- | cmd/podman/port.go | 49 | ||||
-rw-r--r-- | cmd/podman/shared/create.go | 5 | ||||
-rw-r--r-- | cmd/podman/shared/intermediate.go | 1 | ||||
-rw-r--r-- | completions/bash/podman | 6 | ||||
-rw-r--r-- | docs/source/markdown/podman-create.1.md | 4 | ||||
-rw-r--r-- | docs/source/markdown/podman-run.1.md | 4 | ||||
-rw-r--r-- | pkg/adapter/containers.go | 6 | ||||
-rw-r--r-- | test/e2e/healthcheck_run_test.go | 20 | ||||
-rw-r--r-- | test/system/500-networking.bats | 63 |
10 files changed, 132 insertions, 30 deletions
diff --git a/cmd/podman/common.go b/cmd/podman/common.go index 6fa2b3c71..4eeb09d42 100644 --- a/cmd/podman/common.go +++ b/cmd/podman/common.go @@ -396,6 +396,10 @@ func getCreateFlags(c *cliconfig.PodmanCommand) { "Assign a name to the container", ) createFlags.Bool( + "no-healthcheck", false, + "Disable healthchecks on container", + ) + createFlags.Bool( "oom-kill-disable", false, "Disable OOM Killer", ) diff --git a/cmd/podman/port.go b/cmd/podman/port.go index eef3d4b1d..4bb79a3a2 100644 --- a/cmd/podman/port.go +++ b/cmd/podman/port.go @@ -7,6 +7,7 @@ import ( "github.com/containers/libpod/cmd/podman/cliconfig" "github.com/containers/libpod/pkg/adapter" + "github.com/docker/go-connections/nat" "github.com/pkg/errors" "github.com/spf13/cobra" ) @@ -16,7 +17,7 @@ var ( portDescription = `List port mappings for the CONTAINER, or lookup the public-facing port that is NAT-ed to the PRIVATE_PORT ` _portCommand = &cobra.Command{ - Use: "port [flags] CONTAINER", + Use: "port [flags] CONTAINER [PORT]", Short: "List port mappings or a specific mapping for the container", Long: portDescription, RunE: func(cmd *cobra.Command, args []string) error { @@ -48,8 +49,8 @@ func init() { func portCmd(c *cliconfig.PortValues) error { var ( - userProto string - userPort int + userPort nat.Port + err error ) args := c.InputArgs @@ -70,25 +71,19 @@ func portCmd(c *cliconfig.PortValues) error { if len(args) == 1 && c.Latest { port = args[0] } - if port != "" { + if len(port) > 0 { fields := strings.Split(port, "/") - // User supplied at least port - var err error - // User supplied port and protocol - if len(fields) == 2 { - userProto = fields[1] - } - if len(fields) >= 1 { - p := fields[0] - userPort, err = strconv.Atoi(p) - if err != nil { - return errors.Wrapf(err, "unable to format port") - } - } - // Format is incorrect if len(fields) > 2 || len(fields) < 1 { return errors.Errorf("port formats are port/protocol. '%s' is invalid", port) } + if len(fields) == 1 { + fields = append(fields, "tcp") + } + + userPort, err = nat.NewPort(fields[1], fields[0]) + if err != nil { + return err + } } runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand) @@ -96,7 +91,6 @@ func portCmd(c *cliconfig.PortValues) error { return errors.Wrapf(err, "could not get runtime") } defer runtime.DeferredShutdown(false) - containers, err := runtime.Port(c) if err != nil { return err @@ -122,17 +116,18 @@ func portCmd(c *cliconfig.PortValues) error { fmt.Printf("%d/%s -> %s:%d\n", v.ContainerPort, v.Protocol, hostIP, v.HostPort) continue } - // We have a match on ports - if v.ContainerPort == int32(userPort) { - if userProto == "" || userProto == v.Protocol { - fmt.Printf("%s:%d\n", hostIP, v.HostPort) - found = true - break - } + containerPort, err := nat.NewPort(v.Protocol, strconv.Itoa(int(v.ContainerPort))) + if err != nil { + return err + } + if containerPort == userPort { + fmt.Printf("%s:%d\n", hostIP, v.HostPort) + found = true + break } } if !found && port != "" { - return errors.Errorf("failed to find published port '%d'", userPort) + return errors.Errorf("failed to find published port %q", port) } } diff --git a/cmd/podman/shared/create.go b/cmd/podman/shared/create.go index 5b244699c..0814eeba3 100644 --- a/cmd/podman/shared/create.go +++ b/cmd/podman/shared/create.go @@ -120,12 +120,13 @@ func CreateContainer(ctx context.Context, c *GenericCLIResults, runtime *libpod. imageName = newImage.ID() } - // if the user disabled the healthcheck with "none", we skip adding it + // if the user disabled the healthcheck with "none" or the no-healthcheck + // options is provided, we skip adding it healthCheckCommandInput := c.String("healthcheck-command") // the user didn't disable the healthcheck but did pass in a healthcheck command // now we need to make a healthcheck from the commandline input - if healthCheckCommandInput != "none" { + if healthCheckCommandInput != "none" && !c.Bool("no-healthcheck") { if len(healthCheckCommandInput) > 0 { healthCheck, err = makeHealthCheckFromCli(c) if err != nil { diff --git a/cmd/podman/shared/intermediate.go b/cmd/podman/shared/intermediate.go index ee212234f..e76750042 100644 --- a/cmd/podman/shared/intermediate.go +++ b/cmd/podman/shared/intermediate.go @@ -425,6 +425,7 @@ func NewIntermediateLayer(c *cliconfig.PodmanCommand, remote bool) GenericCLIRes m["memory-swappiness"] = newCRInt64(c, "memory-swappiness") m["name"] = newCRString(c, "name") m["network"] = newCRString(c, "network") + m["no-healthcheck"] = newCRBool(c, "no-healthcheck") m["no-hosts"] = newCRBool(c, "no-hosts") m["oom-kill-disable"] = newCRBool(c, "oom-kill-disable") m["oom-score-adj"] = newCRInt(c, "oom-score-adj") diff --git a/completions/bash/podman b/completions/bash/podman index 958633bf0..13be64e06 100644 --- a/completions/bash/podman +++ b/completions/bash/podman @@ -1888,6 +1888,11 @@ _podman_container_run() { --expose --gidmap --group-add + --health-cmd + --health-interval + --health-retries + --health-start-period + --health-timeout --hostname -h --http-proxy --image-volume @@ -1906,6 +1911,7 @@ _podman_container_run() { --memory-reservation --name --network + --no-healthcheck --no-hosts --oom-score-adj --pid diff --git a/docs/source/markdown/podman-create.1.md b/docs/source/markdown/podman-create.1.md index 64e331b42..3c5f81764 100644 --- a/docs/source/markdown/podman-create.1.md +++ b/docs/source/markdown/podman-create.1.md @@ -564,6 +564,10 @@ Valid values are: Not implemented +**--no-healthcheck**=*true|false* + +Disable any defined healthchecks for container. + **--no-hosts**=*true|false* Do not create /etc/hosts for the container. diff --git a/docs/source/markdown/podman-run.1.md b/docs/source/markdown/podman-run.1.md index d33b35f48..220b32a46 100644 --- a/docs/source/markdown/podman-run.1.md +++ b/docs/source/markdown/podman-run.1.md @@ -563,6 +563,10 @@ Valid _mode_ values are: Not implemented. +**--no-healthcheck**=*true|false* + +Disable any defined healthchecks for container. + **--no-hosts**=**true**|**false** Do not create _/etc/hosts_ for the container. diff --git a/pkg/adapter/containers.go b/pkg/adapter/containers.go index ab4255f89..78057e3f9 100644 --- a/pkg/adapter/containers.go +++ b/pkg/adapter/containers.go @@ -1116,7 +1116,11 @@ func (r *LocalRuntime) Port(c *cliconfig.PortValues) ([]*Container, error) { ) if !c.All { - containers, err = shortcuts.GetContainersByContext(false, c.Latest, c.InputArgs, r.Runtime) + names := []string{} + if len(c.InputArgs) >= 1 { + names = []string{c.InputArgs[0]} + } + containers, err = shortcuts.GetContainersByContext(false, c.Latest, names, r.Runtime) } else { containers, err = r.Runtime.GetRunningContainers() } diff --git a/test/e2e/healthcheck_run_test.go b/test/e2e/healthcheck_run_test.go index 7633261e3..19a8658ac 100644 --- a/test/e2e/healthcheck_run_test.go +++ b/test/e2e/healthcheck_run_test.go @@ -41,6 +41,26 @@ var _ = Describe("Podman healthcheck run", func() { Expect(session).To(ExitWithError()) }) + It("podman disable healthcheck with --no-healthcheck on valid container", func() { + SkipIfRemote() + session := podmanTest.Podman([]string{"run", "-dt", "--no-healthcheck", "--name", "hc", healthcheck}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + hc := podmanTest.Podman([]string{"healthcheck", "run", "hc"}) + hc.WaitWithDefaultTimeout() + Expect(hc.ExitCode()).To(Equal(125)) + }) + + It("podman disable healthcheck with --health-cmd=none on valid container", func() { + SkipIfRemote() + session := podmanTest.Podman([]string{"run", "-dt", "--health-cmd", "none", "--name", "hc", healthcheck}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + hc := podmanTest.Podman([]string{"healthcheck", "run", "hc"}) + hc.WaitWithDefaultTimeout() + Expect(hc.ExitCode()).To(Equal(125)) + }) + It("podman healthcheck on valid container", func() { Skip("Extremely consistent flake - re-enable on debugging") session := podmanTest.Podman([]string{"run", "-dt", "--name", "hc", healthcheck}) diff --git a/test/system/500-networking.bats b/test/system/500-networking.bats new file mode 100644 index 000000000..cd836610b --- /dev/null +++ b/test/system/500-networking.bats @@ -0,0 +1,63 @@ +#!/usr/bin/env bats -*- bats -*- +# +# Test podman local networking +# + +load helpers + +# Copied from tsweeney's https://github.com/containers/libpod/issues/4827 +@test "podman networking: port on localhost" { + skip_if_remote + random_1=$(random_string 30) + random_2=$(random_string 30) + + HOST_PORT=8080 + SERVER=http://localhost:$HOST_PORT + + # Create a test file with random content + INDEX1=$PODMAN_TMPDIR/hello.txt + echo $random_1 > $INDEX1 + + # Bind-mount this file with a different name to a container running httpd + run_podman run -d --name myweb -p "$HOST_PORT:80" \ + -v $INDEX1:/var/www/index.txt \ + -w /var/www \ + busybox httpd -f -p 80 + cid=$output + + # In that container, create a second file, using exec and redirection + run_podman exec -i myweb sh -c "cat > index2.txt" <<<"$random_2" + # ...verify its contents as seen from container. + run_podman exec -i myweb cat /var/www/index2.txt + is "$output" "$random_2" "exec cat index2.txt" + + # Verify http contents: curl from localhost + run curl -s $SERVER/index.txt + is "$output" "$random_1" "curl localhost:/index.txt" + run curl -s $SERVER/index2.txt + is "$output" "$random_2" "curl localhost:/index2.txt" + + # Verify http contents: wget from a second container + run_podman run --rm --net=host busybox wget -qO - $SERVER/index.txt + is "$output" "$random_1" "podman wget /index.txt" + run_podman run --rm --net=host busybox wget -qO - $SERVER/index2.txt + is "$output" "$random_2" "podman wget /index2.txt" + + # Tests #4889 - two-argument form of "podman ports" was broken + run_podman port myweb + is "$output" "80/tcp -> 0.0.0.0:$HOST_PORT" "port <cid>" + run_podman port myweb 80 + is "$output" "0.0.0.0:$HOST_PORT" "port <cid> 80" + run_podman port myweb 80/tcp + is "$output" "0.0.0.0:$HOST_PORT" "port <cid> 80/tcp" + + run_podman 125 port myweb 99/tcp + is "$output" 'Error: failed to find published port "99/tcp"' + + # Clean up + run_podman stop -t 1 myweb + run_podman rm myweb + run_podman rmi busybox +} + +# vim: filetype=sh |