summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorValentin Rothberg <rothberg@redhat.com>2021-06-24 14:35:10 +0200
committerValentin Rothberg <rothberg@redhat.com>2021-06-25 09:56:21 +0200
commitf95b0995e521e252af52edaf57a31241d364e3d8 (patch)
tree438f53d11703722c6712cf1b84c9fe1efdc884d0 /libpod
parentd1f57a07c24a0defc0b0027206fc4454307f64fa (diff)
downloadpodman-f95b0995e521e252af52edaf57a31241d364e3d8.tar.gz
podman-f95b0995e521e252af52edaf57a31241d364e3d8.tar.bz2
podman-f95b0995e521e252af52edaf57a31241d364e3d8.zip
remove `pkg/registries`
Pull the trigger on the `pkg/registries` package which acted as a proxy for `c/image/pkg/sysregistriesv2`. Callers should be using the packages from c/image directly, if needed at all. Also make use of libimage's SystemContext() method which returns a copy of a system context, further reducing the risk of unintentionally altering global data. [NO TESTS NEEDED] Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'libpod')
-rw-r--r--libpod/info.go8
-rw-r--r--libpod/runtime.go22
-rw-r--r--libpod/runtime_img_test.go54
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"}))
-}