Skip to content

Commit

Permalink
Only read containers.conf once.
Browse files Browse the repository at this point in the history
We should not be changing these fields on the client side unless the
user specified them.

This patch drops strace mentions of containers.conf from 116 down to 26.

Fixes: containers/common#1200

[NO NEW TESTS NEEDED] Existing tests should test this.

Signed-off-by: Daniel J Walsh <[email protected]>
  • Loading branch information
rhatdan committed Oct 20, 2022
1 parent a77ac5b commit ca9d371
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cmd/podman/registry/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func newPodmanConfig() {
os.Exit(1)
}

cfg, err := config.NewConfig("")
cfg, err := config.Default()
if err != nil {
fmt.Fprint(os.Stderr, "Failed to obtain podman configuration: "+err.Error())
os.Exit(1)
Expand Down
6 changes: 3 additions & 3 deletions cmd/podman/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ func rootFlags(cmd *cobra.Command, opts *entities.PodmanConfig) {
_ = pFlags.MarkHidden(networkBackendFlagName)

rootFlagName := "root"
pFlags.StringVar(&cfg.Engine.StaticDir, rootFlagName, "", "Path to the root directory in which data, including images, is stored")
pFlags.StringVar(&cfg.Engine.StaticDir, rootFlagName, cfg.Engine.StaticDir, "Path to the root directory in which data, including images, is stored")
_ = cmd.RegisterFlagCompletionFunc(rootFlagName, completion.AutocompleteDefault)

pFlags.StringVar(&opts.RegistriesConf, "registries-conf", "", "Path to a registries.conf to use for image processing")
Expand All @@ -468,13 +468,13 @@ func rootFlags(cmd *cobra.Command, opts *entities.PodmanConfig) {
_ = cmd.RegisterFlagCompletionFunc(storageDriverFlagName, completion.AutocompleteNone)

tmpdirFlagName := "tmpdir"
pFlags.StringVar(&opts.Engine.TmpDir, tmpdirFlagName, "", "Path to the tmp directory for libpod state content.\n\nNote: use the environment variable 'TMPDIR' to change the temporary storage location for container images, '/var/tmp'.\n")
pFlags.StringVar(&opts.Engine.TmpDir, tmpdirFlagName, opts.Engine.TmpDir, "Path to the tmp directory for libpod state content.\n\nNote: use the environment variable 'TMPDIR' to change the temporary storage location for container images, '/var/tmp'.\n")
_ = cmd.RegisterFlagCompletionFunc(tmpdirFlagName, completion.AutocompleteDefault)

pFlags.BoolVar(&opts.Trace, "trace", false, "Enable opentracing output (default false)")

volumePathFlagName := "volumepath"
pFlags.StringVar(&opts.Engine.VolumePath, volumePathFlagName, "", "Path to the volume directory in which volume data is stored")
pFlags.StringVar(&opts.Engine.VolumePath, volumePathFlagName, opts.Engine.VolumePath, "Path to the volume directory in which volume data is stored")
_ = cmd.RegisterFlagCompletionFunc(volumePathFlagName, completion.AutocompleteDefault)

// Hide these flags for both ABI and Tunneling
Expand Down
7 changes: 6 additions & 1 deletion libpod/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func SetXdgDirs() error {
// NewRuntime creates a new container runtime
// Options can be passed to override the default configuration for the runtime
func NewRuntime(ctx context.Context, options ...RuntimeOption) (*Runtime, error) {
conf, err := config.NewConfig("")
conf, err := config.Default()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1169,3 +1169,8 @@ func (r *Runtime) RemoteURI() string {
func (r *Runtime) SetRemoteURI(uri string) {
r.config.Engine.RemoteURI = uri
}

// Config returns the system config
func (r *Runtime) Config() *config.Config {
return r.config
}
3 changes: 2 additions & 1 deletion pkg/api/handlers/libpod/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ func ImagesRemove(w http.ResponseWriter, r *http.Request) {
}

func ImageScp(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
decoder := r.Context().Value(api.DecoderKey).(*schema.Decoder)
query := struct {
Destination string `schema:"destination"`
Expand All @@ -618,7 +619,7 @@ func ImageScp(w http.ResponseWriter, r *http.Request) {

sourceArg := utils.GetName(r)

rep, source, dest, _, err := domainUtils.ExecuteTransfer(sourceArg, query.Destination, []string{}, query.Quiet, ssh.GolangMode)
rep, source, dest, _, err := domainUtils.ExecuteTransfer(sourceArg, query.Destination, []string{}, query.Quiet, ssh.GolangMode, runtime.Config())
if err != nil {
utils.Error(w, http.StatusInternalServerError, err)
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/domain/infra/abi/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ func (ir *ImageEngine) Sign(ctx context.Context, names []string, options entitie
}

func (ir *ImageEngine) Scp(ctx context.Context, src, dst string, parentFlags []string, quiet bool, sshMode ssh.EngineMode) error {
rep, source, dest, flags, err := domainUtils.ExecuteTransfer(src, dst, parentFlags, quiet, sshMode)
rep, source, dest, flags, err := domainUtils.ExecuteTransfer(src, dst, parentFlags, quiet, sshMode, ir.Libpod.Config())
if err != nil {
return err
}
Expand Down
9 changes: 2 additions & 7 deletions pkg/domain/utils/scp.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/sirupsen/logrus"
)

func ExecuteTransfer(src, dst string, parentFlags []string, quiet bool, sshMode ssh.EngineMode) (*entities.ImageLoadReport, *entities.ImageScpOptions, *entities.ImageScpOptions, []string, error) {
func ExecuteTransfer(src, dst string, parentFlags []string, quiet bool, sshMode ssh.EngineMode, conf *config.Config) (*entities.ImageLoadReport, *entities.ImageScpOptions, *entities.ImageScpOptions, []string, error) {
source := entities.ImageScpOptions{}
dest := entities.ImageScpOptions{}
sshInfo := entities.ImageScpConnections{}
Expand All @@ -33,11 +33,6 @@ func ExecuteTransfer(src, dst string, parentFlags []string, quiet bool, sshMode
return nil, nil, nil, nil, err
}

confR, err := config.NewConfig("") // create a hand made config for the remote engine since we might use remote and native at once
if err != nil {
return nil, nil, nil, nil, fmt.Errorf("could not make config: %w", err)
}

locations := []*entities.ImageScpOptions{}
cliConnections := []string{}
args := []string{src}
Expand Down Expand Up @@ -94,7 +89,7 @@ func ExecuteTransfer(src, dst string, parentFlags []string, quiet bool, sshMode
return nil, nil, nil, nil, err
}

confR.Engine = config.EngineConfig{Remote: true, CgroupManager: "cgroupfs", ServiceDestinations: serv} // pass the service dest (either remote or something else) to engine
conf.Engine = config.EngineConfig{Remote: true, CgroupManager: "cgroupfs", ServiceDestinations: serv} // pass the service dest (either remote or something else) to engine
saveCmd, loadCmd := CreateCommands(source, dest, parentFlags, podman)

switch {
Expand Down

0 comments on commit ca9d371

Please sign in to comment.