summaryrefslogtreecommitdiff
path: root/libpod/pod.go
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 /libpod/pod.go
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 'libpod/pod.go')
-rw-r--r--libpod/pod.go104
1 files changed, 85 insertions, 19 deletions
diff --git a/libpod/pod.go b/libpod/pod.go
index dce2a0c1c..d7a9b15d9 100644
--- a/libpod/pod.go
+++ b/libpod/pod.go
@@ -1,12 +1,14 @@
package libpod
import (
+ "context"
"net"
"time"
"github.com/containers/podman/v3/libpod/define"
"github.com/containers/podman/v3/libpod/lock"
"github.com/cri-o/ocicni/pkg/ocicni"
+ "github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
)
@@ -91,25 +93,26 @@ type podState struct {
// Generally speaking, aside from those two exceptions, these options will set
// the equivalent field in the container's configuration.
type InfraContainerConfig struct {
- ConmonPidFile string `json:"conmonPidFile"`
- HasInfraContainer bool `json:"makeInfraContainer"`
- NoNetwork bool `json:"noNetwork,omitempty"`
- HostNetwork bool `json:"infraHostNetwork,omitempty"`
- PortBindings []ocicni.PortMapping `json:"infraPortBindings"`
- StaticIP net.IP `json:"staticIP,omitempty"`
- StaticMAC net.HardwareAddr `json:"staticMAC,omitempty"`
- UseImageResolvConf bool `json:"useImageResolvConf,omitempty"`
- DNSServer []string `json:"dnsServer,omitempty"`
- DNSSearch []string `json:"dnsSearch,omitempty"`
- DNSOption []string `json:"dnsOption,omitempty"`
- UseImageHosts bool `json:"useImageHosts,omitempty"`
- HostAdd []string `json:"hostsAdd,omitempty"`
- Networks []string `json:"networks,omitempty"`
- ExitCommand []string `json:"exitCommand,omitempty"`
- InfraImage string `json:"infraImage,omitempty"`
- InfraCommand []string `json:"infraCommand,omitempty"`
- Slirp4netns bool `json:"slirp4netns,omitempty"`
- NetworkOptions map[string][]string `json:"network_options,omitempty"`
+ ConmonPidFile string `json:"conmonPidFile"`
+ HasInfraContainer bool `json:"makeInfraContainer"`
+ NoNetwork bool `json:"noNetwork,omitempty"`
+ HostNetwork bool `json:"infraHostNetwork,omitempty"`
+ PortBindings []ocicni.PortMapping `json:"infraPortBindings"`
+ StaticIP net.IP `json:"staticIP,omitempty"`
+ StaticMAC net.HardwareAddr `json:"staticMAC,omitempty"`
+ UseImageResolvConf bool `json:"useImageResolvConf,omitempty"`
+ DNSServer []string `json:"dnsServer,omitempty"`
+ DNSSearch []string `json:"dnsSearch,omitempty"`
+ DNSOption []string `json:"dnsOption,omitempty"`
+ UseImageHosts bool `json:"useImageHosts,omitempty"`
+ HostAdd []string `json:"hostsAdd,omitempty"`
+ Networks []string `json:"networks,omitempty"`
+ ExitCommand []string `json:"exitCommand,omitempty"`
+ InfraImage string `json:"infraImage,omitempty"`
+ InfraCommand []string `json:"infraCommand,omitempty"`
+ Slirp4netns bool `json:"slirp4netns,omitempty"`
+ NetworkOptions map[string][]string `json:"network_options,omitempty"`
+ ResourceLimits *specs.LinuxResources `json:"resource_limits,omitempty"`
}
// ID retrieves the pod's ID
@@ -128,6 +131,45 @@ func (p *Pod) Namespace() string {
return p.config.Namespace
}
+// ResourceLim returns the cpuset resource limits for the pod
+func (p *Pod) ResourceLim() *specs.LinuxResources {
+ resCopy := &specs.LinuxResources{}
+ if err := JSONDeepCopy(p.config.InfraContainer.ResourceLimits, resCopy); err != nil {
+ return nil
+ }
+ if resCopy != nil && resCopy.CPU != nil {
+ return resCopy
+ }
+ empty := &specs.LinuxResources{
+ CPU: &specs.LinuxCPU{},
+ }
+ return empty
+}
+
+// CPUPeriod returns the pod CPU period
+func (p *Pod) CPUPeriod() uint64 {
+ resCopy := &specs.LinuxResources{}
+ if err := JSONDeepCopy(p.config.InfraContainer.ResourceLimits, resCopy); err != nil {
+ return 0
+ }
+ if resCopy != nil && resCopy.CPU != nil && resCopy.CPU.Period != nil {
+ return *resCopy.CPU.Period
+ }
+ return 0
+}
+
+// CPUQuota returns the pod CPU quota
+func (p *Pod) CPUQuota() int64 {
+ resCopy := &specs.LinuxResources{}
+ if err := JSONDeepCopy(p.config.InfraContainer.ResourceLimits, resCopy); err != nil {
+ return 0
+ }
+ if resCopy != nil && resCopy.CPU != nil && resCopy.CPU.Quota != nil {
+ return *resCopy.CPU.Quota
+ }
+ return 0
+}
+
// Labels returns the pod's labels
func (p *Pod) Labels() map[string]string {
labels := make(map[string]string)
@@ -208,7 +250,31 @@ func (p *Pod) CgroupPath() (string, error) {
if err := p.updatePod(); err != nil {
return "", err
}
+ if p.state.CgroupPath != "" {
+ return p.state.CgroupPath, nil
+ }
+ if !p.HasInfraContainer() {
+ return "", errors.Wrap(define.ErrNoSuchCtr, "pod has no infra container")
+ }
+
+ id := p.state.InfraContainerID
+ if id != "" {
+ ctr, err := p.runtime.state.Container(id)
+ if err != nil {
+ return "", errors.Wrapf(err, "could not get infra")
+ }
+ if ctr != nil {
+ ctr.Start(context.Background(), false)
+ cgroupPath, err := ctr.CGroupPath()
+ if err != nil {
+ return "", errors.Wrapf(err, "could not get container cgroup")
+ }
+ p.state.CgroupPath = cgroupPath
+ p.save()
+ return cgroupPath, nil
+ }
+ }
return p.state.CgroupPath, nil
}