summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/podman/common/inspect.go4
-rw-r--r--cmd/podman/inspect/inspect.go72
-rw-r--r--cmd/podman/pods/inspect.go54
-rw-r--r--go.mod2
-rw-r--r--go.sum3
-rw-r--r--libpod/kube.go15
-rw-r--r--pkg/domain/entities/engine_container.go2
-rw-r--r--pkg/domain/entities/pods.go9
-rw-r--r--pkg/domain/infra/abi/pods.go58
-rw-r--r--pkg/domain/infra/tunnel/pods.go27
-rw-r--r--pkg/specgen/generate/validate.go16
-rw-r--r--test/e2e/common_test.go2
-rw-r--r--test/e2e/generate_kube_test.go6
-rw-r--r--test/e2e/pod_inspect_test.go17
-rw-r--r--test/e2e/run_cpu_test.go16
-rw-r--r--vendor/github.com/docker/go-units/size.go70
-rw-r--r--vendor/modules.txt2
17 files changed, 226 insertions, 149 deletions
diff --git a/cmd/podman/common/inspect.go b/cmd/podman/common/inspect.go
index 12a5af5a9..f82161d31 100644
--- a/cmd/podman/common/inspect.go
+++ b/cmd/podman/common/inspect.go
@@ -11,6 +11,10 @@ const (
NetworkType = "network"
// PodType is the pod type.
PodType = "pod"
+ // PodLegacyType is the pod type for backwards compatibility with the old pod inspect code.
+ // This allows us to use the shared inspect code but still provide the correct output format
+ // when podman pod inspect was called.
+ PodLegacyType = "pod-legacy"
// VolumeType is the volume type
VolumeType = "volume"
)
diff --git a/cmd/podman/inspect/inspect.go b/cmd/podman/inspect/inspect.go
index d519bc7d9..ccabd7614 100644
--- a/cmd/podman/inspect/inspect.go
+++ b/cmd/podman/inspect/inspect.go
@@ -15,7 +15,6 @@ import (
"github.com/containers/podman/v4/cmd/podman/common"
"github.com/containers/podman/v4/cmd/podman/registry"
"github.com/containers/podman/v4/cmd/podman/validate"
- "github.com/containers/podman/v4/libpod/define"
"github.com/containers/podman/v4/pkg/domain/entities"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
@@ -55,18 +54,10 @@ type inspector struct {
containerEngine entities.ContainerEngine
imageEngine entities.ImageEngine
options entities.InspectOptions
- podOptions entities.PodInspectOptions
}
// newInspector creates a new inspector based on the specified options.
func newInspector(options entities.InspectOptions) (*inspector, error) {
- switch options.Type {
- case common.ImageType, common.ContainerType, common.AllType, common.PodType, common.NetworkType, common.VolumeType:
- // Valid types.
- default:
- return nil, fmt.Errorf("invalid type %q: must be %q, %q, %q, %q, %q, or %q", options.Type,
- common.ImageType, common.ContainerType, common.PodType, common.NetworkType, common.VolumeType, common.AllType)
- }
if options.Type == common.ImageType {
if options.Latest {
return nil, fmt.Errorf("latest is not supported for type %q", common.ImageType)
@@ -78,15 +69,10 @@ func newInspector(options entities.InspectOptions) (*inspector, error) {
if options.Type == common.PodType && options.Size {
return nil, fmt.Errorf("size is not supported for type %q", common.PodType)
}
- podOpts := entities.PodInspectOptions{
- Latest: options.Latest,
- Format: options.Format,
- }
return &inspector{
containerEngine: registry.ContainerEngine(),
imageEngine: registry.ImageEngine(),
options: options,
- podOptions: podOpts,
}, nil
}
@@ -140,34 +126,16 @@ func (i *inspector) inspect(namesOrIDs []string) error {
for i := range ctrData {
data = append(data, ctrData[i])
}
- case common.PodType:
- for _, pod := range namesOrIDs {
- i.podOptions.NameOrID = pod
- podData, err := i.containerEngine.PodInspect(ctx, i.podOptions)
- if err != nil {
- if !strings.Contains(err.Error(), define.ErrNoSuchPod.Error()) {
- errs = []error{err}
- } else {
- return err
- }
- } else {
- errs = nil
- data = append(data, podData)
- }
+ case common.PodType, common.PodLegacyType:
+ podData, allErrs, err := i.containerEngine.PodInspect(ctx, namesOrIDs, i.options)
+ if err != nil {
+ return err
}
- if i.podOptions.Latest { // latest means there are no names in the namesOrID array
- podData, err := i.containerEngine.PodInspect(ctx, i.podOptions)
- if err != nil {
- if !strings.Contains(err.Error(), define.ErrNoSuchPod.Error()) {
- errs = []error{err}
- } else {
- return err
- }
- } else {
- errs = nil
- data = append(data, podData)
- }
+ errs = allErrs
+ for i := range podData {
+ data = append(data, podData[i])
}
+
case common.NetworkType:
networkData, allErrs, err := registry.ContainerEngine().NetworkInspect(ctx, namesOrIDs, i.options)
if err != nil {
@@ -198,7 +166,14 @@ func (i *inspector) inspect(namesOrIDs []string) error {
var err error
switch {
case report.IsJSON(i.options.Format) || i.options.Format == "":
- err = printJSON(data)
+ if i.options.Type == common.PodLegacyType && len(data) == 1 {
+ // We need backwards compat with the old podman pod inspect behavior.
+ // https://github.com/containers/podman/pull/15675
+ // TODO (5.0): consider removing this to better match other commands.
+ err = printJSON(data[0])
+ } else {
+ err = printJSON(data)
+ }
default:
// Landing here implies user has given a custom --format
row := inspectNormalize(i.options.Format, tmpType)
@@ -221,7 +196,7 @@ func (i *inspector) inspect(namesOrIDs []string) error {
return nil
}
-func printJSON(data []interface{}) error {
+func printJSON(data interface{}) error {
enc := json.NewEncoder(os.Stdout)
// by default, json marshallers will force utf=8 from
// a string. this breaks healthchecks that use <,>, &&.
@@ -282,14 +257,13 @@ func (i *inspector) inspectAll(ctx context.Context, namesOrIDs []string) ([]inte
data = append(data, networkData[0])
continue
}
- i.podOptions.NameOrID = name
- podData, err := i.containerEngine.PodInspect(ctx, i.podOptions)
+
+ podData, errs, err := i.containerEngine.PodInspect(ctx, []string{name}, i.options)
if err != nil {
- if !strings.Contains(err.Error(), define.ErrNoSuchPod.Error()) {
- return nil, nil, err
- }
- } else {
- data = append(data, podData)
+ return nil, nil, err
+ }
+ if len(errs) == 0 {
+ data = append(data, podData[0])
continue
}
if len(errs) > 0 {
diff --git a/cmd/podman/pods/inspect.go b/cmd/podman/pods/inspect.go
index 082e8d9a1..22e781cdf 100644
--- a/cmd/podman/pods/inspect.go
+++ b/cmd/podman/pods/inspect.go
@@ -1,13 +1,8 @@
package pods
import (
- "context"
- "errors"
- "os"
- "text/template"
-
- "github.com/containers/common/pkg/report"
"github.com/containers/podman/v4/cmd/podman/common"
+ "github.com/containers/podman/v4/cmd/podman/inspect"
"github.com/containers/podman/v4/cmd/podman/registry"
"github.com/containers/podman/v4/cmd/podman/validate"
"github.com/containers/podman/v4/pkg/domain/entities"
@@ -15,10 +10,6 @@ import (
)
var (
- inspectOptions = entities.PodInspectOptions{}
-)
-
-var (
inspectDescription = `Display the configuration for a pod by name or id
By default, this will render all results in a JSON array.`
@@ -27,10 +18,12 @@ var (
Use: "inspect [options] POD [POD...]",
Short: "Displays a pod configuration",
Long: inspectDescription,
- RunE: inspect,
+ RunE: inspectExec,
ValidArgsFunction: common.AutocompletePods,
Example: `podman pod inspect podID`,
}
+
+ inspectOpts = &entities.InspectOptions{}
)
func init() {
@@ -41,40 +34,15 @@ func init() {
flags := inspectCmd.Flags()
formatFlagName := "format"
- flags.StringVarP(&inspectOptions.Format, formatFlagName, "f", "json", "Format the output to a Go template or json")
+ flags.StringVarP(&inspectOpts.Format, formatFlagName, "f", "json", "Format the output to a Go template or json")
_ = inspectCmd.RegisterFlagCompletionFunc(formatFlagName, common.AutocompleteFormat(&entities.PodInspectReport{}))
- validate.AddLatestFlag(inspectCmd, &inspectOptions.Latest)
+ validate.AddLatestFlag(inspectCmd, &inspectOpts.Latest)
}
-func inspect(cmd *cobra.Command, args []string) error {
- if len(args) < 1 && !inspectOptions.Latest {
- return errors.New("you must provide the name or id of a running pod")
- }
- if len(args) > 0 && inspectOptions.Latest {
- return errors.New("--latest and containers cannot be used together")
- }
-
- if !inspectOptions.Latest {
- inspectOptions.NameOrID = args[0]
- }
- responses, err := registry.ContainerEngine().PodInspect(context.Background(), inspectOptions)
- if err != nil {
- return err
- }
-
- if report.IsJSON(inspectOptions.Format) {
- enc := json.NewEncoder(os.Stdout)
- enc.SetIndent("", " ")
- return enc.Encode(responses)
- }
-
- // Cannot use report.New() as it enforces {{range .}} for OriginUser templates
- tmpl := template.New(cmd.Name()).Funcs(template.FuncMap(report.DefaultFuncs))
- format := report.NormalizeFormat(inspectOptions.Format)
- tmpl, err = tmpl.Parse(format)
- if err != nil {
- return err
- }
- return tmpl.Execute(os.Stdout, *responses)
+func inspectExec(cmd *cobra.Command, args []string) error {
+ // We need backwards compat with the old podman pod inspect behavior.
+ // https://github.com/containers/podman/pull/15675
+ inspectOpts.Type = common.PodLegacyType
+ return inspect.Inspect(args, *inspectOpts)
}
diff --git a/go.mod b/go.mod
index 1c2b86b9a..f911af11a 100644
--- a/go.mod
+++ b/go.mod
@@ -26,7 +26,7 @@ require (
github.com/docker/docker v20.10.17+incompatible
github.com/docker/go-connections v0.4.1-0.20210727194412-58542c764a11
github.com/docker/go-plugins-helpers v0.0.0-20211224144127-6eecb7beb651
- github.com/docker/go-units v0.4.0
+ github.com/docker/go-units v0.5.0
github.com/fsnotify/fsnotify v1.5.4
github.com/ghodss/yaml v1.0.0
github.com/godbus/dbus/v5 v5.1.0
diff --git a/go.sum b/go.sum
index 5815deb72..e6459c43d 100644
--- a/go.sum
+++ b/go.sum
@@ -500,8 +500,9 @@ github.com/docker/go-metrics v0.0.1 h1:AgB/0SvBxihN0X8OR4SjsblXkbMvalQ8cjmtKQ2rQ
github.com/docker/go-metrics v0.0.1/go.mod h1:cG1hvH2utMXtqgqqYE9plW6lDxS3/5ayHzueweSI3Vw=
github.com/docker/go-plugins-helpers v0.0.0-20211224144127-6eecb7beb651 h1:YcvzLmdrP/b8kLAGJ8GT7bdncgCAiWxJZIlt84D+RJg=
github.com/docker/go-plugins-helpers v0.0.0-20211224144127-6eecb7beb651/go.mod h1:LFyLie6XcDbyKGeVK6bHe+9aJTYCxWLBg5IrJZOaXKA=
-github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw=
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
+github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
+github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/docker/libtrust v0.0.0-20150114040149-fa567046d9b1/go.mod h1:cyGadeNEkKy96OOhEzfZl+yxihPEzKnqJwvfuSUqbZE=
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 h1:UhxFibDNY/bfvqU5CAUmr9zpesgbU6SWc8/B4mflAE4=
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7/go.mod h1:cyGadeNEkKy96OOhEzfZl+yxihPEzKnqJwvfuSUqbZE=
diff --git a/libpod/kube.go b/libpod/kube.go
index d4414aabd..c7aa4b57d 100644
--- a/libpod/kube.go
+++ b/libpod/kube.go
@@ -470,13 +470,16 @@ func newPodObject(podName string, annotations map[string]string, initCtrs, conta
}
// Set enableServiceLinks to false as podman doesn't use the service port environment variables
enableServiceLinks := false
+ // Set automountServiceAccountToken to false as podman doesn't use service account tokens
+ automountServiceAccountToken := false
ps := v1.PodSpec{
- Containers: containers,
- Hostname: hostname,
- HostNetwork: hostNetwork,
- InitContainers: initCtrs,
- Volumes: volumes,
- EnableServiceLinks: &enableServiceLinks,
+ Containers: containers,
+ Hostname: hostname,
+ HostNetwork: hostNetwork,
+ InitContainers: initCtrs,
+ Volumes: volumes,
+ EnableServiceLinks: &enableServiceLinks,
+ AutomountServiceAccountToken: &automountServiceAccountToken,
}
if dnsOptions != nil && (len(dnsOptions.Nameservers)+len(dnsOptions.Searches)+len(dnsOptions.Options) > 0) {
ps.DNSConfig = dnsOptions
diff --git a/pkg/domain/entities/engine_container.go b/pkg/domain/entities/engine_container.go
index 69adc9732..19b666f8e 100644
--- a/pkg/domain/entities/engine_container.go
+++ b/pkg/domain/entities/engine_container.go
@@ -75,7 +75,7 @@ type ContainerEngine interface {
PodCreate(ctx context.Context, specg PodSpec) (*PodCreateReport, error)
PodClone(ctx context.Context, podClone PodCloneOptions) (*PodCloneReport, error)
PodExists(ctx context.Context, nameOrID string) (*BoolReport, error)
- PodInspect(ctx context.Context, options PodInspectOptions) (*PodInspectReport, error)
+ PodInspect(ctx context.Context, namesOrID []string, options InspectOptions) ([]*PodInspectReport, []error, error)
PodKill(ctx context.Context, namesOrIds []string, options PodKillOptions) ([]*PodKillReport, error)
PodLogs(ctx context.Context, pod string, options PodLogsOptions) error
PodPause(ctx context.Context, namesOrIds []string, options PodPauseOptions) ([]*PodPauseReport, error)
diff --git a/pkg/domain/entities/pods.go b/pkg/domain/entities/pods.go
index b672434d8..55e2fd574 100644
--- a/pkg/domain/entities/pods.go
+++ b/pkg/domain/entities/pods.go
@@ -438,15 +438,6 @@ type PodPSOptions struct {
Sort string
}
-type PodInspectOptions struct {
- Latest bool
-
- // Options for the API.
- NameOrID string
-
- Format string
-}
-
type PodInspectReport struct {
*define.InspectPodData
}
diff --git a/pkg/domain/infra/abi/pods.go b/pkg/domain/infra/abi/pods.go
index 03c8082c4..68f2fa125 100644
--- a/pkg/domain/infra/abi/pods.go
+++ b/pkg/domain/infra/abi/pods.go
@@ -505,23 +505,49 @@ func (ic *ContainerEngine) PodPs(ctx context.Context, options entities.PodPSOpti
return reports, nil
}
-func (ic *ContainerEngine) PodInspect(ctx context.Context, options entities.PodInspectOptions) (*entities.PodInspectReport, error) {
- var (
- pod *libpod.Pod
- err error
- )
- // Look up the pod.
+func (ic *ContainerEngine) PodInspect(ctx context.Context, nameOrIDs []string, options entities.InspectOptions) ([]*entities.PodInspectReport, []error, error) {
if options.Latest {
- pod, err = ic.Libpod.GetLatestPod()
- } else {
- pod, err = ic.Libpod.LookupPod(options.NameOrID)
- }
- if err != nil {
- return nil, fmt.Errorf("unable to look up requested container: %w", err)
+ pod, err := ic.Libpod.GetLatestPod()
+ if err != nil {
+ return nil, nil, err
+ }
+ inspect, err := pod.Inspect()
+ if err != nil {
+ return nil, nil, err
+ }
+
+ return []*entities.PodInspectReport{
+ {
+ InspectPodData: inspect,
+ },
+ }, nil, nil
}
- inspect, err := pod.Inspect()
- if err != nil {
- return nil, err
+
+ var errs []error
+ podReport := make([]*entities.PodInspectReport, 0, len(nameOrIDs))
+ for _, name := range nameOrIDs {
+ pod, err := ic.Libpod.LookupPod(name)
+ if err != nil {
+ // ErrNoSuchPod is non-fatal, other errors will be
+ // treated as fatal.
+ if errors.Is(err, define.ErrNoSuchPod) {
+ errs = append(errs, fmt.Errorf("no such pod %s", name))
+ continue
+ }
+ return nil, nil, err
+ }
+
+ inspect, err := pod.Inspect()
+ if err != nil {
+ // ErrNoSuchPod is non-fatal, other errors will be
+ // treated as fatal.
+ if errors.Is(err, define.ErrNoSuchPod) {
+ errs = append(errs, fmt.Errorf("no such pod %s", name))
+ continue
+ }
+ return nil, nil, err
+ }
+ podReport = append(podReport, &entities.PodInspectReport{InspectPodData: inspect})
}
- return &entities.PodInspectReport{InspectPodData: inspect}, nil
+ return podReport, errs, nil
}
diff --git a/pkg/domain/infra/tunnel/pods.go b/pkg/domain/infra/tunnel/pods.go
index bcbd32d1b..f9314dcfe 100644
--- a/pkg/domain/infra/tunnel/pods.go
+++ b/pkg/domain/infra/tunnel/pods.go
@@ -3,10 +3,12 @@ package tunnel
import (
"context"
"errors"
+ "fmt"
"github.com/containers/podman/v4/libpod/define"
"github.com/containers/podman/v4/pkg/bindings/pods"
"github.com/containers/podman/v4/pkg/domain/entities"
+ "github.com/containers/podman/v4/pkg/errorhandling"
"github.com/containers/podman/v4/pkg/util"
)
@@ -223,14 +225,25 @@ func (ic *ContainerEngine) PodPs(ctx context.Context, opts entities.PodPSOptions
return pods.List(ic.ClientCtx, options)
}
-func (ic *ContainerEngine) PodInspect(ctx context.Context, options entities.PodInspectOptions) (*entities.PodInspectReport, error) {
- switch {
- case options.Latest:
- return nil, errors.New("latest is not supported")
- case options.NameOrID == "":
- return nil, errors.New("NameOrID must be specified")
+func (ic *ContainerEngine) PodInspect(ctx context.Context, namesOrIDs []string, options entities.InspectOptions) ([]*entities.PodInspectReport, []error, error) {
+ var errs []error
+ podReport := make([]*entities.PodInspectReport, 0, len(namesOrIDs))
+ for _, name := range namesOrIDs {
+ inspect, err := pods.Inspect(ic.ClientCtx, name, nil)
+ if err != nil {
+ errModel, ok := err.(*errorhandling.ErrorModel)
+ if !ok {
+ return nil, nil, err
+ }
+ if errModel.ResponseCode == 404 {
+ errs = append(errs, fmt.Errorf("no such pod %q", name))
+ continue
+ }
+ return nil, nil, err
+ }
+ podReport = append(podReport, inspect)
}
- return pods.Inspect(ic.ClientCtx, options.NameOrID, nil)
+ return podReport, errs, nil
}
func (ic *ContainerEngine) PodStats(ctx context.Context, namesOrIds []string, opts entities.PodStatsOptions) ([]*entities.PodStatsReport, error) {
diff --git a/pkg/specgen/generate/validate.go b/pkg/specgen/generate/validate.go
index 3c5d5fb96..e9ebdfce3 100644
--- a/pkg/specgen/generate/validate.go
+++ b/pkg/specgen/generate/validate.go
@@ -82,7 +82,7 @@ func verifyContainerResourcesCgroupV1(s *specgen.SpecGenerator) ([]string, error
}
}
- // CPU Checks
+ // CPU checks
if s.ResourceLimits.CPU != nil {
cpu := s.ResourceLimits.CPU
if cpu.Shares != nil && !sysInfo.CPUShares {
@@ -169,6 +169,7 @@ func verifyContainerResourcesCgroupV2(s *specgen.SpecGenerator) ([]string, error
return warnings, nil
}
+ // Memory checks
if s.ResourceLimits.Memory != nil && s.ResourceLimits.Memory.Swap != nil {
own, err := utils.GetOwnCgroup()
if err != nil {
@@ -198,6 +199,19 @@ func verifyContainerResourcesCgroupV2(s *specgen.SpecGenerator) ([]string, error
s.ResourceLimits.Memory.Swap = nil
}
}
+
+ // CPU checks
+ if s.ResourceLimits.CPU != nil {
+ cpu := s.ResourceLimits.CPU
+ if cpu.RealtimePeriod != nil {
+ warnings = append(warnings, "Realtime period not supported on cgroups V2 systems")
+ cpu.RealtimePeriod = nil
+ }
+ if cpu.RealtimeRuntime != nil {
+ warnings = append(warnings, "Realtime runtime not supported on cgroups V2 systems")
+ cpu.RealtimeRuntime = nil
+ }
+ }
return warnings, nil
}
diff --git a/test/e2e/common_test.go b/test/e2e/common_test.go
index 2d7c47a7f..8fe89f32e 100644
--- a/test/e2e/common_test.go
+++ b/test/e2e/common_test.go
@@ -571,7 +571,7 @@ func (s *PodmanSessionIntegration) InspectContainerToJSON() []define.InspectCont
func (s *PodmanSessionIntegration) InspectPodToJSON() define.InspectPodData {
var i define.InspectPodData
err := jsoniter.Unmarshal(s.Out.Contents(), &i)
- Expect(err).To(BeNil())
+ Expect(err).ToNot(HaveOccurred())
return i
}
diff --git a/test/e2e/generate_kube_test.go b/test/e2e/generate_kube_test.go
index 960837ebe..39acff6dc 100644
--- a/test/e2e/generate_kube_test.go
+++ b/test/e2e/generate_kube_test.go
@@ -73,6 +73,8 @@ var _ = Describe("Podman generate kube", func() {
Expect(pod).To(HaveField("Name", "top-pod"))
enableServiceLinks := false
Expect(pod.Spec).To(HaveField("EnableServiceLinks", &enableServiceLinks))
+ automountServiceAccountToken := false
+ Expect(pod.Spec).To(HaveField("AutomountServiceAccountToken", &automountServiceAccountToken))
numContainers := 0
for range pod.Spec.Containers {
@@ -169,6 +171,8 @@ var _ = Describe("Podman generate kube", func() {
Expect(pod.Spec).To(HaveField("HostNetwork", false))
enableServiceLinks := false
Expect(pod.Spec).To(HaveField("EnableServiceLinks", &enableServiceLinks))
+ automountServiceAccountToken := false
+ Expect(pod.Spec).To(HaveField("AutomountServiceAccountToken", &automountServiceAccountToken))
numContainers := 0
for range pod.Spec.Containers {
@@ -501,7 +505,7 @@ var _ = Describe("Podman generate kube", func() {
Expect(podSession).Should(Exit(0))
ctr1Name := "ctr1"
- ctr1Session := podmanTest.Podman([]string{"create", "--name", ctr1Name, "--pod", podName, "--memory", "10Mi", ALPINE, "top"})
+ ctr1Session := podmanTest.Podman([]string{"create", "--name", ctr1Name, "--pod", podName, "--memory", "10M", ALPINE, "top"})
ctr1Session.WaitWithDefaultTimeout()
Expect(ctr1Session).Should(Exit(0))
diff --git a/test/e2e/pod_inspect_test.go b/test/e2e/pod_inspect_test.go
index 351317cc5..cefdee40a 100644
--- a/test/e2e/pod_inspect_test.go
+++ b/test/e2e/pod_inspect_test.go
@@ -118,4 +118,21 @@ var _ = Describe("Podman pod inspect", func() {
Expect(inspectOut.OutputToString()).To(ContainSubstring(macAddr))
})
+
+ It("podman inspect two pods", func() {
+ _, ec, podid1 := podmanTest.CreatePod(nil)
+ Expect(ec).To(Equal(0))
+
+ _, ec, podid2 := podmanTest.CreatePod(nil)
+ Expect(ec).To(Equal(0))
+
+ inspect := podmanTest.Podman([]string{"pod", "inspect", podid1, podid2})
+ inspect.WaitWithDefaultTimeout()
+ Expect(inspect).Should(Exit(0))
+ Expect(inspect.OutputToString()).To(BeValidJSON())
+ podData := inspect.InspectPodArrToJSON()
+ Expect(podData).To(HaveLen(2))
+ Expect(podData[0]).To(HaveField("ID", podid1))
+ Expect(podData[1]).To(HaveField("ID", podid2))
+ })
})
diff --git a/test/e2e/run_cpu_test.go b/test/e2e/run_cpu_test.go
index e57eb3b26..19bb735ff 100644
--- a/test/e2e/run_cpu_test.go
+++ b/test/e2e/run_cpu_test.go
@@ -138,4 +138,20 @@ var _ = Describe("Podman run cpu", func() {
result.WaitWithDefaultTimeout()
Expect(result).To(ExitWithError())
})
+
+ It("podman run invalid cpu-rt-period with cgroupsv2", func() {
+ SkipIfCgroupV1("testing options that only work in cgroup v2")
+ result := podmanTest.Podman([]string{"run", "--rm", "--cpu-rt-period=5000", ALPINE, "ls"})
+ result.WaitWithDefaultTimeout()
+ Expect(result).Should(Exit(0))
+ Expect(result.ErrorToString()).To(ContainSubstring("Realtime period not supported on cgroups V2 systems"))
+ })
+
+ It("podman run invalid cpu-rt-runtime with cgroupsv2", func() {
+ SkipIfCgroupV1("testing options that only work in cgroup v2")
+ result := podmanTest.Podman([]string{"run", "--rm", "--cpu-rt-runtime=5000", ALPINE, "ls"})
+ result.WaitWithDefaultTimeout()
+ Expect(result).Should(Exit(0))
+ Expect(result.ErrorToString()).To(ContainSubstring("Realtime runtime not supported on cgroups V2 systems"))
+ })
})
diff --git a/vendor/github.com/docker/go-units/size.go b/vendor/github.com/docker/go-units/size.go
index 85f6ab071..c245a8951 100644
--- a/vendor/github.com/docker/go-units/size.go
+++ b/vendor/github.com/docker/go-units/size.go
@@ -2,7 +2,6 @@ package units
import (
"fmt"
- "regexp"
"strconv"
"strings"
)
@@ -26,16 +25,17 @@ const (
PiB = 1024 * TiB
)
-type unitMap map[string]int64
+type unitMap map[byte]int64
var (
- decimalMap = unitMap{"k": KB, "m": MB, "g": GB, "t": TB, "p": PB}
- binaryMap = unitMap{"k": KiB, "m": MiB, "g": GiB, "t": TiB, "p": PiB}
- sizeRegex = regexp.MustCompile(`^(\d+(\.\d+)*) ?([kKmMgGtTpP])?[iI]?[bB]?$`)
+ decimalMap = unitMap{'k': KB, 'm': MB, 'g': GB, 't': TB, 'p': PB}
+ binaryMap = unitMap{'k': KiB, 'm': MiB, 'g': GiB, 't': TiB, 'p': PiB}
)
-var decimapAbbrs = []string{"B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"}
-var binaryAbbrs = []string{"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"}
+var (
+ decimapAbbrs = []string{"B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"}
+ binaryAbbrs = []string{"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"}
+)
func getSizeAndUnit(size float64, base float64, _map []string) (float64, string) {
i := 0
@@ -89,20 +89,66 @@ func RAMInBytes(size string) (int64, error) {
// Parses the human-readable size string into the amount it represents.
func parseSize(sizeStr string, uMap unitMap) (int64, error) {
- matches := sizeRegex.FindStringSubmatch(sizeStr)
- if len(matches) != 4 {
+ // TODO: rewrite to use strings.Cut if there's a space
+ // once Go < 1.18 is deprecated.
+ sep := strings.LastIndexAny(sizeStr, "01234567890. ")
+ if sep == -1 {
+ // There should be at least a digit.
return -1, fmt.Errorf("invalid size: '%s'", sizeStr)
}
+ var num, sfx string
+ if sizeStr[sep] != ' ' {
+ num = sizeStr[:sep+1]
+ sfx = sizeStr[sep+1:]
+ } else {
+ // Omit the space separator.
+ num = sizeStr[:sep]
+ sfx = sizeStr[sep+1:]
+ }
- size, err := strconv.ParseFloat(matches[1], 64)
+ size, err := strconv.ParseFloat(num, 64)
if err != nil {
return -1, err
}
+ // Backward compatibility: reject negative sizes.
+ if size < 0 {
+ return -1, fmt.Errorf("invalid size: '%s'", sizeStr)
+ }
+
+ if len(sfx) == 0 {
+ return int64(size), nil
+ }
- unitPrefix := strings.ToLower(matches[3])
- if mul, ok := uMap[unitPrefix]; ok {
+ // Process the suffix.
+
+ if len(sfx) > 3 { // Too long.
+ goto badSuffix
+ }
+ sfx = strings.ToLower(sfx)
+ // Trivial case: b suffix.
+ if sfx[0] == 'b' {
+ if len(sfx) > 1 { // no extra characters allowed after b.
+ goto badSuffix
+ }
+ return int64(size), nil
+ }
+ // A suffix from the map.
+ if mul, ok := uMap[sfx[0]]; ok {
size *= float64(mul)
+ } else {
+ goto badSuffix
+ }
+
+ // The suffix may have extra "b" or "ib" (e.g. KiB or MB).
+ switch {
+ case len(sfx) == 2 && sfx[1] != 'b':
+ goto badSuffix
+ case len(sfx) == 3 && sfx[1:] != "ib":
+ goto badSuffix
}
return int64(size), nil
+
+badSuffix:
+ return -1, fmt.Errorf("invalid suffix: '%s'", sfx)
}
diff --git a/vendor/modules.txt b/vendor/modules.txt
index f1d4758e4..26727842b 100644
--- a/vendor/modules.txt
+++ b/vendor/modules.txt
@@ -397,7 +397,7 @@ github.com/docker/go-metrics
## explicit
github.com/docker/go-plugins-helpers/sdk
github.com/docker/go-plugins-helpers/volume
-# github.com/docker/go-units v0.4.0
+# github.com/docker/go-units v0.5.0
## explicit
github.com/docker/go-units
# github.com/felixge/httpsnoop v1.0.1