mirror of
https://github.com/containers/podman.git
synced 2025-06-20 00:51:16 +08:00
Merge pull request #6415 from vrothberg/systemd-new-pod
podman-generate-systemd --new for pods
This commit is contained in:
@ -18,6 +18,9 @@ type InspectPodData struct {
|
||||
Namespace string `json:"Namespace,omitempty"`
|
||||
// Created is the time when the pod was created.
|
||||
Created time.Time
|
||||
// CreateCommand is the full command plus arguments of the process the
|
||||
// container has been created with.
|
||||
CreateCommand []string `json:"CreateCommand,omitempty"`
|
||||
// State represents the current state of the pod.
|
||||
State string `json:"State"`
|
||||
// Hostname is the hostname that the pod will set.
|
||||
|
@ -1538,6 +1538,30 @@ func WithPodHostname(hostname string) PodCreateOption {
|
||||
}
|
||||
}
|
||||
|
||||
// WithPodCreateCommand adds the full command plus arguments of the current
|
||||
// process to the pod config.
|
||||
func WithPodCreateCommand() PodCreateOption {
|
||||
return func(pod *Pod) error {
|
||||
if pod.valid {
|
||||
return define.ErrPodFinalized
|
||||
}
|
||||
pod.config.CreateCommand = os.Args
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// WithInfraConmonPidFile sets the path to a custom conmon PID file for the
|
||||
// infra container.
|
||||
func WithInfraConmonPidFile(path string) PodCreateOption {
|
||||
return func(pod *Pod) error {
|
||||
if pod.valid {
|
||||
return define.ErrPodFinalized
|
||||
}
|
||||
pod.config.InfraContainer.ConmonPidFile = path
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// WithPodLabels sets the labels of a pod.
|
||||
func WithPodLabels(labels map[string]string) PodCreateOption {
|
||||
return func(pod *Pod) error {
|
||||
|
@ -64,6 +64,10 @@ type PodConfig struct {
|
||||
// Time pod was created
|
||||
CreatedTime time.Time `json:"created"`
|
||||
|
||||
// CreateCommand is the full command plus arguments of the process the
|
||||
// container has been created with.
|
||||
CreateCommand []string `json:"CreateCommand,omitempty"`
|
||||
|
||||
// ID of the pod's lock
|
||||
LockID uint32 `json:"lockID"`
|
||||
}
|
||||
@ -79,6 +83,7 @@ type podState struct {
|
||||
|
||||
// InfraContainerConfig is the configuration for the pod's infra container
|
||||
type InfraContainerConfig struct {
|
||||
ConmonPidFile string `json:"conmonPidFile"`
|
||||
HasInfraContainer bool `json:"makeInfraContainer"`
|
||||
HostNetwork bool `json:"infraHostNetwork,omitempty"`
|
||||
PortBindings []ocicni.PortMapping `json:"infraPortBindings"`
|
||||
@ -124,6 +129,12 @@ func (p *Pod) CreatedTime() time.Time {
|
||||
return p.config.CreatedTime
|
||||
}
|
||||
|
||||
// CreateCommand returns the os.Args of the process with which the pod has been
|
||||
// created.
|
||||
func (p *Pod) CreateCommand() []string {
|
||||
return p.config.CreateCommand
|
||||
}
|
||||
|
||||
// CgroupParent returns the pod's CGroup parent
|
||||
func (p *Pod) CgroupParent() string {
|
||||
return p.config.CgroupParent
|
||||
@ -246,6 +257,20 @@ func (p *Pod) InfraContainerID() (string, error) {
|
||||
return p.state.InfraContainerID, nil
|
||||
}
|
||||
|
||||
// InfraContainer returns the infra container.
|
||||
func (p *Pod) InfraContainer() (*Container, error) {
|
||||
if !p.HasInfraContainer() {
|
||||
return nil, errors.Wrap(define.ErrNoSuchCtr, "pod has no infra container")
|
||||
}
|
||||
|
||||
id, err := p.InfraContainerID()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return p.runtime.state.Container(id)
|
||||
}
|
||||
|
||||
// TODO add pod batching
|
||||
// Lock pod to avoid lock contention
|
||||
// Store and lock all containers (no RemoveContainer in batch guarantees cache will not become stale)
|
||||
|
@ -489,6 +489,7 @@ func (p *Pod) Inspect() (*define.InspectPodData, error) {
|
||||
Name: p.Name(),
|
||||
Namespace: p.Namespace(),
|
||||
Created: p.CreatedTime(),
|
||||
CreateCommand: p.config.CreateCommand,
|
||||
State: podState,
|
||||
Hostname: p.config.Hostname,
|
||||
Labels: p.Labels(),
|
||||
|
@ -130,6 +130,9 @@ func (r *Runtime) makeInfraContainer(ctx context.Context, p *Pod, imgName, rawIm
|
||||
options = append(options, WithRootFSFromImage(imgID, imgName, rawImageName))
|
||||
options = append(options, WithName(containerName))
|
||||
options = append(options, withIsInfra())
|
||||
if len(p.config.InfraContainer.ConmonPidFile) > 0 {
|
||||
options = append(options, WithConmonPidFile(p.config.InfraContainer.ConmonPidFile))
|
||||
}
|
||||
|
||||
return r.newContainer(ctx, g.Config, options...)
|
||||
}
|
||||
|
Reference in New Issue
Block a user