diff options
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/api/handlers/types.go | 1 | ||||
-rw-r--r-- | pkg/domain/entities/pods.go | 2 | ||||
-rw-r--r-- | pkg/domain/infra/abi/containers.go | 47 | ||||
-rw-r--r-- | pkg/domain/infra/tunnel/containers.go | 26 | ||||
-rw-r--r-- | pkg/specgen/generate/pod_create.go | 4 | ||||
-rw-r--r-- | pkg/specgen/pod_validate.go | 3 | ||||
-rw-r--r-- | pkg/specgen/podspecgen.go | 6 |
7 files changed, 62 insertions, 27 deletions
diff --git a/pkg/api/handlers/types.go b/pkg/api/handlers/types.go index 59f948567..3cc10d70f 100644 --- a/pkg/api/handlers/types.go +++ b/pkg/api/handlers/types.go @@ -133,6 +133,7 @@ type PodCreateConfig struct { Infra bool `json:"infra"` InfraCommand string `json:"infra-command"` InfraImage string `json:"infra-image"` + InfraName string `json:"infra-name"` Labels []string `json:"labels"` Publish []string `json:"publish"` Share string `json:"share"` diff --git a/pkg/domain/entities/pods.go b/pkg/domain/entities/pods.go index a0a2a1790..68e335f8d 100644 --- a/pkg/domain/entities/pods.go +++ b/pkg/domain/entities/pods.go @@ -112,6 +112,7 @@ type PodCreateOptions struct { Hostname string Infra bool InfraImage string + InfraName string InfraCommand string InfraConmonPidFile string Labels map[string]string @@ -172,6 +173,7 @@ func (p *PodCreateOptions) ToPodSpecGen(s *specgen.PodSpecGenerator) error { s.InfraConmonPidFile = p.InfraConmonPidFile } s.InfraImage = p.InfraImage + s.InfraName = p.InfraName s.SharedNamespaces = p.Share s.PodCreateCommand = p.CreateCommand diff --git a/pkg/domain/infra/abi/containers.go b/pkg/domain/infra/abi/containers.go index 2c5300ccb..50751aa12 100644 --- a/pkg/domain/infra/abi/containers.go +++ b/pkg/domain/infra/abi/containers.go @@ -261,6 +261,24 @@ func (ic *ContainerEngine) ContainerRestart(ctx context.Context, namesOrIds []st return reports, nil } +func (ic *ContainerEngine) removeContainer(ctx context.Context, ctr *libpod.Container, options entities.RmOptions) error { + err := ic.Libpod.RemoveContainer(ctx, ctr, options.Force, options.Volumes) + if err == nil { + return nil + } + logrus.Debugf("Failed to remove container %s: %s", ctr.ID(), err.Error()) + switch errors.Cause(err) { + case define.ErrNoSuchCtr: + if options.Ignore { + logrus.Debugf("Ignoring error (--allow-missing): %v", err) + return nil + } + case define.ErrCtrRemoved: + return nil + } + return err +} + func (ic *ContainerEngine) ContainerRm(ctx context.Context, namesOrIds []string, options entities.RmOptions) ([]*entities.RmReport, error) { reports := []*entities.RmReport{} @@ -318,21 +336,7 @@ func (ic *ContainerEngine) ContainerRm(ctx context.Context, namesOrIds []string, } errMap, err := parallelctr.ContainerOp(ctx, ctrs, func(c *libpod.Container) error { - err := ic.Libpod.RemoveContainer(ctx, c, options.Force, options.Volumes) - if err == nil { - return nil - } - logrus.Debugf("Failed to remove container %s: %s", c.ID(), err.Error()) - switch errors.Cause(err) { - case define.ErrNoSuchCtr: - if options.Ignore { - logrus.Debugf("Ignoring error (--allow-missing): %v", err) - return nil - } - case define.ErrCtrRemoved: - return nil - } - return err + return ic.removeContainer(ctx, c, options) }) if err != nil { return nil, err @@ -791,6 +795,11 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri Err: err, ExitCode: exitCode, }) + if ctr.AutoRemove() { + if err := ic.removeContainer(ctx, ctr, entities.RmOptions{}); err != nil { + logrus.Errorf("Error removing container %s: %v", ctr.ID(), err) + } + } return reports, errors.Wrapf(err, "unable to start container %s", ctr.ID()) } @@ -827,9 +836,6 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri ExitCode: 125, } if err := ctr.Start(ctx, true); err != nil { - // if lastError != nil { - // fmt.Fprintln(os.Stderr, lastError) - // } report.Err = err if errors.Cause(err) == define.ErrWillDeadlock { report.Err = errors.Wrapf(err, "please run 'podman system renumber' to resolve deadlocks") @@ -838,6 +844,11 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri } report.Err = errors.Wrapf(err, "unable to start container %q", ctr.ID()) reports = append(reports, report) + if ctr.AutoRemove() { + if err := ic.removeContainer(ctx, ctr, entities.RmOptions{}); err != nil { + logrus.Errorf("Error removing container %s: %v", ctr.ID(), err) + } + } continue } report.ExitCode = 0 diff --git a/pkg/domain/infra/tunnel/containers.go b/pkg/domain/infra/tunnel/containers.go index 56315f46f..c17d7b54f 100644 --- a/pkg/domain/infra/tunnel/containers.go +++ b/pkg/domain/infra/tunnel/containers.go @@ -541,6 +541,17 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri return nil, err } removeOptions := new(containers.RemoveOptions).WithVolumes(true).WithForce(false) + removeContainer := func(id string) { + if err := containers.Remove(ic.ClientCtx, id, removeOptions); err != nil { + if errorhandling.Contains(err, define.ErrNoSuchCtr) || + errorhandling.Contains(err, define.ErrCtrRemoved) { + logrus.Debugf("Container %s does not exist: %v", id, err) + } else { + logrus.Errorf("Error removing container %s: %v", id, err) + } + } + } + // There can only be one container if attach was used for i, ctr := range ctrs { name := ctr.ID @@ -568,6 +579,9 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri } if err != nil { + if ctr.AutoRemove { + removeContainer(ctr.ID) + } report.ExitCode = define.ExitCode(report.Err) report.Err = err reports = append(reports, &report) @@ -582,16 +596,10 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri logrus.Errorf("Failed to check if %s should restart: %v", ctr.ID, err) return } + logrus.Errorf("Should restart: %v", shouldRestart) - if !shouldRestart { - if err := containers.Remove(ic.ClientCtx, ctr.ID, removeOptions); err != nil { - if errorhandling.Contains(err, define.ErrNoSuchCtr) || - errorhandling.Contains(err, define.ErrCtrRemoved) { - logrus.Debugf("Container %s does not exist: %v", ctr.ID, err) - } else { - logrus.Errorf("Error removing container %s: %v", ctr.ID, err) - } - } + if !shouldRestart && ctr.AutoRemove { + removeContainer(ctr.ID) } }() } diff --git a/pkg/specgen/generate/pod_create.go b/pkg/specgen/generate/pod_create.go index 4ffd8a37f..aab29499e 100644 --- a/pkg/specgen/generate/pod_create.go +++ b/pkg/specgen/generate/pod_create.go @@ -98,6 +98,10 @@ func createPodOptions(p *specgen.PodSpecGenerator, rt *libpod.Runtime) ([]libpod options = append(options, libpod.WithInfraImage(p.InfraImage)) } + if len(p.InfraName) > 0 { + options = append(options, libpod.WithInfraName(p.InfraName)) + } + if len(p.InfraCommand) > 0 { options = append(options, libpod.WithInfraCommand(p.InfraCommand)) } diff --git a/pkg/specgen/pod_validate.go b/pkg/specgen/pod_validate.go index c746bcd1a..bca7b6dbe 100644 --- a/pkg/specgen/pod_validate.go +++ b/pkg/specgen/pod_validate.go @@ -36,6 +36,9 @@ func (p *PodSpecGenerator) Validate() error { if len(p.InfraImage) > 0 { return exclusivePodOptions("NoInfra", "InfraImage") } + if len(p.InfraName) > 0 { + return exclusivePodOptions("NoInfra", "InfraName") + } if len(p.SharedNamespaces) > 0 { return exclusivePodOptions("NoInfra", "SharedNamespaces") } diff --git a/pkg/specgen/podspecgen.go b/pkg/specgen/podspecgen.go index 319345c71..02237afe9 100644 --- a/pkg/specgen/podspecgen.go +++ b/pkg/specgen/podspecgen.go @@ -43,6 +43,12 @@ type PodBasicConfig struct { // Conflicts with NoInfra=true. // Optional. InfraImage string `json:"infra_image,omitempty"` + // InfraName is the name that will be used for the infra container. + // If not set, the default set in the Libpod configuration file will be + // used. + // Conflicts with NoInfra=true. + // Optional. + InfraName string `json:"infra_name,omitempty"` // SharedNamespaces instructs the pod to share a set of namespaces. // Shared namespaces will be joined (by default) by every container // which joins the pod. |