diff options
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/info.go | 8 | ||||
-rw-r--r-- | libpod/runtime.go | 22 | ||||
-rw-r--r-- | libpod/runtime_img_test.go | 54 |
3 files changed, 11 insertions, 73 deletions
diff --git a/libpod/info.go b/libpod/info.go index 461e39a48..cdc73780f 100644 --- a/libpod/info.go +++ b/libpod/info.go @@ -15,10 +15,10 @@ import ( "github.com/containers/buildah" "github.com/containers/common/pkg/apparmor" "github.com/containers/common/pkg/seccomp" + "github.com/containers/image/v5/pkg/sysregistriesv2" "github.com/containers/podman/v3/libpod/define" "github.com/containers/podman/v3/libpod/linkmode" "github.com/containers/podman/v3/pkg/cgroups" - registries2 "github.com/containers/podman/v3/pkg/registries" "github.com/containers/podman/v3/pkg/rootless" "github.com/containers/storage" "github.com/containers/storage/pkg/system" @@ -49,14 +49,16 @@ func (r *Runtime) info() (*define.Info, error) { } info.Store = storeInfo registries := make(map[string]interface{}) - data, err := registries2.GetRegistriesData() + + sys := r.SystemContext() + data, err := sysregistriesv2.GetRegistries(sys) if err != nil { return nil, errors.Wrapf(err, "error getting registries") } for _, reg := range data { registries[reg.Prefix] = reg } - regs, err := registries2.GetRegistries() + regs, err := sysregistriesv2.UnqualifiedSearchRegistries(sys) if err != nil { return nil, errors.Wrapf(err, "error getting registries") } diff --git a/libpod/runtime.go b/libpod/runtime.go index f53789e89..d31d00ae4 100644 --- a/libpod/runtime.go +++ b/libpod/runtime.go @@ -29,7 +29,6 @@ import ( "github.com/containers/podman/v3/libpod/plugin" "github.com/containers/podman/v3/libpod/shutdown" "github.com/containers/podman/v3/pkg/cgroups" - "github.com/containers/podman/v3/pkg/registries" "github.com/containers/podman/v3/pkg/rootless" "github.com/containers/podman/v3/pkg/util" "github.com/containers/storage" @@ -932,7 +931,9 @@ func (r *Runtime) LibimageRuntime() *libimage.Runtime { // SystemContext returns the imagecontext func (r *Runtime) SystemContext() *types.SystemContext { - return r.imageContext + // Return the context from the libimage runtime. libimage is sensitive + // to a number of env vars. + return r.libimageRuntime.SystemContext() } // GetOCIRuntimePath retrieves the path of the default OCI runtime. @@ -1042,9 +1043,9 @@ func (r *Runtime) Reload() error { if err := r.reloadStorageConf(); err != nil { return err } - if err := reloadRegistriesConf(); err != nil { - return err - } + // Invalidate the registries.conf cache. The next invocation will + // reload all data. + sysregistriesv2.InvalidateCache() return nil } @@ -1059,17 +1060,6 @@ func (r *Runtime) reloadContainersConf() error { return nil } -// reloadRegistries reloads the registries.conf -func reloadRegistriesConf() error { - sysregistriesv2.InvalidateCache() - registries, err := sysregistriesv2.GetRegistries(&types.SystemContext{SystemRegistriesConfPath: registries.SystemRegistriesConfPath()}) - if err != nil { - return err - } - logrus.Infof("applied new registry configuration: %+v", registries) - return nil -} - // reloadStorageConf reloads the storage.conf func (r *Runtime) reloadStorageConf() error { configFile, err := storage.DefaultConfigFile(rootless.IsRootless()) diff --git a/libpod/runtime_img_test.go b/libpod/runtime_img_test.go deleted file mode 100644 index c25f3f08c..000000000 --- a/libpod/runtime_img_test.go +++ /dev/null @@ -1,54 +0,0 @@ -package libpod - -import ( - "io/ioutil" - "os" - "reflect" - "testing" - - sysreg "github.com/containers/podman/v3/pkg/registries" - "github.com/stretchr/testify/assert" -) - -var ( - registry = `[registries.search] -registries = ['one'] - -[registries.insecure] -registries = ['two']` -) - -func createTmpFile(content []byte) (string, error) { - tmpfile, err := ioutil.TempFile(os.TempDir(), "unittest") - if err != nil { - return "", err - } - - if _, err := tmpfile.Write(content); err != nil { - return "", err - } - if err := tmpfile.Close(); err != nil { - return "", err - } - return tmpfile.Name(), nil -} - -func TestGetRegistries(t *testing.T) { - registryPath, err := createTmpFile([]byte(registry)) - assert.NoError(t, err) - defer os.Remove(registryPath) - os.Setenv("CONTAINERS_REGISTRIES_CONF", registryPath) - registries, err := sysreg.GetRegistries() - assert.NoError(t, err) - assert.True(t, reflect.DeepEqual(registries, []string{"one"})) -} - -func TestGetInsecureRegistries(t *testing.T) { - registryPath, err := createTmpFile([]byte(registry)) - assert.NoError(t, err) - os.Setenv("CONTAINERS_REGISTRIES_CONF", registryPath) - defer os.Remove(registryPath) - registries, err := sysreg.GetInsecureRegistries() - assert.NoError(t, err) - assert.True(t, reflect.DeepEqual(registries, []string{"two"})) -} |