Skip to content

Commit 55ab02e

Browse files
Merge pull request #187 from tmshort/synchronize
NO-ISSUE: Synchronize From Upstream Repositories
2 parents ac5fbe6 + 5f0e668 commit 55ab02e

File tree

28 files changed

+474
-121
lines changed

28 files changed

+474
-121
lines changed

cmd/manager/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,9 @@ func main() {
314314
}
315315

316316
if err = (&controllers.ClusterCatalogReconciler{
317-
Client: cl,
318-
Cache: catalogClientBackend,
317+
Client: cl,
318+
CatalogCache: catalogClientBackend,
319+
CatalogCachePopulator: catalogClient,
319320
}).SetupWithManager(mgr); err != nil {
320321
setupLog.Error(err, "unable to create controller", "controller", "ClusterCatalog")
321322
os.Exit(1)

commitchecker.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
expectedMergeBase: cd0b096468d5d3ca6268dbef22d9b1eea789f771
1+
expectedMergeBase: cfd4bec28827a94e717f824a111ddcac3a144709
22
upstreamBranch: main
33
upstreamOrg: operator-framework
44
upstreamRepo: operator-controller

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ require (
1313
github.com/go-logr/logr v1.4.2
1414
github.com/google/go-cmp v0.6.0
1515
github.com/google/go-containerregistry v0.20.2
16-
github.com/onsi/ginkgo/v2 v2.20.2
17-
github.com/onsi/gomega v1.34.2
16+
github.com/onsi/ginkgo/v2 v2.21.0
17+
github.com/onsi/gomega v1.35.1
1818
github.com/opencontainers/go-digest v1.0.0
1919
github.com/operator-framework/api v0.27.0
2020
github.com/operator-framework/catalogd v0.35.0
@@ -116,7 +116,7 @@ require (
116116
github.com/google/cel-go v0.20.1 // indirect
117117
github.com/google/gnostic-models v0.6.8 // indirect
118118
github.com/google/gofuzz v1.2.0 // indirect
119-
github.com/google/pprof v0.0.0-20240827171923-fa2c70bbbfe5 // indirect
119+
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db // indirect
120120
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
121121
github.com/google/uuid v1.6.0 // indirect
122122
github.com/gorilla/mux v1.8.1 // indirect
@@ -230,7 +230,7 @@ require (
230230
golang.org/x/term v0.25.0 // indirect
231231
golang.org/x/text v0.19.0 // indirect
232232
golang.org/x/time v0.5.0 // indirect
233-
golang.org/x/tools v0.25.0 // indirect
233+
golang.org/x/tools v0.26.0 // indirect
234234
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
235235
google.golang.org/genproto v0.0.0-20240311173647-c811ad7063a7 // indirect
236236
google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 // indirect

go.sum

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/
310310
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
311311
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
312312
github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
313-
github.com/google/pprof v0.0.0-20240827171923-fa2c70bbbfe5 h1:5iH8iuqE5apketRbSFBy+X1V0o+l+8NF1avt4HWl7cA=
314-
github.com/google/pprof v0.0.0-20240827171923-fa2c70bbbfe5/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144=
313+
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db h1:097atOisP2aRj7vFgYQBbFN4U4JNXUNYpxael3UzMyo=
314+
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144=
315315
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
316316
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
317317
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
@@ -518,13 +518,13 @@ github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108
518518
github.com/onsi/ginkgo v1.13.0/go.mod h1:+REjRxOmWfHCjfv9TTWB1jD1Frx4XydAD3zm1lskyM0=
519519
github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc=
520520
github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
521-
github.com/onsi/ginkgo/v2 v2.20.2 h1:7NVCeyIWROIAheY21RLS+3j2bb52W0W82tkberYytp4=
522-
github.com/onsi/ginkgo/v2 v2.20.2/go.mod h1:K9gyxPIlb+aIvnZ8bd9Ak+YP18w3APlR+5coaZoE2ag=
521+
github.com/onsi/ginkgo/v2 v2.21.0 h1:7rg/4f3rB88pb5obDgNZrNHrQ4e6WpjonchcpuBRnZM=
522+
github.com/onsi/ginkgo/v2 v2.21.0/go.mod h1:7Du3c42kxCUegi0IImZ1wUQzMBVecgIHjR1C+NkhLQo=
523523
github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
524524
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
525525
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
526-
github.com/onsi/gomega v1.34.2 h1:pNCwDkzrsv7MS9kpaQvVb1aVLahQXyJ/Tv5oAZMI3i8=
527-
github.com/onsi/gomega v1.34.2/go.mod h1:v1xfxRgk0KIsG+QOdm7p8UosrOzPYRo60fd3B/1Dukc=
526+
github.com/onsi/gomega v1.35.1 h1:Cwbd75ZBPxFSuZ6T+rN/WCb/gOc6YgFBXLlZLhC7Ds4=
527+
github.com/onsi/gomega v1.35.1/go.mod h1:PvZbdDc8J6XJEpDK4HCuRBm8a6Fzp9/DmhC9C7yFlog=
528528
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
529529
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
530530
github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug=
@@ -892,8 +892,8 @@ golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtn
892892
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
893893
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
894894
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
895-
golang.org/x/tools v0.25.0 h1:oFU9pkj/iJgs+0DT+VMHrx+oBKs/LJMV+Uvg78sl+fE=
896-
golang.org/x/tools v0.25.0/go.mod h1:/vtpO8WL1N9cQC3FN5zPqb//fRXskFHbLKk4OW1Q7rg=
895+
golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ=
896+
golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0=
897897
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
898898
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
899899
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

internal/catalogmetadata/client/client.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,10 @@ func (c *Client) GetPackage(ctx context.Context, catalog *catalogd.ClusterCatalo
6565

6666
catalogFsys, err := c.cache.Get(catalog.Name, catalog.Status.ResolvedSource.Image.Ref)
6767
if err != nil {
68-
return nil, fmt.Errorf("error retrieving catalog cache: %v", err)
68+
return nil, fmt.Errorf("error retrieving cache for catalog %q: %v", catalog.Name, err)
6969
}
7070
if catalogFsys == nil {
71-
// TODO: https://github.com/operator-framework/operator-controller/pull/1284
72-
// For now we are still populating cache (if absent) on-demand,
73-
// but we might end up just returning a "cache not found" error here
74-
// once we implement cache population in the controller.
75-
catalogFsys, err = c.PopulateCache(ctx, catalog)
76-
if err != nil {
77-
return nil, fmt.Errorf("error fetching catalog contents: %v", err)
78-
}
71+
return nil, fmt.Errorf("cache for catalog %q not found", catalog.Name)
7972
}
8073

8174
pkgFsys, err := fs.Sub(catalogFsys, pkgName)

internal/catalogmetadata/client/client_test.go

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func TestClientGetPackage(t *testing.T) {
6262
catalog: defaultCatalog,
6363
cache: &fakeCache{getErr: errors.New("fetch error")},
6464
assert: func(t *testing.T, dc *declcfg.DeclarativeConfig, err error) {
65-
assert.ErrorContains(t, err, `error retrieving catalog cache`)
65+
assert.ErrorContains(t, err, `error retrieving cache for catalog "catalog-1"`)
6666
},
6767
},
6868
{
@@ -114,18 +114,7 @@ func TestClientGetPackage(t *testing.T) {
114114
return testFS, nil
115115
}},
116116
assert: func(t *testing.T, fbc *declcfg.DeclarativeConfig, err error) {
117-
require.NoError(t, err)
118-
assert.Equal(t, &declcfg.DeclarativeConfig{Packages: []declcfg.Package{{Schema: declcfg.SchemaPackage, Name: "pkg-present"}}}, fbc)
119-
},
120-
},
121-
{
122-
name: "cache unpopulated and fails to populate",
123-
catalog: defaultCatalog,
124-
pkgName: "pkg-present",
125-
cache: &fakeCache{putErr: errors.New("fake cache put error")},
126-
assert: func(t *testing.T, fbc *declcfg.DeclarativeConfig, err error) {
127-
assert.Nil(t, fbc)
128-
assert.ErrorContains(t, err, "error fetching catalog contents")
117+
assert.ErrorContains(t, err, `cache for catalog "catalog-1" not found`)
129118
},
130119
},
131120
} {
@@ -278,7 +267,6 @@ type fakeCache struct {
278267
getErr error
279268

280269
putFunc func(source string, errToCache error) (fs.FS, error)
281-
putErr error
282270
}
283271

284272
func (c *fakeCache) Get(catalogName, resolvedRef string) (fs.FS, error) {
@@ -293,9 +281,6 @@ func (c *fakeCache) Put(catalogName, resolvedRef string, source io.Reader, errTo
293281
}
294282
return c.putFunc(buf.String(), errToCache)
295283
}
296-
if c.putErr != nil {
297-
return nil, c.putErr
298-
}
299284

300285
return nil, errors.New("unexpected error")
301286
}

internal/controllers/clustercatalog_controller.go

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,30 @@ package controllers
1818

1919
import (
2020
"context"
21+
"fmt"
22+
"io/fs"
2123

2224
apierrors "k8s.io/apimachinery/pkg/api/errors"
2325
ctrl "sigs.k8s.io/controller-runtime"
24-
"sigs.k8s.io/controller-runtime/pkg/builder"
2526
"sigs.k8s.io/controller-runtime/pkg/client"
26-
"sigs.k8s.io/controller-runtime/pkg/event"
27-
"sigs.k8s.io/controller-runtime/pkg/predicate"
2827

2928
catalogd "github.com/operator-framework/catalogd/api/core/v1alpha1"
3029
)
3130

32-
type CatalogCacheRemover interface {
31+
type CatalogCache interface {
32+
Get(catalogName, resolvedRef string) (fs.FS, error)
3333
Remove(catalogName string) error
3434
}
3535

36+
type CatalogCachePopulator interface {
37+
PopulateCache(ctx context.Context, catalog *catalogd.ClusterCatalog) (fs.FS, error)
38+
}
39+
3640
// ClusterCatalogReconciler reconciles a ClusterCatalog object
3741
type ClusterCatalogReconciler struct {
3842
client.Client
39-
Cache CatalogCacheRemover
43+
CatalogCache CatalogCache
44+
CatalogCachePopulator CatalogCachePopulator
4045
}
4146

4247
//+kubebuilder:rbac:groups=olm.operatorframework.io,resources=clustercatalogs,verbs=get;list;watch
@@ -45,31 +50,44 @@ func (r *ClusterCatalogReconciler) Reconcile(ctx context.Context, req ctrl.Reque
4550
existingCatalog := &catalogd.ClusterCatalog{}
4651
err := r.Client.Get(ctx, req.NamespacedName, existingCatalog)
4752
if apierrors.IsNotFound(err) {
48-
return ctrl.Result{}, r.Cache.Remove(req.Name)
53+
if err := r.CatalogCache.Remove(req.Name); err != nil {
54+
return ctrl.Result{}, fmt.Errorf("error removing cache for catalog %q: %v", req.Name, err)
55+
}
56+
return ctrl.Result{}, nil
4957
}
5058
if err != nil {
5159
return ctrl.Result{}, err
5260
}
61+
62+
if existingCatalog.Status.ResolvedSource == nil ||
63+
existingCatalog.Status.ResolvedSource.Image == nil ||
64+
existingCatalog.Status.ResolvedSource.Image.Ref == "" {
65+
// Reference is not known yet - skip cache population with no error.
66+
// Once the reference is resolved another reconcile cycle
67+
// will be triggered and we will progress further.
68+
return ctrl.Result{}, nil
69+
}
70+
71+
catalogFsys, err := r.CatalogCache.Get(existingCatalog.Name, existingCatalog.Status.ResolvedSource.Image.Ref)
72+
if err != nil {
73+
return ctrl.Result{}, fmt.Errorf("error retrieving cache for catalog %q: %v", existingCatalog.Name, err)
74+
}
75+
if catalogFsys != nil {
76+
// Cache already exists so we do not need to populate it
77+
return ctrl.Result{}, nil
78+
}
79+
80+
if _, err = r.CatalogCachePopulator.PopulateCache(ctx, existingCatalog); err != nil {
81+
return ctrl.Result{}, fmt.Errorf("error populating cache for catalog %q: %v", existingCatalog.Name, err)
82+
}
83+
5384
return ctrl.Result{}, nil
5485
}
5586

5687
// SetupWithManager sets up the controller with the Manager.
5788
func (r *ClusterCatalogReconciler) SetupWithManager(mgr ctrl.Manager) error {
5889
_, err := ctrl.NewControllerManagedBy(mgr).
59-
For(&catalogd.ClusterCatalog{}, builder.WithPredicates(predicate.Funcs{
60-
CreateFunc: func(e event.CreateEvent) bool {
61-
return false
62-
},
63-
UpdateFunc: func(e event.UpdateEvent) bool {
64-
return false
65-
},
66-
DeleteFunc: func(e event.DeleteEvent) bool {
67-
return true
68-
},
69-
GenericFunc: func(e event.GenericEvent) bool {
70-
return false
71-
},
72-
})).
90+
For(&catalogd.ClusterCatalog{}).
7391
Build(r)
7492

7593
return err

0 commit comments

Comments
 (0)