diff options
28 files changed, 145 insertions, 101 deletions
diff --git a/cmd/podman/common/specgen.go b/cmd/podman/common/specgen.go index 39ff02857..0bb6e79e5 100644 --- a/cmd/podman/common/specgen.go +++ b/cmd/podman/common/specgen.go @@ -592,7 +592,7 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string case "max-size": logSize, err := units.FromHumanSize(split[1]) if err != nil { - return errors.Wrapf(err, "%s is not a valid option", o) + return err } s.LogConfiguration.Size = logSize default: @@ -662,7 +662,7 @@ func makeHealthCheckFromCli(inCmd, interval string, retries uint, timeout, start } intervalDuration, err := time.ParseDuration(interval) if err != nil { - return nil, errors.Wrapf(err, "invalid healthcheck-interval %s ", interval) + return nil, errors.Wrapf(err, "invalid healthcheck-interval") } hc.Interval = intervalDuration @@ -673,7 +673,7 @@ func makeHealthCheckFromCli(inCmd, interval string, retries uint, timeout, start hc.Retries = int(retries) timeoutDuration, err := time.ParseDuration(timeout) if err != nil { - return nil, errors.Wrapf(err, "invalid healthcheck-timeout %s", timeout) + return nil, errors.Wrapf(err, "invalid healthcheck-timeout") } if timeoutDuration < time.Duration(1) { return nil, errors.New("healthcheck-timeout must be at least 1 second") @@ -682,7 +682,7 @@ func makeHealthCheckFromCli(inCmd, interval string, retries uint, timeout, start startPeriodDuration, err := time.ParseDuration(startPeriod) if err != nil { - return nil, errors.Wrapf(err, "invalid healthcheck-start-period %s", startPeriod) + return nil, errors.Wrapf(err, "invalid healthcheck-start-period") } if startPeriodDuration < time.Duration(0) { return nil, errors.New("healthcheck-start-period must be 0 seconds or greater") diff --git a/cmd/podman/common/util.go b/cmd/podman/common/util.go index a971aa957..ef30e08d3 100644 --- a/cmd/podman/common/util.go +++ b/cmd/podman/common/util.go @@ -250,7 +250,7 @@ func parseAndValidateRange(portRange string) (uint16, uint16, error) { func parseAndValidatePort(port string) (uint16, error) { num, err := strconv.Atoi(port) if err != nil { - return 0, errors.Wrapf(err, "cannot parse %q as a port number", port) + return 0, errors.Wrapf(err, "invalid port number") } if num < 1 || num > 65535 { return 0, errors.Errorf("port numbers must be between 1 and 65535 (inclusive), got %d", num) diff --git a/cmd/podman/containers/prune.go b/cmd/podman/containers/prune.go index e8debd3ad..9ac529b1c 100644 --- a/cmd/podman/containers/prune.go +++ b/cmd/podman/containers/prune.go @@ -57,7 +57,7 @@ func prune(cmd *cobra.Command, args []string) error { fmt.Print("Are you sure you want to continue? [y/N] ") answer, err := reader.ReadString('\n') if err != nil { - return errors.Wrapf(err, "error reading input") + return err } if strings.ToLower(answer)[0] != 'y' { return nil diff --git a/cmd/podman/containers/run.go b/cmd/podman/containers/run.go index b17c13f46..6ff1b929d 100644 --- a/cmd/podman/containers/run.go +++ b/cmd/podman/containers/run.go @@ -205,7 +205,7 @@ func run(cmd *cobra.Command, args []string) error { if runRmi { _, rmErrors := registry.ImageEngine().Remove(registry.GetContext(), []string{imageName}, entities.ImageRemoveOptions{}) if len(rmErrors) > 0 { - logrus.Errorf("%s", errors.Wrapf(errorhandling.JoinErrors(rmErrors), "failed removing image")) + logrus.Errorf("%s", errorhandling.JoinErrors(rmErrors)) } } return nil diff --git a/cmd/podman/images/build.go b/cmd/podman/images/build.go index c76e4ac80..739e1c265 100644 --- a/cmd/podman/images/build.go +++ b/cmd/podman/images/build.go @@ -353,18 +353,18 @@ func buildFlagsWrapperToOptions(c *cobra.Command, contextDir string, flags *buil isolation, err := parse.IsolationOption(flags.Isolation) if err != nil { - return nil, errors.Wrapf(err, "error parsing ID mapping options") + return nil, err } usernsOption, idmappingOptions, err := parse.IDMappingOptions(c, isolation) if err != nil { - return nil, errors.Wrapf(err, "error parsing ID mapping options") + return nil, err } nsValues = append(nsValues, usernsOption...) systemContext, err := parse.SystemContextFromOptions(c) if err != nil { - return nil, errors.Wrapf(err, "error building system context") + return nil, err } format := "" diff --git a/cmd/podman/images/prune.go b/cmd/podman/images/prune.go index 3af56b015..e68fe5f40 100644 --- a/cmd/podman/images/prune.go +++ b/cmd/podman/images/prune.go @@ -11,7 +11,6 @@ import ( "github.com/containers/podman/v2/cmd/podman/utils" "github.com/containers/podman/v2/cmd/podman/validate" "github.com/containers/podman/v2/pkg/domain/entities" - "github.com/pkg/errors" "github.com/spf13/cobra" ) @@ -60,7 +59,7 @@ WARNING! This will remove all dangling images. Are you sure you want to continue? [y/N] `) answer, err := reader.ReadString('\n') if err != nil { - return errors.Wrapf(err, "error reading input") + return err } if strings.ToLower(answer)[0] != 'y' { return nil diff --git a/cmd/podman/images/sign.go b/cmd/podman/images/sign.go index 529fb3d92..342536f7c 100644 --- a/cmd/podman/images/sign.go +++ b/cmd/podman/images/sign.go @@ -58,7 +58,7 @@ func sign(cmd *cobra.Command, args []string) error { if len(signOptions.Directory) > 0 { sigStoreDir = signOptions.Directory if _, err := os.Stat(sigStoreDir); err != nil { - return errors.Wrapf(err, "invalid directory %s", sigStoreDir) + return err } } _, err := registry.ImageEngine().Sign(registry.Context(), args, signOptions) diff --git a/cmd/podman/images/trust_set.go b/cmd/podman/images/trust_set.go index f0399b110..1a7392f3e 100644 --- a/cmd/podman/images/trust_set.go +++ b/cmd/podman/images/trust_set.go @@ -55,7 +55,7 @@ func setTrust(cmd *cobra.Command, args []string) error { valid, err := image.IsValidImageURI(args[0]) if err != nil || !valid { - return errors.Wrapf(err, "invalid image uri %s", args[0]) + return err } if !util.StringInSlice(setOptions.Type, validTrustTypes) { diff --git a/cmd/podman/manifest/add.go b/cmd/podman/manifest/add.go index 91bd423b8..cb0838eeb 100644 --- a/cmd/podman/manifest/add.go +++ b/cmd/podman/manifest/add.go @@ -11,7 +11,6 @@ import ( "github.com/containers/podman/v2/cmd/podman/registry" "github.com/containers/podman/v2/pkg/domain/entities" "github.com/containers/podman/v2/pkg/util" - "github.com/pkg/errors" "github.com/spf13/cobra" ) @@ -116,7 +115,7 @@ func add(cmd *cobra.Command, args []string) error { listID, err := registry.ImageEngine().ManifestAdd(context.Background(), manifestAddOpts.ManifestAddOptions) if err != nil { - return errors.Wrapf(err, "error adding to manifest list %s", args[0]) + return err } fmt.Printf("%s\n", listID) return nil diff --git a/cmd/podman/manifest/annotate.go b/cmd/podman/manifest/annotate.go index dab8c4da6..71017e0ec 100644 --- a/cmd/podman/manifest/annotate.go +++ b/cmd/podman/manifest/annotate.go @@ -73,7 +73,7 @@ func annotate(cmd *cobra.Command, args []string) error { } updatedListID, err := registry.ImageEngine().ManifestAnnotate(context.Background(), args, manifestAnnotateOpts) if err != nil { - return errors.Wrapf(err, "error removing from manifest list %s", listImageSpec) + return err } fmt.Printf("%s\n", updatedListID) return nil diff --git a/cmd/podman/manifest/create.go b/cmd/podman/manifest/create.go index c903c6fa8..399f9440c 100644 --- a/cmd/podman/manifest/create.go +++ b/cmd/podman/manifest/create.go @@ -7,7 +7,6 @@ import ( "github.com/containers/podman/v2/cmd/podman/common" "github.com/containers/podman/v2/cmd/podman/registry" "github.com/containers/podman/v2/pkg/domain/entities" - "github.com/pkg/errors" "github.com/spf13/cobra" ) @@ -39,7 +38,7 @@ func init() { func create(cmd *cobra.Command, args []string) error { imageID, err := registry.ImageEngine().ManifestCreate(context.Background(), args[:1], args[1:], manifestCreateOpts) if err != nil { - return errors.Wrapf(err, "error creating manifest %s", args[0]) + return err } fmt.Printf("%s\n", imageID) return nil diff --git a/cmd/podman/manifest/inspect.go b/cmd/podman/manifest/inspect.go index 17c94aaba..39fd54445 100644 --- a/cmd/podman/manifest/inspect.go +++ b/cmd/podman/manifest/inspect.go @@ -7,7 +7,6 @@ import ( "github.com/containers/podman/v2/cmd/podman/common" "github.com/containers/podman/v2/cmd/podman/registry" "github.com/containers/podman/v2/pkg/domain/entities" - "github.com/pkg/errors" "github.com/spf13/cobra" ) @@ -35,7 +34,7 @@ func init() { func inspect(cmd *cobra.Command, args []string) error { buf, err := registry.ImageEngine().ManifestInspect(context.Background(), args[0]) if err != nil { - return errors.Wrapf(err, "error inspect manifest %s", args[0]) + return err } fmt.Printf("%s\n", buf) return nil diff --git a/cmd/podman/manifest/push.go b/cmd/podman/manifest/push.go index 9d0977834..593d62710 100644 --- a/cmd/podman/manifest/push.go +++ b/cmd/podman/manifest/push.go @@ -108,7 +108,7 @@ func push(cmd *cobra.Command, args []string) error { manifestPushOpts.SkipTLSVerify = types.NewOptionalBool(!manifestPushOpts.TLSVerifyCLI) } if err := registry.ImageEngine().ManifestPush(registry.Context(), args, manifestPushOpts.ManifestPushOptions); err != nil { - return errors.Wrapf(err, "error pushing manifest %s to %s", listImageSpec, destSpec) + return err } return nil } diff --git a/cmd/podman/pods/create.go b/cmd/podman/pods/create.go index d33455e81..449d60bb9 100644 --- a/cmd/podman/pods/create.go +++ b/cmd/podman/pods/create.go @@ -218,7 +218,7 @@ func create(cmd *cobra.Command, args []string) error { } if len(podIDFile) > 0 { if err = ioutil.WriteFile(podIDFile, []byte(response.Id), 0644); err != nil { - return errors.Wrapf(err, "failed to write pod ID to file %q", podIDFile) + return errors.Wrapf(err, "failed to write pod ID to file") } } fmt.Println(response.Id) diff --git a/cmd/podman/pods/prune.go b/cmd/podman/pods/prune.go index 626ef2895..444b0f5e0 100644 --- a/cmd/podman/pods/prune.go +++ b/cmd/podman/pods/prune.go @@ -12,7 +12,6 @@ import ( "github.com/containers/podman/v2/cmd/podman/utils" "github.com/containers/podman/v2/cmd/podman/validate" "github.com/containers/podman/v2/pkg/domain/entities" - "github.com/pkg/errors" "github.com/spf13/cobra" ) @@ -51,7 +50,7 @@ func prune(cmd *cobra.Command, args []string) error { fmt.Print("Are you sure you want to continue? [y/N] ") answer, err := reader.ReadString('\n') if err != nil { - return errors.Wrapf(err, "error reading input") + return err } if strings.ToLower(answer)[0] != 'y' { return nil diff --git a/cmd/podman/root.go b/cmd/podman/root.go index 0a44f5eac..34d92cd0f 100644 --- a/cmd/podman/root.go +++ b/cmd/podman/root.go @@ -189,8 +189,7 @@ func persistentPreRunE(cmd *cobra.Command, args []string) error { if cmd.Flag("cpu-profile").Changed { f, err := os.Create(cfg.CPUProfile) if err != nil { - return errors.Wrapf(err, "unable to create cpu profiling file %s", - cfg.CPUProfile) + return err } if err := pprof.StartCPUProfile(f); err != nil { return err diff --git a/cmd/podman/system/connection/add.go b/cmd/podman/system/connection/add.go index b3a23bffd..57e747451 100644 --- a/cmd/podman/system/connection/add.go +++ b/cmd/podman/system/connection/add.go @@ -79,14 +79,14 @@ func add(cmd *cobra.Command, args []string) error { // Default to ssh: schema if none given dest := args[1] if match, err := regexp.Match(schemaPattern, []byte(dest)); err != nil { - return errors.Wrapf(err, "internal regex error %q", schemaPattern) + return errors.Wrapf(err, "invalid destination") } else if !match { dest = "ssh://" + dest } uri, err := url.Parse(dest) if err != nil { - return errors.Wrapf(err, "failed to parse %q", dest) + return err } if uri.User.Username() == "" { @@ -109,7 +109,7 @@ func add(cmd *cobra.Command, args []string) error { if uri.Path == "" || uri.Path == "/" { if uri.Path, err = getUDS(cmd, uri); err != nil { - return errors.Wrapf(err, "failed to connect to %q", uri.String()) + return err } } @@ -151,7 +151,7 @@ func getUserInfo(uri *url.URL) (*url.Userinfo, error) { if u, found := os.LookupEnv("_CONTAINERS_ROOTLESS_UID"); found { usr, err = user.LookupId(u) if err != nil { - return nil, errors.Wrapf(err, "failed to find user %q", u) + return nil, errors.Wrapf(err, "failed to lookup rootless user") } } else { usr, err = user.Current() @@ -209,7 +209,7 @@ func getUDS(cmd *cobra.Command, uri *url.URL) (string, error) { } dial, err := ssh.Dial("tcp", uri.Host, cfg) if err != nil { - return "", errors.Wrapf(err, "failed to connect to %q", uri.Host) + return "", errors.Wrapf(err, "failed to connect") } defer dial.Close() @@ -229,7 +229,7 @@ func getUDS(cmd *cobra.Command, uri *url.URL) (string, error) { var buffer bytes.Buffer session.Stdout = &buffer if err := session.Run(run); err != nil { - return "", errors.Wrapf(err, "failed to run %q", run) + return "", err } var info define.Info @@ -238,7 +238,7 @@ func getUDS(cmd *cobra.Command, uri *url.URL) (string, error) { } if info.Host.RemoteSocket == nil || len(info.Host.RemoteSocket.Path) == 0 { - return "", fmt.Errorf("remote podman %q failed to report its UDS socket", uri.Host) + return "", errors.Errorf("remote podman %q failed to report its UDS socket", uri.Host) } return info.Host.RemoteSocket.Path, nil } diff --git a/cmd/podman/system/events.go b/cmd/podman/system/events.go index 224ef89f3..d2aefab67 100644 --- a/cmd/podman/system/events.go +++ b/cmd/podman/system/events.go @@ -13,7 +13,6 @@ import ( "github.com/containers/podman/v2/cmd/podman/validate" "github.com/containers/podman/v2/libpod/events" "github.com/containers/podman/v2/pkg/domain/entities" - "github.com/pkg/errors" "github.com/spf13/cobra" ) @@ -104,7 +103,7 @@ func eventsCmd(cmd *cobra.Command, _ []string) error { case doJSON: jsonStr, err := event.ToJSONString() if err != nil { - return errors.Wrapf(err, "unable to format json") + return err } fmt.Println(jsonStr) case cmd.Flags().Changed("format"): diff --git a/cmd/podman/system/prune.go b/cmd/podman/system/prune.go index be0d60604..f2b9a3db5 100644 --- a/cmd/podman/system/prune.go +++ b/cmd/podman/system/prune.go @@ -12,7 +12,6 @@ import ( "github.com/containers/podman/v2/cmd/podman/utils" "github.com/containers/podman/v2/cmd/podman/validate" "github.com/containers/podman/v2/pkg/domain/entities" - "github.com/pkg/errors" "github.com/spf13/cobra" ) @@ -68,7 +67,7 @@ WARNING! This will remove: Are you sure you want to continue? [y/N] `, volumeString) answer, err := reader.ReadString('\n') if err != nil { - return errors.Wrapf(err, "error reading input") + return err } if strings.ToLower(answer)[0] != 'y' { return nil diff --git a/cmd/podman/system/reset.go b/cmd/podman/system/reset.go index d38a1a427..97f4fba28 100644 --- a/cmd/podman/system/reset.go +++ b/cmd/podman/system/reset.go @@ -13,7 +13,7 @@ import ( "github.com/containers/podman/v2/cmd/podman/validate" "github.com/containers/podman/v2/pkg/domain/entities" "github.com/containers/podman/v2/pkg/domain/infra" - "github.com/pkg/errors" + "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -57,7 +57,7 @@ WARNING! This will remove: Are you sure you want to continue? [y/N] `) answer, err := reader.ReadString('\n') if err != nil { - fmt.Println(errors.Wrapf(err, "error reading input")) + logrus.Error(err) os.Exit(1) } if strings.ToLower(answer)[0] != 'y' { @@ -71,13 +71,13 @@ Are you sure you want to continue? [y/N] `) engine, err := infra.NewSystemEngine(entities.ResetMode, registry.PodmanConfig()) if err != nil { - fmt.Println(err) + logrus.Error(err) os.Exit(125) } defer engine.Shutdown(registry.Context()) if err := engine.Reset(registry.Context()); err != nil { - fmt.Println(err) + logrus.Error(err) os.Exit(125) } os.Exit(0) diff --git a/cmd/podman/system/service_abi.go b/cmd/podman/system/service_abi.go index 95cbd19d9..84f9293d4 100644 --- a/cmd/podman/system/service_abi.go +++ b/cmd/podman/system/service_abi.go @@ -33,7 +33,7 @@ func restService(opts entities.ServiceOptions, flags *pflag.FlagSet, cfg *entiti address := strings.Join(fields[1:], ":") l, err := net.Listen(fields[0], address) if err != nil { - return errors.Wrapf(err, "unable to create socket %s", opts.URI) + return errors.Wrapf(err, "unable to create socket") } listener = &l } diff --git a/cmd/podman/volumes/prune.go b/cmd/podman/volumes/prune.go index 2f58b668f..4c2136dcf 100644 --- a/cmd/podman/volumes/prune.go +++ b/cmd/podman/volumes/prune.go @@ -12,7 +12,6 @@ import ( "github.com/containers/podman/v2/cmd/podman/utils" "github.com/containers/podman/v2/cmd/podman/validate" "github.com/containers/podman/v2/pkg/domain/entities" - "github.com/pkg/errors" "github.com/spf13/cobra" ) @@ -53,7 +52,7 @@ func prune(cmd *cobra.Command, args []string) error { fmt.Print("Are you sure you want to continue? [y/N] ") answer, err := reader.ReadString('\n') if err != nil { - return errors.Wrapf(err, "error reading input") + return err } if strings.ToLower(answer)[0] != 'y' { return nil diff --git a/docs/source/markdown/podman-create.1.md b/docs/source/markdown/podman-create.1.md index 9f2aa1d7b..749af8a66 100644 --- a/docs/source/markdown/podman-create.1.md +++ b/docs/source/markdown/podman-create.1.md @@ -346,7 +346,7 @@ value can be expressed in a time format such as `1m22s`. The default value is ` Container host name -Sets the container host name that is available inside the container. Can only be used with a private UTS namespace `--uts=private` (default). If `--pod` is specified and the pod shares the UTS namespace (default) the pods hostname will be used. +Sets the container host name that is available inside the container. Can only be used with a private UTS namespace `--uts=private` (default). If `--pod` is specified and the pod shares the UTS namespace (default) the pod's hostname will be used. #### **--help** @@ -576,7 +576,7 @@ This works for both background and foreground containers. #### **--network**=*mode*, **--net** -Set the network mode for the container. Invalid if using **--dns**, **--dns-opt**, or **--dns-search** with **--network** that is set to **none** or **container:**_id_. If used together with **--pod**, the container will not join the pods network namespace. +Set the network mode for the container. Invalid if using **--dns**, **--dns-opt**, or **--dns-search** with **--network** that is set to **none** or **container:**_id_. If used together with **--pod**, the container will not join the pod's network namespace. Valid _mode_ values are: diff --git a/docs/source/markdown/podman-run.1.md b/docs/source/markdown/podman-run.1.md index 8c7d713ac..5b2cdd6a5 100644 --- a/docs/source/markdown/podman-run.1.md +++ b/docs/source/markdown/podman-run.1.md @@ -384,7 +384,7 @@ Print usage statement Container host name -Sets the container host name that is available inside the container. Can only be used with a private UTS namespace `--uts=private` (default). If `--pod` is specified and the pod shares the UTS namespace (default) the pods hostname will be used. +Sets the container host name that is available inside the container. Can only be used with a private UTS namespace `--uts=private` (default). If `--pod` is specified and the pod shares the UTS namespace (default) the pod's hostname will be used. #### **--http-proxy**=**true**|**false** diff --git a/libpod/container.go b/libpod/container.go index 580fa7b3d..333e1d848 100644 --- a/libpod/container.go +++ b/libpod/container.go @@ -1,22 +1,18 @@ package libpod import ( + "bytes" "fmt" "io/ioutil" "net" "os" - "path/filepath" - "strings" "time" "github.com/containernetworking/cni/pkg/types" cnitypes "github.com/containernetworking/cni/pkg/types/current" - "github.com/containers/common/pkg/config" "github.com/containers/image/v5/manifest" "github.com/containers/podman/v2/libpod/define" "github.com/containers/podman/v2/libpod/lock" - "github.com/containers/podman/v2/pkg/rootless" - "github.com/containers/podman/v2/utils" "github.com/containers/storage" "github.com/cri-o/ocicni/pkg/ocicni" spec "github.com/opencontainers/runtime-spec/specs-go" @@ -912,44 +908,23 @@ func (c *Container) CgroupManager() string { // CGroupPath returns a cgroups "path" for a given container. func (c *Container) CGroupPath() (string, error) { - cgroupManager := c.CgroupManager() - - switch { - case c.config.NoCgroups || c.config.CgroupsMode == "disabled": + if c.config.NoCgroups || c.config.CgroupsMode == "disabled" { return "", errors.Wrapf(define.ErrNoCgroups, "this container is not creating cgroups") - case c.config.CgroupsMode == cgroupSplit: - if c.config.CgroupParent != "" { - return "", errors.Errorf("cannot specify cgroup-parent with cgroup-mode %q", cgroupSplit) - } - cg, err := utils.GetCgroupProcess(c.state.ConmonPID) - if err != nil { - return "", err - } - // Use the conmon cgroup for two reasons: we validate the container - // delegation was correct, and the conmon cgroup doesn't change at runtime - // while we are not sure about the container that can create sub cgroups. - if !strings.HasSuffix(cg, "supervisor") { - return "", errors.Errorf("invalid cgroup for conmon %q", cg) - } - return strings.TrimSuffix(cg, "/supervisor") + "/container", nil - case cgroupManager == config.CgroupfsCgroupsManager: - return filepath.Join(c.config.CgroupParent, fmt.Sprintf("libpod-%s", c.ID())), nil - case cgroupManager == config.SystemdCgroupsManager: - if rootless.IsRootless() { - uid := rootless.GetRootlessUID() - parts := strings.SplitN(c.config.CgroupParent, "/", 2) - - dir := "" - if len(parts) > 1 { - dir = parts[1] - } + } - return filepath.Join(parts[0], fmt.Sprintf("user-%d.slice/user@%d.service/user.slice/%s", uid, uid, dir), createUnitName("libpod", c.ID())), nil - } - return filepath.Join(c.config.CgroupParent, createUnitName("libpod", c.ID())), nil - default: - return "", errors.Wrapf(define.ErrInvalidArg, "unsupported CGroup manager %s in use", cgroupManager) + // Read /proc/[PID]/cgroup and look at the first line. cgroups(7) + // nails it down to three fields with the 3rd pointing to the cgroup's + // path which works both on v1 and v2. + procPath := fmt.Sprintf("/proc/%d/cgroup", c.state.PID) + lines, err := ioutil.ReadFile(procPath) + if err != nil { + return "", err + } + fields := bytes.Split(bytes.Split(lines, []byte("\n"))[0], []byte(":")) + if len(fields) != 3 { + return "", errors.Errorf("expected 3 fields but got %d: %s", len(fields), procPath) } + return string(fields[2]), nil } // RootFsSize returns the root FS size of the container diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go index 83d5c20cb..b81f3f716 100644 --- a/libpod/container_internal_linux.go +++ b/libpod/container_internal_linux.go @@ -1354,6 +1354,14 @@ func (c *Container) makeBindMounts() error { return err } } + } else { + if !c.config.UseImageHosts && c.state.BindMounts["/etc/hosts"] == "" { + newHosts, err := c.generateHosts("/etc/hosts") + if err != nil { + return errors.Wrapf(err, "error creating hosts file for container %s", c.ID()) + } + c.state.BindMounts["/etc/hosts"] = newHosts + } } // SHM is always added when we mount the container @@ -1614,14 +1622,11 @@ func (c *Container) getHosts() string { } if !hasNetNS { // 127.0.1.1 and host's hostname to match Docker - osHostname, err := os.Hostname() - if err != nil { - osHostname = c.Hostname() - } - hosts += fmt.Sprintf("127.0.1.1 %s\n", osHostname) + osHostname, _ := os.Hostname() + hosts += fmt.Sprintf("127.0.1.1 %s %s %s\n", osHostname, c.Hostname(), c.config.Name) } if netNone { - hosts += fmt.Sprintf("127.0.1.1 %s\n", c.Hostname()) + hosts += fmt.Sprintf("127.0.1.1 %s %s\n", c.Hostname(), c.config.Name) } } } @@ -2091,10 +2096,7 @@ func (c *Container) getOCICgroupPath() (string, error) { logrus.Debugf("Setting CGroups for container %s to %s", c.ID(), systemdCgroups) return systemdCgroups, nil case cgroupManager == config.CgroupfsCgroupsManager: - cgroupPath, err := c.CGroupPath() - if err != nil { - return "", err - } + cgroupPath := filepath.Join(c.config.CgroupParent, fmt.Sprintf("libpod-%s", c.ID())) logrus.Debugf("Setting CGroup path for container %s to %s", c.ID(), cgroupPath) return cgroupPath, nil default: diff --git a/test/e2e/run_networking_test.go b/test/e2e/run_networking_test.go index e9c1bab21..3e80e953e 100644 --- a/test/e2e/run_networking_test.go +++ b/test/e2e/run_networking_test.go @@ -551,6 +551,10 @@ var _ = Describe("Podman run networking", func() { run.WaitWithDefaultTimeout() Expect(run.ExitCode()).To(BeZero()) Expect(run.OutputToString()).To(ContainSubstring(ipAddr)) + + create = podmanTest.Podman([]string{"network", "rm", netName}) + create.WaitWithDefaultTimeout() + Expect(create.ExitCode()).To(BeZero()) }) It("podman run with new:pod and static-ip", func() { @@ -588,7 +592,7 @@ var _ = Describe("Podman run networking", func() { Expect(strings.Contains(run.OutputToString(), hostname)).To(BeTrue()) }) - It("podman run with --net=none adds hostname to /etc/hosts", func() { + It("podman run with --net=none sets hostname", func() { hostname := "testctr" run := podmanTest.Podman([]string{"run", "--net=none", "--hostname", hostname, ALPINE, "hostname"}) run.WaitWithDefaultTimeout() @@ -596,6 +600,37 @@ var _ = Describe("Podman run networking", func() { Expect(strings.Contains(run.OutputToString(), hostname)).To(BeTrue()) }) + It("podman run with --net=none adds hostname to /etc/hosts", func() { + hostname := "testctr" + run := podmanTest.Podman([]string{"run", "--net=none", "--hostname", hostname, ALPINE, "cat", "/etc/hosts"}) + run.WaitWithDefaultTimeout() + Expect(run.ExitCode()).To(BeZero()) + Expect(strings.Contains(run.OutputToString(), hostname)).To(BeTrue()) + }) + + ping_test := func(netns string) { + hostname := "testctr" + run := podmanTest.Podman([]string{"run", netns, "--hostname", hostname, ALPINE, "ping", "-c", "1", hostname}) + run.WaitWithDefaultTimeout() + Expect(run.ExitCode()).To(BeZero()) + + run = podmanTest.Podman([]string{"run", netns, "--hostname", hostname, "--name", "test", ALPINE, "ping", "-c", "1", "test"}) + run.WaitWithDefaultTimeout() + Expect(run.ExitCode()).To(BeZero()) + } + + It("podman attempt to ping container name and hostname --net=none", func() { + ping_test("--net=none") + }) + + It("podman attempt to ping container name and hostname --net=host", func() { + ping_test("--net=host") + }) + + It("podman attempt to ping container name and hostname --net=private", func() { + ping_test("--net=private") + }) + It("podman run check dnsname plugin", func() { pod := "testpod" session := podmanTest.Podman([]string{"pod", "create", "--name", pod}) @@ -621,10 +656,10 @@ var _ = Describe("Podman run networking", func() { session.WaitWithDefaultTimeout() Expect(session.ExitCode()).To(BeZero()) - session = podmanTest.Podman([]string{"run", "--name", "con3", "--pod", pod2, ALPINE, "nslookup", "con3"}) + session = podmanTest.Podman([]string{"run", "--name", "con3", "--pod", pod2, ALPINE, "nslookup", "con1"}) session.WaitWithDefaultTimeout() Expect(session.ExitCode()).To(Equal(1)) - Expect(session.ErrorToString()).To(ContainSubstring("can't resolve 'con3'")) + Expect(session.ErrorToString()).To(ContainSubstring("can't resolve 'con1'")) session = podmanTest.Podman([]string{"run", "--name", "con4", "--network", net, ALPINE, "nslookup", pod2}) session.WaitWithDefaultTimeout() diff --git a/test/e2e/stats_test.go b/test/e2e/stats_test.go index c8f5efa9d..5e8a7a3d0 100644 --- a/test/e2e/stats_test.go +++ b/test/e2e/stats_test.go @@ -5,6 +5,7 @@ package integration import ( "fmt" "os" + "strconv" "time" . "github.com/containers/podman/v2/test/utils" @@ -126,4 +127,44 @@ var _ = Describe("Podman stats", func() { session.WaitWithDefaultTimeout() Expect(session.ExitCode()).To(Equal(0)) }) + + // Regression test for #8265 + It("podman stats with custom memory limits", func() { + // Run thre containers. One with a memory limit. Make sure + // that the limits are different and the limited one has a + // lower limit. + ctrNoLimit0 := "no-limit-0" + ctrNoLimit1 := "no-limit-1" + ctrWithLimit := "with-limit" + + session := podmanTest.Podman([]string{"run", "-d", "--name", ctrNoLimit0, ALPINE, "top"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + session = podmanTest.Podman([]string{"run", "-d", "--name", ctrNoLimit1, ALPINE, "top"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + session = podmanTest.Podman([]string{"run", "-d", "--name", ctrWithLimit, "--memory", "50m", ALPINE, "top"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + session = podmanTest.Podman([]string{"stats", "--no-stream", "--format", "{{.MemLimit}}", ctrNoLimit0, ctrNoLimit1, ctrWithLimit}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + // We have three containers. The unlimited ones need to have + // the same limit, the limited one a lower one. + limits := session.OutputToStringArray() + Expect(len(limits)).To(BeNumerically("==", 3)) + Expect(limits[0]).To(Equal(limits[1])) + Expect(limits[0]).ToNot(Equal(limits[2])) + + defaultLimit, err := strconv.Atoi(limits[0]) + Expect(err).To(BeNil()) + customLimit, err := strconv.Atoi(limits[2]) + Expect(err).To(BeNil()) + + Expect(customLimit).To(BeNumerically("<", defaultLimit)) + }) }) |