summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorcdoern <cbdoer23@g.holycross.edu>2021-06-17 17:36:35 -0400
committercdoern <cbdoer23@g.holycross.edu>2021-06-23 13:47:57 -0400
commitbbd085ad1e3cf9c5b543c907ad7014ccf8a5cb34 (patch)
tree14dd2d240f32586a624f6a786d8127b8bfb95017 /cmd
parent510509bafcdd055b4a6819ed300db7292c6fb6b8 (diff)
downloadpodman-bbd085ad1e3cf9c5b543c907ad7014ccf8a5cb34.tar.gz
podman-bbd085ad1e3cf9c5b543c907ad7014ccf8a5cb34.tar.bz2
podman-bbd085ad1e3cf9c5b543c907ad7014ccf8a5cb34.zip
Podman Pod Create --cpus and --cpuset-cpus flags
Added logic and handling for two new Podman pod create Flags. --cpus specifies the total number of cores on which the pod can execute, this is a combination of the period and quota for the CPU. --cpuset-cpus is a string value which determines of these available cores, how many we will truly execute on. Signed-off-by: cdoern <cbdoer23@g.holycross.edu>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/containers/create.go3
-rw-r--r--cmd/podman/pods/create.go53
2 files changed, 55 insertions, 1 deletions
diff --git a/cmd/podman/containers/create.go b/cmd/podman/containers/create.go
index 68a17abd0..ecaef5c0a 100644
--- a/cmd/podman/containers/create.go
+++ b/cmd/podman/containers/create.go
@@ -225,7 +225,6 @@ func createInit(c *cobra.Command) error {
}
cliVals.Env = env
}
-
if c.Flag("cgroups").Changed && cliVals.CGroupsMode == "split" && registry.IsRemote() {
return errors.Errorf("the option --cgroups=%q is not supported in remote mode", cliVals.CGroupsMode)
}
@@ -316,6 +315,8 @@ func createPodIfNecessary(s *specgen.SpecGenerator, netOpts *entities.NetOptions
Net: netOpts,
CreateCommand: os.Args,
Hostname: s.ContainerBasicConfig.Hostname,
+ Cpus: cliVals.CPUS,
+ CpusetCpus: cliVals.CPUSetCPUs,
}
// Unset config values we passed to the pod to prevent them being used twice for the container and pod.
s.ContainerBasicConfig.Hostname = ""
diff --git a/cmd/podman/pods/create.go b/cmd/podman/pods/create.go
index 735dfa78c..03e3ffaa0 100644
--- a/cmd/podman/pods/create.go
+++ b/cmd/podman/pods/create.go
@@ -5,9 +5,13 @@ import (
"fmt"
"io/ioutil"
"os"
+ "runtime"
+ "sort"
+ "strconv"
"strings"
"github.com/containers/common/pkg/completion"
+ "github.com/containers/common/pkg/sysinfo"
"github.com/containers/podman/v3/cmd/podman/common"
"github.com/containers/podman/v3/cmd/podman/parse"
"github.com/containers/podman/v3/cmd/podman/registry"
@@ -16,6 +20,7 @@ import (
"github.com/containers/podman/v3/pkg/errorhandling"
"github.com/containers/podman/v3/pkg/specgen"
"github.com/containers/podman/v3/pkg/util"
+ "github.com/docker/docker/pkg/parsers"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
@@ -55,6 +60,14 @@ func init() {
common.DefineNetFlags(createCommand)
+ cpusetflagName := "cpuset-cpus"
+ flags.StringVar(&createOptions.CpusetCpus, cpusetflagName, "", "CPUs in which to allow execution")
+ _ = createCommand.RegisterFlagCompletionFunc(cpusetflagName, completion.AutocompleteDefault)
+
+ cpusflagName := "cpus"
+ flags.Float64Var(&createOptions.Cpus, cpusflagName, 0.000, "set amount of CPUs for the pod")
+ _ = createCommand.RegisterFlagCompletionFunc(cpusflagName, completion.AutocompleteDefault)
+
cgroupParentflagName := "cgroup-parent"
flags.StringVar(&createOptions.CGroupParent, cgroupParentflagName, "", "Set parent cgroup for the pod")
_ = createCommand.RegisterFlagCompletionFunc(cgroupParentflagName, completion.AutocompleteDefault)
@@ -185,6 +198,46 @@ func create(cmd *cobra.Command, args []string) error {
}
}
+ numCPU := sysinfo.NumCPU()
+ if numCPU == 0 {
+ numCPU = runtime.NumCPU()
+ }
+ if createOptions.Cpus > float64(numCPU) {
+ createOptions.Cpus = float64(numCPU)
+ }
+ copy := createOptions.CpusetCpus
+ cpuSet := createOptions.Cpus
+ if cpuSet == 0 {
+ cpuSet = float64(sysinfo.NumCPU())
+ }
+ ret, err := parsers.ParseUintList(copy)
+ copy = ""
+ if err != nil {
+ errors.Wrapf(err, "could not parse list")
+ }
+ var vals []int
+ for ind, val := range ret {
+ if val {
+ vals = append(vals, ind)
+ }
+ }
+ sort.Ints(vals)
+ for ind, core := range vals {
+ if core > int(cpuSet) {
+ if copy == "" {
+ copy = "0-" + strconv.Itoa(int(cpuSet))
+ createOptions.CpusetCpus = copy
+ break
+ } else {
+ createOptions.CpusetCpus = copy
+ break
+ }
+ } else if ind != 0 {
+ copy += "," + strconv.Itoa(core)
+ } else {
+ copy = "" + strconv.Itoa(core)
+ }
+ }
response, err := registry.ContainerEngine().PodCreate(context.Background(), createOptions)
if err != nil {
return err