Skip to content

Commit 66cc4fd

Browse files
Merge pull request #375 from grokspawn/opm-caching
Bug OCPBUGS-828: backport `opm serve` caching functionality (and bugfix) + `opm serve` leaving orphan tmpfiles
2 parents 8a984d4 + 8149337 commit 66cc4fd

File tree

20 files changed

+1094
-345
lines changed

20 files changed

+1094
-345
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ require (
234234
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
235235
google.golang.org/appengine v1.6.7 // indirect
236236
google.golang.org/genproto v0.0.0-20220107163113-42d7afdf6368 // indirect
237-
google.golang.org/grpc v1.43.0 // indirect
237+
google.golang.org/grpc v1.45.0 // indirect
238238
gopkg.in/inf.v0 v0.9.1 // indirect
239239
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
240240
gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473 // indirect

staging/operator-registry/alpha/action/generate_dockerfile.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,11 @@ FROM {{.BaseImage}}
4545
4646
# Configure the entrypoint and command
4747
ENTRYPOINT ["/bin/opm"]
48-
CMD ["serve", "/configs"]
48+
CMD ["serve", "/configs", "--cache-dir=/tmp/cache"]
4949
50-
# Copy declarative config root into image at /configs
50+
# Copy declarative config root into image at /configs and pre-populate serve cache
5151
ADD {{.IndexDir}} /configs
52+
RUN ["/bin/opm", "serve", "/configs", "--cache-dir=/tmp/cache", "--cache-only"]
5253
5354
# Set DC-specific label for the location of the DC root directory
5455
# in the image

staging/operator-registry/alpha/action/generate_dockerfile_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ FROM foo
5050
5151
# Configure the entrypoint and command
5252
ENTRYPOINT ["/bin/opm"]
53-
CMD ["serve", "/configs"]
53+
CMD ["serve", "/configs", "--cache-dir=/tmp/cache"]
5454
55-
# Copy declarative config root into image at /configs
55+
# Copy declarative config root into image at /configs and pre-populate serve cache
5656
ADD bar /configs
57+
RUN ["/bin/opm", "serve", "/configs", "--cache-dir=/tmp/cache", "--cache-only"]
5758
5859
# Set DC-specific label for the location of the DC root directory
5960
# in the image
@@ -76,10 +77,11 @@ FROM foo
7677
7778
# Configure the entrypoint and command
7879
ENTRYPOINT ["/bin/opm"]
79-
CMD ["serve", "/configs"]
80+
CMD ["serve", "/configs", "--cache-dir=/tmp/cache"]
8081
81-
# Copy declarative config root into image at /configs
82+
# Copy declarative config root into image at /configs and pre-populate serve cache
8283
ADD bar /configs
84+
RUN ["/bin/opm", "serve", "/configs", "--cache-dir=/tmp/cache", "--cache-only"]
8385
8486
# Set DC-specific label for the location of the DC root directory
8587
# in the image

staging/operator-registry/cmd/opm/registry/serve.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func serveFunc(cmd *cobra.Command, _ []string) error {
115115

116116
lis, err := net.Listen("tcp", ":"+port)
117117
if err != nil {
118-
logger.Fatalf("failed to listen: %s", err)
118+
return fmt.Errorf("failed to listen: %s", err)
119119
}
120120

121121
timeout, err := cmd.Flags().GetString("timeout-seconds")

staging/operator-registry/cmd/opm/serve/serve.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"google.golang.org/grpc"
1212
"google.golang.org/grpc/reflection"
1313

14-
"github.com/operator-framework/operator-registry/alpha/declcfg"
1514
"github.com/operator-framework/operator-registry/pkg/api"
1615
health "github.com/operator-framework/operator-registry/pkg/api/grpc_health_v1"
1716
"github.com/operator-framework/operator-registry/pkg/lib/dns"
@@ -23,6 +22,8 @@ import (
2322

2423
type serve struct {
2524
configDir string
25+
cacheDir string
26+
cacheOnly bool
2627

2728
port string
2829
terminationLog string
@@ -78,24 +79,18 @@ func (s *serve) run(ctx context.Context) error {
7879

7980
s.logger = s.logger.WithFields(logrus.Fields{"configs": s.configDir, "port": s.port})
8081

81-
cfg, err := declcfg.LoadFS(os.DirFS(s.configDir))
82-
if err != nil {
83-
return fmt.Errorf("load declarative config directory: %v", err)
84-
}
85-
86-
m, err := declcfg.ConvertToModel(*cfg)
87-
if err != nil {
88-
return fmt.Errorf("could not build index model from declarative config: %v", err)
89-
}
90-
store, err := registry.NewQuerier(m)
82+
store, err := registry.NewQuerierFromFS(os.DirFS(s.configDir), s.cacheDir)
9183
defer store.Close()
9284
if err != nil {
9385
return err
9486
}
87+
if s.cacheOnly {
88+
return nil
89+
}
9590

9691
lis, err := net.Listen("tcp", ":"+s.port)
9792
if err != nil {
98-
s.logger.Fatalf("failed to listen: %s", err)
93+
return fmt.Errorf("failed to listen: %s", err)
9994
}
10095

10196
grpcServer := grpc.NewServer()

staging/operator-registry/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ require (
3535
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3
3636
golang.org/x/net v0.0.0-20220407224826-aac1ed45d8e3
3737
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
38-
google.golang.org/grpc v1.40.0
38+
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad
39+
google.golang.org/grpc v1.45.0
3940
google.golang.org/grpc/cmd/protoc-gen-go-grpc v0.0.0-20200709232328-d8193ee9cc3e
4041
google.golang.org/protobuf v1.27.1
4142
gopkg.in/yaml.v2 v2.4.0
@@ -147,7 +148,6 @@ require (
147148
go.opentelemetry.io/proto/otlp v0.7.0 // indirect
148149
golang.org/x/crypto v0.0.0-20220408190544-5352b0902921 // indirect
149150
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
150-
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
151151
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
152152
golang.org/x/text v0.3.7 // indirect
153153
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect

staging/operator-registry/go.sum

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,11 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
145145
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
146146
github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
147147
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
148+
github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI=
148149
github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
150+
github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
151+
github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
152+
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
149153
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
150154
github.com/cockroachdb/cockroach-go v0.0.0-20181001143604-e0a95dfd547c/go.mod h1:XGLbWH/ujMcbPbhZq52Nv6UrCghb1yGn//133kEsvDk=
151155
github.com/cockroachdb/datadriven v0.0.0-20200714090401-bf6692d28da5/go.mod h1:h6jFvWxBdQXxjopDMZyH2UVceIRfR84bdzbkoKrsWNo=
@@ -246,6 +250,7 @@ github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5y
246250
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
247251
github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
248252
github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ=
253+
github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0=
249254
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
250255
github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
251256
github.com/evanphx/json-patch v4.11.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
@@ -1278,8 +1283,9 @@ google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAG
12781283
google.golang.org/grpc v1.36.1/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
12791284
google.golang.org/grpc v1.37.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
12801285
google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
1281-
google.golang.org/grpc v1.40.0 h1:AGJ0Ih4mHjSeibYkFGh1dD9KJ/eOtZ93I6hoHhukQ5Q=
12821286
google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34=
1287+
google.golang.org/grpc v1.45.0 h1:NEpgUqV3Z+ZjkqMsxMg11IaDrXY4RY6CQukSGK0uI1M=
1288+
google.golang.org/grpc v1.45.0/go.mod h1:lN7owxKUQEqMfSyQikvvk5tf/6zMPsrK+ONuO11+0rQ=
12831289
google.golang.org/grpc/cmd/protoc-gen-go-grpc v0.0.0-20200709232328-d8193ee9cc3e h1:4BwkYybqoRhPKm97iNO3ACkxj26G0hC18CaO9QXOxto=
12841290
google.golang.org/grpc/cmd/protoc-gen-go-grpc v0.0.0-20200709232328-d8193ee9cc3e/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw=
12851291
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=

0 commit comments

Comments
 (0)