runtime: pass down the context
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
parent
525f0b30ac
commit
f49e0c19ed
|
|
@ -47,7 +47,7 @@ func attachCmd(c *cliconfig.AttachValues) error {
|
|||
if remoteclient && len(c.InputArgs) != 1 {
|
||||
return errors.Errorf("attach requires the name or id of one running container")
|
||||
}
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -206,7 +206,7 @@ func buildCmd(c *cliconfig.BuildValues) error {
|
|||
dockerfiles = append(dockerfiles, filepath.Join(contextDir, "Dockerfile"))
|
||||
}
|
||||
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ func checkpointCmd(c *cliconfig.CheckpointValues) error {
|
|||
return errors.New("checkpointing a container requires root")
|
||||
}
|
||||
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ func init() {
|
|||
}
|
||||
|
||||
func cleanupCmd(c *cliconfig.CleanupValues) error {
|
||||
runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := libpodruntime.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ func init() {
|
|||
}
|
||||
|
||||
func commitCmd(c *cliconfig.CommitValues) error {
|
||||
runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := libpodruntime.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ func pruneContainers(runtime *adapter.LocalRuntime, ctx context.Context, maxWork
|
|||
}
|
||||
|
||||
func pruneContainersCmd(c *cliconfig.PruneContainersValues) error {
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ func cpCmd(c *cliconfig.CpValues) error {
|
|||
return errors.Errorf("you must provide a source path and a destination path")
|
||||
}
|
||||
|
||||
runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := libpodruntime.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ func createCmd(c *cliconfig.CreateValues) error {
|
|||
return err
|
||||
}
|
||||
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating libpod runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ func diffCmd(c *cliconfig.DiffValues) error {
|
|||
return errors.Errorf("container, image, or layer name must be specified: podman diff [options [...]] ID-NAME")
|
||||
}
|
||||
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ func init() {
|
|||
}
|
||||
|
||||
func eventsCmd(c *cliconfig.EventValues) error {
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating libpod runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ func execCmd(c *cliconfig.ExecValues) error {
|
|||
argStart = 0
|
||||
}
|
||||
cmd := args[argStart:]
|
||||
runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := libpodruntime.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating libpod runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ func imageExistsCmd(c *cliconfig.ImageExistsValues) error {
|
|||
if len(args) > 1 || len(args) < 1 {
|
||||
return errors.New("you may only check for the existence of one image at a time")
|
||||
}
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
@ -107,7 +107,7 @@ func containerExistsCmd(c *cliconfig.ContainerExistsValues) error {
|
|||
if len(args) > 1 || len(args) < 1 {
|
||||
return errors.New("you may only check for the existence of one container at a time")
|
||||
}
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
@ -126,7 +126,7 @@ func podExistsCmd(c *cliconfig.PodExistsValues) error {
|
|||
if len(args) > 1 || len(args) < 1 {
|
||||
return errors.New("you may only check for the existence of one pod at a time")
|
||||
}
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ func init() {
|
|||
|
||||
// exportCmd saves a container to a tarball on disk
|
||||
func exportCmd(c *cliconfig.ExportValues) error {
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ func generateKubeYAMLCmd(c *cliconfig.GenerateKubeValues) error {
|
|||
return errors.Errorf("you must provide exactly one container|pod ID or name")
|
||||
}
|
||||
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ func init() {
|
|||
}
|
||||
|
||||
func healthCheckCmd(c *cliconfig.HealthCheckValues) error {
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ func init() {
|
|||
}
|
||||
|
||||
func historyCmd(c *cliconfig.HistoryValues) error {
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ func imagesCmd(c *cliconfig.ImagesValues) error {
|
|||
image string
|
||||
)
|
||||
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ func init() {
|
|||
}
|
||||
|
||||
func pruneImagesCmd(c *cliconfig.PruneImagesValues) error {
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ func init() {
|
|||
}
|
||||
|
||||
func importCmd(c *cliconfig.ImportValues) error {
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ func infoCmd(c *cliconfig.InfoValues) error {
|
|||
info := map[string]interface{}{}
|
||||
remoteClientInfo := map[string]interface{}{}
|
||||
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ func inspectCmd(c *cliconfig.InspectValues) error {
|
|||
return errors.Errorf("you cannot provide additional arguments with --latest")
|
||||
}
|
||||
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating libpod runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ func killCmd(c *cliconfig.KillValues) error {
|
|||
return err
|
||||
}
|
||||
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package libpodruntime
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/containers/libpod/cmd/podman/cliconfig"
|
||||
"github.com/containers/libpod/libpod"
|
||||
"github.com/containers/libpod/pkg/rootless"
|
||||
|
|
@ -10,21 +12,21 @@ import (
|
|||
)
|
||||
|
||||
// GetRuntimeMigrate gets a libpod runtime that will perform a migration of existing containers
|
||||
func GetRuntimeMigrate(c *cliconfig.PodmanCommand) (*libpod.Runtime, error) {
|
||||
return getRuntime(c, false, true)
|
||||
func GetRuntimeMigrate(ctx context.Context, c *cliconfig.PodmanCommand) (*libpod.Runtime, error) {
|
||||
return getRuntime(ctx, c, false, true)
|
||||
}
|
||||
|
||||
// GetRuntimeRenumber gets a libpod runtime that will perform a lock renumber
|
||||
func GetRuntimeRenumber(c *cliconfig.PodmanCommand) (*libpod.Runtime, error) {
|
||||
return getRuntime(c, true, false)
|
||||
func GetRuntimeRenumber(ctx context.Context, c *cliconfig.PodmanCommand) (*libpod.Runtime, error) {
|
||||
return getRuntime(ctx, c, true, false)
|
||||
}
|
||||
|
||||
// GetRuntime generates a new libpod runtime configured by command line options
|
||||
func GetRuntime(c *cliconfig.PodmanCommand) (*libpod.Runtime, error) {
|
||||
return getRuntime(c, false, false)
|
||||
func GetRuntime(ctx context.Context, c *cliconfig.PodmanCommand) (*libpod.Runtime, error) {
|
||||
return getRuntime(ctx, c, false, false)
|
||||
}
|
||||
|
||||
func getRuntime(c *cliconfig.PodmanCommand, renumber bool, migrate bool) (*libpod.Runtime, error) {
|
||||
func getRuntime(ctx context.Context, c *cliconfig.PodmanCommand, renumber bool, migrate bool) (*libpod.Runtime, error) {
|
||||
options := []libpod.RuntimeOption{}
|
||||
storageOpts := storage.StoreOptions{}
|
||||
storageSet := false
|
||||
|
|
@ -76,6 +78,8 @@ func getRuntime(c *cliconfig.PodmanCommand, renumber bool, migrate bool) (*libpo
|
|||
options = append(options, libpod.WithRenumber())
|
||||
}
|
||||
|
||||
options = append(options, libpod.WithContext(ctx))
|
||||
|
||||
// Only set this if the user changes storage config on the command line
|
||||
if storageSet {
|
||||
options = append(options, libpod.WithStorageConfig(storageOpts))
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ func loadCmd(c *cliconfig.LoadValues) error {
|
|||
return errors.New("too many arguments. Requires exactly 1")
|
||||
}
|
||||
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ func init() {
|
|||
func logsCmd(c *cliconfig.LogsValues) error {
|
||||
var err error
|
||||
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ func setupRootless(cmd *cobra.Command, args []string) error {
|
|||
MainGlobalOpts,
|
||||
remoteclient,
|
||||
}
|
||||
runtime, err := libpodruntime.GetRuntime(&podmanCmd)
|
||||
runtime, err := libpodruntime.GetRuntime(getContext(), &podmanCmd)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ type jsonMountPoint struct {
|
|||
}
|
||||
|
||||
func mountCmd(c *cliconfig.MountValues) error {
|
||||
runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := libpodruntime.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ func pauseCmd(c *cliconfig.PauseValues) error {
|
|||
return errors.New("pause is not supported for rootless containers")
|
||||
}
|
||||
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ func playKubeCmd(c *cliconfig.KubePlayValues) error {
|
|||
}
|
||||
|
||||
ctx := getContext()
|
||||
runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := libpodruntime.GetRuntime(ctx, &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ func podCreateCmd(c *cliconfig.PodCreateValues) error {
|
|||
podIdFile *os.File
|
||||
)
|
||||
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating libpod runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ func podInspectCmd(c *cliconfig.PodInspectValues) error {
|
|||
return errors.Errorf("you must provide the name or id of a pod")
|
||||
}
|
||||
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ func init() {
|
|||
|
||||
// podKillCmd kills one or more pods with a signal
|
||||
func podKillCmd(c *cliconfig.PodKillValues) error {
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ func init() {
|
|||
|
||||
func podPauseCmd(c *cliconfig.PodPauseValues) error {
|
||||
var lastError error
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating libpod runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ func podPsCmd(c *cliconfig.PodPsValues) error {
|
|||
return errors.Wrapf(err, "error with flags passed")
|
||||
}
|
||||
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating libpod runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ func init() {
|
|||
|
||||
func podRestartCmd(c *cliconfig.PodRestartValues) error {
|
||||
var lastError error
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ func init() {
|
|||
|
||||
// podRmCmd deletes pods
|
||||
func podRmCmd(c *cliconfig.PodRmValues) error {
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ func init() {
|
|||
}
|
||||
|
||||
func podStartCmd(c *cliconfig.PodStartValues) error {
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ func podStatsCmd(c *cliconfig.PodStatsValues) error {
|
|||
all = true
|
||||
}
|
||||
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ func init() {
|
|||
}
|
||||
|
||||
func podStopCmd(c *cliconfig.PodStopValues) error {
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ func podTopCmd(c *cliconfig.PodTopValues) error {
|
|||
return errors.Errorf("you must provide the name or id of a running pod")
|
||||
}
|
||||
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating libpod runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ func init() {
|
|||
|
||||
func podUnpauseCmd(c *cliconfig.PodUnpauseValues) error {
|
||||
var lastError error
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating libpod runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ func init() {
|
|||
}
|
||||
|
||||
func podPruneCmd(c *cliconfig.PodPruneValues) error {
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ func portCmd(c *cliconfig.PortValues) error {
|
|||
}
|
||||
}
|
||||
|
||||
runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := libpodruntime.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -211,7 +211,7 @@ func psCmd(c *cliconfig.PsValues) error {
|
|||
return errors.Wrapf(err, "error with flags passed")
|
||||
}
|
||||
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating libpod runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ func pullCmd(c *cliconfig.PullValues) (retError error) {
|
|||
defer span.Finish()
|
||||
}
|
||||
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ func pushCmd(c *cliconfig.PushValues) error {
|
|||
registryCreds = creds
|
||||
}
|
||||
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not create runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ func init() {
|
|||
}
|
||||
|
||||
func refreshCmd(c *cliconfig.RefreshValues) error {
|
||||
runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := libpodruntime.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating libpod runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ func restartCmd(c *cliconfig.RestartValues) error {
|
|||
return errors.Wrapf(libpod.ErrInvalidArg, "you must provide at least one container name or ID")
|
||||
}
|
||||
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating libpod runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ func restoreCmd(c *cliconfig.RestoreValues) error {
|
|||
return errors.New("restoring a container requires root")
|
||||
}
|
||||
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ func init() {
|
|||
|
||||
// rmCmd removes one or more containers
|
||||
func rmCmd(c *cliconfig.RmValues) error {
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ func rmiCmd(c *cliconfig.RmiValues) error {
|
|||
|
||||
ctx := getContext()
|
||||
removeAll := c.All
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ func runCmd(c *cliconfig.RunValues) error {
|
|||
return err
|
||||
}
|
||||
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating libpod runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ func runlabelCmd(c *cliconfig.RunlabelValues) error {
|
|||
}
|
||||
|
||||
opts := make(map[string]string)
|
||||
runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := libpodruntime.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ func saveCmd(c *cliconfig.SaveValues) error {
|
|||
return errors.Errorf("need at least 1 argument")
|
||||
}
|
||||
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not create runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ func signCmd(c *cliconfig.SignValues) error {
|
|||
if len(args) < 1 {
|
||||
return errors.Errorf("at least one image name must be specified")
|
||||
}
|
||||
runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := libpodruntime.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not create runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ func startCmd(c *cliconfig.StartValues) error {
|
|||
return errors.Wrapf(libpod.ErrInvalidArg, "you cannot use sig-proxy without --attach")
|
||||
}
|
||||
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating libpod runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ func statsCmd(c *cliconfig.StatsValues) error {
|
|||
return errors.Errorf("you must specify --all, --latest, or at least one container")
|
||||
}
|
||||
|
||||
runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := libpodruntime.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ func stopCmd(c *cliconfig.StopValues) error {
|
|||
defer span.Finish()
|
||||
}
|
||||
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ func init() {
|
|||
}
|
||||
|
||||
func dfSystemCmd(c *cliconfig.SystemDfValues) error {
|
||||
runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := libpodruntime.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ func migrateCmd(c *cliconfig.SystemMigrateValues) error {
|
|||
// We need to pass one extra option to NewRuntime.
|
||||
// This will inform the OCI runtime to start a migrate.
|
||||
// That's controlled by the last argument to GetRuntime.
|
||||
r, err := libpodruntime.GetRuntimeMigrate(&c.PodmanCommand)
|
||||
r, err := libpodruntime.GetRuntimeMigrate(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error migrating containers")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ Are you sure you want to continue? [y/N] `, volumeString)
|
|||
}
|
||||
}
|
||||
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ func renumberCmd(c *cliconfig.SystemRenumberValues) error {
|
|||
// We need to pass one extra option to NewRuntime.
|
||||
// This will inform the OCI runtime to start a renumber.
|
||||
// That's controlled by the last argument to GetRuntime.
|
||||
r, err := libpodruntime.GetRuntimeRenumber(&c.PodmanCommand)
|
||||
r, err := libpodruntime.GetRuntimeRenumber(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error renumbering locks")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ func tagCmd(c *cliconfig.TagValues) error {
|
|||
if len(args) < 2 {
|
||||
return errors.Errorf("image name and at least one new name must be specified")
|
||||
}
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not create runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ func topCmd(c *cliconfig.TopValues) error {
|
|||
return errors.Errorf("you must provide the name or id of a running container")
|
||||
}
|
||||
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating libpod runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ func treeCmd(c *cliconfig.TreeValues) error {
|
|||
return errors.Errorf("you must provide at most 1 argument")
|
||||
}
|
||||
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating libpod runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ File(s) must exist before using this command`)
|
|||
}
|
||||
|
||||
func showTrustCmd(c *cliconfig.ShowTrustValues) error {
|
||||
runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := libpodruntime.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not create runtime")
|
||||
}
|
||||
|
|
@ -131,7 +131,7 @@ func showTrustCmd(c *cliconfig.ShowTrustValues) error {
|
|||
}
|
||||
|
||||
func setTrustCmd(c *cliconfig.SetTrustValues) error {
|
||||
runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := libpodruntime.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not create runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ func init() {
|
|||
}
|
||||
|
||||
func umountCmd(c *cliconfig.UmountValues) error {
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ func unpauseCmd(c *cliconfig.UnpauseValues) error {
|
|||
return errors.New("unpause is not supported for rootless containers")
|
||||
}
|
||||
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ func varlinkCmd(c *cliconfig.VarlinkValues) error {
|
|||
timeout := time.Duration(c.Timeout) * time.Millisecond
|
||||
|
||||
// Create a single runtime for varlink
|
||||
runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := libpodruntime.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating libpod runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ func init() {
|
|||
}
|
||||
|
||||
func volumeCreateCmd(c *cliconfig.VolumeCreateValues) error {
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating libpod runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ func volumeInspectCmd(c *cliconfig.VolumeInspectValues) error {
|
|||
return errors.New("provide one or more volume names or use --all")
|
||||
}
|
||||
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating libpod runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ func init() {
|
|||
}
|
||||
|
||||
func volumeLsCmd(c *cliconfig.VolumeLsValues) error {
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating libpod runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ func volumePrune(runtime *adapter.LocalRuntime, ctx context.Context) error {
|
|||
}
|
||||
|
||||
func volumePruneCmd(c *cliconfig.VolumePruneValues) error {
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating libpod runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ func volumeRmCmd(c *cliconfig.VolumeRmValues) error {
|
|||
return errors.New("choose either one or more volumes or all")
|
||||
}
|
||||
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating libpod runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ func waitCmd(c *cliconfig.WaitValues) error {
|
|||
}
|
||||
interval := time.Duration(c.Interval) * time.Millisecond
|
||||
|
||||
runtime, err := adapter.GetRuntime(&c.PodmanCommand)
|
||||
runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating runtime")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package libpod
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
|
@ -466,6 +467,19 @@ func WithShmDir(dir string) CtrCreateOption {
|
|||
}
|
||||
}
|
||||
|
||||
// WithContext sets the context to use.
|
||||
func WithContext(ctx context.Context) RuntimeOption {
|
||||
return func(rt *Runtime) error {
|
||||
if rt.valid {
|
||||
return ErrRuntimeFinalized
|
||||
}
|
||||
|
||||
rt.ctx = ctx
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// WithSystemd turns on systemd mode in the container
|
||||
func WithSystemd() CtrCreateOption {
|
||||
return func(ctr *Container) error {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package libpod
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
|
@ -111,6 +112,8 @@ type Runtime struct {
|
|||
|
||||
// mechanism to read and write even logs
|
||||
eventer events.Eventer
|
||||
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
// OCIRuntimePath contains information about an OCI runtime.
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package libpod
|
||||
|
||||
import (
|
||||
"context"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
|
@ -39,7 +38,7 @@ func (r *Runtime) migrate() error {
|
|||
}
|
||||
|
||||
for _, ctr := range runningContainers {
|
||||
if err := ctr.Start(context.Background(), true); err != nil {
|
||||
if err := ctr.Start(r.ctx, true); err != nil {
|
||||
logrus.Errorf("error restarting container %s", ctr.ID())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,8 +57,8 @@ type Volume struct {
|
|||
type VolumeFilter func(*Volume) bool
|
||||
|
||||
// GetRuntime returns a LocalRuntime struct with the actual runtime embedded in it
|
||||
func GetRuntime(c *cliconfig.PodmanCommand) (*LocalRuntime, error) {
|
||||
runtime, err := libpodruntime.GetRuntime(c)
|
||||
func GetRuntime(ctx context.Context, c *cliconfig.PodmanCommand) (*LocalRuntime, error) {
|
||||
runtime, err := libpodruntime.GetRuntime(ctx, c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ type LocalRuntime struct {
|
|||
}
|
||||
|
||||
// GetRuntime returns a LocalRuntime struct with the actual runtime embedded in it
|
||||
func GetRuntime(c *cliconfig.PodmanCommand) (*LocalRuntime, error) {
|
||||
func GetRuntime(ctx context.Context, c *cliconfig.PodmanCommand) (*LocalRuntime, error) {
|
||||
runtime := RemoteRuntime{}
|
||||
conn, err := runtime.Connect()
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Reference in New Issue