summaryrefslogtreecommitdiff
path: root/pkg/adapter/containers.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/adapter/containers.go')
-rw-r--r--pkg/adapter/containers.go33
1 files changed, 23 insertions, 10 deletions
diff --git a/pkg/adapter/containers.go b/pkg/adapter/containers.go
index c2206caad..8b21d6b94 100644
--- a/pkg/adapter/containers.go
+++ b/pkg/adapter/containers.go
@@ -375,7 +375,7 @@ func (r *LocalRuntime) selectDetachKeys(flagValue string) (string, error) {
config, err := r.GetConfig()
if err != nil {
- return "", errors.Wrapf(err, "unable to retrive runtime config")
+ return "", errors.Wrapf(err, "unable to retrieve runtime config")
}
if config.DetachKeys != "" {
return config.DetachKeys, nil
@@ -609,11 +609,12 @@ func (r *LocalRuntime) Restore(ctx context.Context, c *cliconfig.RestoreValues)
return state == define.ContainerStateExited
})
- if c.Import != "" {
+ switch {
+ case c.Import != "":
containers, err = crImportCheckpoint(ctx, r.Runtime, c.Import, c.Name)
- } else if c.All {
+ case c.All:
containers, err = r.GetContainers(filterFuncs...)
- } else {
+ default:
containers, err = shortcuts.GetContainersByContext(false, c.Latest, c.InputArgs, r.Runtime)
}
if err != nil {
@@ -835,25 +836,26 @@ func (r *LocalRuntime) Restart(ctx context.Context, c *cliconfig.RestartValues)
inputTimeout := c.Timeout
// Handle --latest
- if c.Latest {
+ switch {
+ case c.Latest:
lastCtr, err := r.Runtime.GetLatestContainer()
if err != nil {
return nil, nil, errors.Wrapf(err, "unable to get latest container")
}
restartContainers = append(restartContainers, lastCtr)
- } else if c.Running {
+ case c.Running:
containers, err = r.GetRunningContainers()
if err != nil {
return nil, nil, err
}
restartContainers = append(restartContainers, containers...)
- } else if c.All {
+ case c.All:
containers, err = r.Runtime.GetAllContainers()
if err != nil {
return nil, nil, err
}
restartContainers = append(restartContainers, containers...)
- } else {
+ default:
for _, id := range c.InputArgs {
ctr, err := r.Runtime.LookupContainer(id)
if err != nil {
@@ -1230,6 +1232,7 @@ func (r *LocalRuntime) generateSystemdgenContainerInfo(c *cliconfig.GenerateSyst
PIDFile: conmonPidFile,
StopTimeout: timeout,
GenerateTimestamp: true,
+ CreateCommand: config.CreateCommand,
}
return info, true, nil
@@ -1237,11 +1240,21 @@ func (r *LocalRuntime) generateSystemdgenContainerInfo(c *cliconfig.GenerateSyst
// GenerateSystemd creates a unit file for a container or pod.
func (r *LocalRuntime) GenerateSystemd(c *cliconfig.GenerateSystemdValues) (string, error) {
+ opts := systemdgen.Options{
+ Files: c.Files,
+ New: c.New,
+ }
+
// First assume it's a container.
if info, found, err := r.generateSystemdgenContainerInfo(c, c.InputArgs[0], nil); found && err != nil {
return "", err
} else if found && err == nil {
- return systemdgen.CreateContainerSystemdUnit(info, c.Files)
+ return systemdgen.CreateContainerSystemdUnit(info, opts)
+ }
+
+ // --new does not support pods.
+ if c.New {
+ return "", errors.Errorf("error generating systemd unit files: cannot generate generic files for a pod")
}
// We're either having a pod or garbage.
@@ -1312,7 +1325,7 @@ func (r *LocalRuntime) GenerateSystemd(c *cliconfig.GenerateSystemdValues) (stri
if i > 0 {
builder.WriteByte('\n')
}
- out, err := systemdgen.CreateContainerSystemdUnit(info, c.Files)
+ out, err := systemdgen.CreateContainerSystemdUnit(info, opts)
if err != nil {
return "", err
}