Skip to content

Commit 1dde4b5

Browse files
committed
containers/image registry implementation with layer caching
Signed-off-by: Joe Lanford <[email protected]>
1 parent e6d2c99 commit 1dde4b5

File tree

7 files changed

+469
-58
lines changed

7 files changed

+469
-58
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ null :=
2727
space := $(null) #
2828
comma := ,
2929
# default to json1 for sqlite3
30-
TAGS := -tags=json1
30+
TAGS := -tags=json1,containers_image_openpgp
3131

3232
# Cluster to use for e2e testing
3333
CLUSTER ?= ""

alpha/action/render.go

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ import (
2222
"github.com/operator-framework/operator-registry/alpha/property"
2323
"github.com/operator-framework/operator-registry/pkg/containertools"
2424
"github.com/operator-framework/operator-registry/pkg/image"
25-
"github.com/operator-framework/operator-registry/pkg/image/containerdregistry"
25+
"github.com/operator-framework/operator-registry/pkg/image/containersimageregistry"
2626
"github.com/operator-framework/operator-registry/pkg/lib/bundle"
27-
"github.com/operator-framework/operator-registry/pkg/lib/log"
2827
"github.com/operator-framework/operator-registry/pkg/registry"
2928
"github.com/operator-framework/operator-registry/pkg/sqlite"
3029
)
@@ -66,7 +65,7 @@ func (r Render) Run(ctx context.Context) (*declcfg.DeclarativeConfig, error) {
6665
logDeprecationMessage.Do(func() {})
6766
}
6867
if r.Registry == nil {
69-
reg, err := r.createRegistry()
68+
reg, err := containersimageregistry.NewDefault()
7069
if err != nil {
7170
return nil, fmt.Errorf("create registry: %v", err)
7271
}
@@ -101,26 +100,6 @@ func (r Render) Run(ctx context.Context) (*declcfg.DeclarativeConfig, error) {
101100
return combineConfigs(cfgs), nil
102101
}
103102

104-
func (r Render) createRegistry() (*containerdregistry.Registry, error) {
105-
cacheDir, err := os.MkdirTemp("", "render-registry-")
106-
if err != nil {
107-
return nil, fmt.Errorf("create tempdir: %v", err)
108-
}
109-
110-
reg, err := containerdregistry.NewRegistry(
111-
containerdregistry.WithCacheDir(cacheDir),
112-
113-
// The containerd registry impl is somewhat verbose, even on the happy path,
114-
// so discard all logger logs. Any important failures will be returned from
115-
// registry methods and eventually logged as fatal errors.
116-
containerdregistry.WithLog(log.Null()),
117-
)
118-
if err != nil {
119-
return nil, err
120-
}
121-
return reg, nil
122-
}
123-
124103
func (r Render) renderReference(ctx context.Context, ref string) (*declcfg.DeclarativeConfig, error) {
125104
stat, err := os.Stat(ref)
126105
if err != nil {

cmd/opm/alpha/bundle/validate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
"github.com/operator-framework/operator-registry/pkg/containertools"
1212
"github.com/operator-framework/operator-registry/pkg/image"
13-
"github.com/operator-framework/operator-registry/pkg/image/containerdregistry"
13+
"github.com/operator-framework/operator-registry/pkg/image/containersimageregistry"
1414
"github.com/operator-framework/operator-registry/pkg/image/execregistry"
1515
"github.com/operator-framework/operator-registry/pkg/lib/bundle"
1616
)
@@ -69,7 +69,7 @@ func validateFunc(cmd *cobra.Command, _ []string) error {
6969
case containertools.PodmanTool, containertools.DockerTool:
7070
registry, err = execregistry.NewRegistry(tool, logger)
7171
case containertools.NoneTool:
72-
registry, err = containerdregistry.NewRegistry(containerdregistry.WithLog(logger))
72+
registry, err = containersimageregistry.NewDefault()
7373
default:
7474
err = fmt.Errorf("unrecognized container-tool option: %s", containerTool)
7575
}

cmd/opm/internal/util/util.go

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77

88
"github.com/spf13/cobra"
99

10-
"github.com/operator-framework/operator-registry/pkg/image/containerdregistry"
11-
"github.com/operator-framework/operator-registry/pkg/lib/log"
10+
"github.com/operator-framework/operator-registry/pkg/image"
11+
"github.com/operator-framework/operator-registry/pkg/image/containersimageregistry"
1212
)
1313

1414
// GetTLSOptions validates and returns TLS options set by opm flags
@@ -45,27 +45,15 @@ func GetTLSOptions(cmd *cobra.Command) (bool, bool, error) {
4545

4646
// This works in tandem with opm/index/cmd, which adds the relevant flags as persistent
4747
// as part of the root command (cmd/root/cmd) initialization
48-
func CreateCLIRegistry(cmd *cobra.Command) (*containerdregistry.Registry, error) {
48+
func CreateCLIRegistry(cmd *cobra.Command) (image.Registry, error) {
4949
skipTLSVerify, useHTTP, err := GetTLSOptions(cmd)
5050
if err != nil {
5151
return nil, err
5252
}
53-
54-
cacheDir, err := os.MkdirTemp("", "opm-registry-")
55-
if err != nil {
56-
return nil, err
57-
}
58-
59-
reg, err := containerdregistry.NewRegistry(
60-
containerdregistry.WithCacheDir(cacheDir),
61-
containerdregistry.SkipTLSVerify(skipTLSVerify),
62-
containerdregistry.WithPlainHTTP(useHTTP),
63-
containerdregistry.WithLog(log.Null()),
53+
return containersimageregistry.New(
54+
containersimageregistry.DefaultSystemContext,
55+
containersimageregistry.InsecureSkipTLSVerify(skipTLSVerify || useHTTP),
6456
)
65-
if err != nil {
66-
return nil, err
67-
}
68-
return reg, nil
6957
}
7058

7159
func OpenFileOrStdin(cmd *cobra.Command, args []string) (io.ReadCloser, string, error) {

go.mod

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ require (
5353
k8s.io/apimachinery v0.32.3
5454
k8s.io/client-go v0.32.3
5555
k8s.io/kubectl v0.32.0
56+
oras.land/oras-go/v2 v2.5.0
5657
sigs.k8s.io/controller-runtime v0.20.3
5758
sigs.k8s.io/kind v0.27.0
5859
sigs.k8s.io/yaml v1.4.0
@@ -67,6 +68,8 @@ require (
6768
github.com/MakeNowJust/heredoc v1.0.0 // indirect
6869
github.com/Microsoft/go-winio v0.6.2 // indirect
6970
github.com/Microsoft/hcsshim v0.12.9 // indirect
71+
github.com/VividCortex/ewma v1.2.0 // indirect
72+
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
7073
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
7174
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
7275
github.com/beorn7/perks v1.0.1 // indirect
@@ -85,6 +88,7 @@ require (
8588
github.com/containers/ocicrypt v1.2.1 // indirect
8689
github.com/containers/storage v1.57.2 // indirect
8790
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
91+
github.com/cyberphone/json-canonicalization v0.0.0-20231217050601-ba74d44ecf5f // indirect
8892
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
8993
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
9094
github.com/docker/distribution v2.8.3+incompatible // indirect
@@ -104,15 +108,23 @@ require (
104108
github.com/go-jose/go-jose/v4 v4.0.4 // indirect
105109
github.com/go-logr/logr v1.4.2 // indirect
106110
github.com/go-logr/stdr v1.2.2 // indirect
111+
github.com/go-openapi/analysis v0.23.0 // indirect
112+
github.com/go-openapi/errors v0.22.0 // indirect
107113
github.com/go-openapi/jsonpointer v0.21.0 // indirect
108114
github.com/go-openapi/jsonreference v0.21.0 // indirect
115+
github.com/go-openapi/loads v0.22.0 // indirect
116+
github.com/go-openapi/runtime v0.28.0 // indirect
117+
github.com/go-openapi/spec v0.21.0 // indirect
118+
github.com/go-openapi/strfmt v0.23.0 // indirect
109119
github.com/go-openapi/swag v0.23.0 // indirect
120+
github.com/go-openapi/validate v0.24.0 // indirect
110121
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
111122
github.com/gogo/protobuf v1.3.2 // indirect
112123
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
113124
github.com/golang/protobuf v1.5.4 // indirect
114125
github.com/google/cel-go v0.22.1 // indirect
115126
github.com/google/gnostic-models v0.6.8 // indirect
127+
github.com/google/go-containerregistry v0.20.2 // indirect
116128
github.com/google/gofuzz v1.2.0 // indirect
117129
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad // indirect
118130
github.com/google/safetext v0.0.0-20220905092116-b49f7bc46da2 // indirect
@@ -128,10 +140,15 @@ require (
128140
github.com/josharian/intern v1.0.0 // indirect
129141
github.com/json-iterator/go v1.1.12 // indirect
130142
github.com/klauspost/compress v1.17.11 // indirect
143+
github.com/klauspost/pgzip v1.2.6 // indirect
144+
github.com/letsencrypt/boulder v0.0.0-20240620165639-de9c06129bec // indirect
131145
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
132146
github.com/mailru/easyjson v0.7.7 // indirect
133147
github.com/mattn/go-isatty v0.0.20 // indirect
148+
github.com/mattn/go-runewidth v0.0.16 // indirect
149+
github.com/miekg/pkcs11 v1.1.1 // indirect
134150
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
151+
github.com/mitchellh/mapstructure v1.5.0 // indirect
135152
github.com/moby/locker v1.0.1 // indirect
136153
github.com/moby/spdystream v0.5.0 // indirect
137154
github.com/moby/sys/capability v0.4.0 // indirect
@@ -144,22 +161,36 @@ require (
144161
github.com/modern-go/reflect2 v1.0.2 // indirect
145162
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
146163
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
164+
github.com/oklog/ulid v1.3.1 // indirect
147165
github.com/opencontainers/runtime-spec v1.2.0 // indirect
148166
github.com/otiai10/mint v1.6.3 // indirect
149167
github.com/pelletier/go-toml v1.9.5 // indirect
150168
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
169+
github.com/proglottis/gpgme v0.1.4 // indirect
151170
github.com/prometheus/client_golang v1.20.5 // indirect
152171
github.com/prometheus/client_model v0.6.1 // indirect
153172
github.com/prometheus/common v0.60.1 // indirect
154173
github.com/prometheus/procfs v0.15.1 // indirect
155174
github.com/redis/go-redis/extra/rediscmd/v9 v9.0.5 // indirect
156175
github.com/redis/go-redis/extra/redisotel/v9 v9.0.5 // indirect
157-
github.com/redis/go-redis/v9 v9.1.0 // indirect
176+
github.com/redis/go-redis/v9 v9.7.0 // indirect
177+
github.com/rivo/uniseg v0.4.7 // indirect
158178
github.com/russross/blackfriday/v2 v2.1.0 // indirect
179+
github.com/secure-systems-lab/go-securesystemslib v0.9.0 // indirect
180+
github.com/sigstore/fulcio v1.6.4 // indirect
181+
github.com/sigstore/rekor v1.3.8 // indirect
182+
github.com/sigstore/sigstore v1.8.12 // indirect
183+
github.com/smallstep/pkcs7 v0.1.1 // indirect
159184
github.com/spiffe/go-spiffe/v2 v2.4.0 // indirect
185+
github.com/stefanberger/go-pkcs11uri v0.0.0-20230803200340-78284954bff6 // indirect
160186
github.com/stoewer/go-strcase v1.3.0 // indirect
187+
github.com/titanous/rocacheck v0.0.0-20171023193734-afe73141d399 // indirect
188+
github.com/ulikunitz/xz v0.5.12 // indirect
189+
github.com/vbatts/tar-split v0.11.7 // indirect
190+
github.com/vbauerster/mpb/v8 v8.9.1 // indirect
161191
github.com/x448/float16 v0.8.4 // indirect
162192
github.com/zeebo/errs v1.3.0 // indirect
193+
go.mongodb.org/mongo-driver v1.14.0 // indirect
163194
go.opencensus.io v0.24.0 // indirect
164195
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
165196
go.opentelemetry.io/contrib/bridges/prometheus v0.57.0 // indirect
@@ -187,9 +218,9 @@ require (
187218
golang.org/x/crypto v0.36.0 // indirect
188219
golang.org/x/oauth2 v0.27.0 // indirect
189220
golang.org/x/term v0.30.0 // indirect
190-
golang.org/x/time v0.7.0 // indirect
221+
golang.org/x/time v0.9.0 // indirect
191222
golang.org/x/tools v0.30.0 // indirect
192-
google.golang.org/genproto v0.0.0-20240903143218-8af14fe29dc1 // indirect
223+
google.golang.org/genproto v0.0.0-20241118233622-e639e219e697 // indirect
193224
google.golang.org/genproto/googleapis/api v0.0.0-20250303144028-a0af3efb3deb // indirect
194225
google.golang.org/genproto/googleapis/rpc v0.0.0-20250227231956-55c901821b1e // indirect
195226
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect

0 commit comments

Comments
 (0)