Skip to content

Commit fb9cc60

Browse files
committed
fixup PR comments
Signed-off-by: Joe Lanford <[email protected]>
1 parent 19d10a0 commit fb9cc60

File tree

12 files changed

+159
-169
lines changed

12 files changed

+159
-169
lines changed

catalogd/internal/controllers/core/clustercatalog_controller.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,14 @@ func (r *ClusterCatalogReconciler) reconcile(ctx context.Context, catalog *catal
234234
}
235235

236236
if catalog.Spec.Source.Type != catalogdv1.SourceTypeImage {
237-
panic(fmt.Sprintf("programmer error: source type %q is unable to handle specified catalog source type %q", catalogdv1.SourceTypeImage, catalog.Spec.Source.Type))
237+
err := reconcile.TerminalError(fmt.Errorf("unknown source type %q", catalog.Spec.Source.Type))
238+
updateStatusProgressing(&catalog.Status, catalog.GetGeneration(), err)
239+
return ctrl.Result{}, err
238240
}
239241
if catalog.Spec.Source.Image == nil {
240-
unpackErr := reconcile.TerminalError(fmt.Errorf("error parsing catalog, catalog %s has a nil image source", catalog.Name))
241-
updateStatusProgressing(&catalog.Status, catalog.GetGeneration(), unpackErr)
242-
return ctrl.Result{}, unpackErr
242+
err := reconcile.TerminalError(fmt.Errorf("error parsing catalog, catalog %s has a nil image source", catalog.Name))
243+
updateStatusProgressing(&catalog.Status, catalog.GetGeneration(), err)
244+
return ctrl.Result{}, err
243245
}
244246

245247
fsys, canonicalRef, unpackTime, err := r.ImagePuller.Pull(ctx, catalog.Name, catalog.Spec.Source.Image.Ref, r.ImageCache)
@@ -271,7 +273,7 @@ func (r *ClusterCatalogReconciler) reconcile(ctx context.Context, catalog *catal
271273
observedGeneration: catalog.GetGeneration(),
272274
}
273275
r.storedCatalogsMu.Unlock()
274-
return nextPollResult(time.Now(), catalog), nil
276+
return nextPollResult(lastSuccessfulPoll, catalog), nil
275277
}
276278

277279
func (r *ClusterCatalogReconciler) getCurrentState(catalog *catalogdv1.ClusterCatalog) (*catalogdv1.ClusterCatalogStatus, storedCatalogData, bool) {
@@ -450,7 +452,7 @@ func (r *ClusterCatalogReconciler) deleteCatalogCache(ctx context.Context, catal
450452
return err
451453
}
452454
updateStatusNotServing(&catalog.Status, catalog.GetGeneration())
453-
if err := r.ImageCache.DeleteID(ctx, catalog.Name); err != nil {
455+
if err := r.ImageCache.Delete(ctx, catalog.Name); err != nil {
454456
updateStatusProgressing(&catalog.Status, catalog.GetGeneration(), err)
455457
return err
456458
}

catalogd/internal/controllers/core/clustercatalog_controller_test.go

Lines changed: 32 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"errors"
66
"fmt"
77
"io/fs"
8-
"iter"
98
"net/http"
109
"testing"
1110
"testing/fstest"
@@ -14,7 +13,6 @@ import (
1413
"github.com/containers/image/v5/docker/reference"
1514
"github.com/google/go-cmp/cmp"
1615
"github.com/google/go-cmp/cmp/cmpopts"
17-
ocispecv1 "github.com/opencontainers/image-spec/specs-go/v1"
1816
"github.com/stretchr/testify/assert"
1917
"github.com/stretchr/testify/require"
2018
"k8s.io/apimachinery/pkg/api/meta"
@@ -28,50 +26,6 @@ import (
2826
imageutil "github.com/operator-framework/operator-controller/internal/util/image"
2927
)
3028

31-
var _ imageutil.Puller = &MockPuller{}
32-
33-
// MockPuller is a utility for mocking out an imageutil.Puller interface
34-
type MockPuller struct {
35-
// result is the result that should be returned when MockPuller.Unpack is called
36-
fsys fs.FS
37-
ref reference.Canonical
38-
modTime time.Time
39-
40-
// error is the error to be returned when MockPuller.Unpack is called
41-
pullError error
42-
}
43-
44-
func (ms *MockPuller) Pull(_ context.Context, _, _ string, _ imageutil.Cache) (fs.FS, reference.Canonical, time.Time, error) {
45-
if ms.pullError != nil {
46-
return nil, nil, time.Time{}, ms.pullError
47-
}
48-
49-
return ms.fsys, ms.ref, ms.modTime, nil
50-
}
51-
52-
var _ imageutil.Cache = (*MockCache)(nil)
53-
54-
type MockCache struct {
55-
// cleanupError is the error to be returned when MockPuller.Cleanup is called
56-
cleanupError error
57-
}
58-
59-
func (ms *MockCache) Fetch(_ context.Context, _ string, _ reference.Canonical) (fs.FS, time.Time, error) {
60-
panic("not implemented")
61-
}
62-
63-
func (ms *MockCache) Store(_ context.Context, _ string, _ reference.Named, _ reference.Canonical, _ ocispecv1.Image, _ iter.Seq[imageutil.LayerData]) (fs.FS, time.Time, error) {
64-
panic("not implemented")
65-
}
66-
67-
func (ms *MockCache) GarbageCollect(_ context.Context, _ string, _ reference.Canonical) error {
68-
panic("not implemented")
69-
}
70-
71-
func (ms *MockCache) DeleteID(_ context.Context, _ string) error {
72-
return ms.cleanupError
73-
}
74-
7529
var _ storage.Instance = &MockStore{}
7630

7731
type MockStore struct {
@@ -111,13 +65,13 @@ func TestCatalogdControllerReconcile(t *testing.T) {
11165
expectedError error
11266
shouldPanic bool
11367
expectedCatalog *catalogdv1.ClusterCatalog
114-
source imageutil.Puller
68+
puller imageutil.Puller
11569
cache imageutil.Cache
11670
store storage.Instance
11771
}{
11872
{
11973
name: "invalid source type, panics",
120-
source: &MockPuller{},
74+
puller: &imageutil.MockPuller{},
12175
store: &MockStore{},
12276
catalog: &catalogdv1.ClusterCatalog{
12377
ObjectMeta: metav1.ObjectMeta{
@@ -154,9 +108,9 @@ func TestCatalogdControllerReconcile(t *testing.T) {
154108
},
155109
{
156110
name: "valid source type, unpack returns error, status updated to reflect error state and error is returned",
157-
expectedError: fmt.Errorf("source catalog content: %w", fmt.Errorf("mocksource error")),
158-
source: &MockPuller{
159-
pullError: errors.New("mocksource error"),
111+
expectedError: fmt.Errorf("source catalog content: %w", fmt.Errorf("mockpuller error")),
112+
puller: &imageutil.MockPuller{
113+
Error: errors.New("mockpuller error"),
160114
},
161115
store: &MockStore{},
162116
catalog: &catalogdv1.ClusterCatalog{
@@ -199,9 +153,9 @@ func TestCatalogdControllerReconcile(t *testing.T) {
199153
},
200154
{
201155
name: "valid source type, unpack returns terminal error, status updated to reflect terminal error state(Blocked) and error is returned",
202-
expectedError: fmt.Errorf("source catalog content: %w", reconcile.TerminalError(fmt.Errorf("mocksource terminal error"))),
203-
source: &MockPuller{
204-
pullError: reconcile.TerminalError(errors.New("mocksource terminal error")),
156+
expectedError: fmt.Errorf("source catalog content: %w", reconcile.TerminalError(fmt.Errorf("mockpuller terminal error"))),
157+
puller: &imageutil.MockPuller{
158+
Error: reconcile.TerminalError(errors.New("mockpuller terminal error")),
205159
},
206160
store: &MockStore{},
207161
catalog: &catalogdv1.ClusterCatalog{
@@ -244,9 +198,9 @@ func TestCatalogdControllerReconcile(t *testing.T) {
244198
},
245199
{
246200
name: "valid source type, unpack state == Unpacked, should reflect in status that it's progressing, and is serving",
247-
source: &MockPuller{
248-
fsys: &fstest.MapFS{},
249-
ref: mustRef(t, "my.org/someimage@sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"),
201+
puller: &imageutil.MockPuller{
202+
ImageFS: &fstest.MapFS{},
203+
Ref: mustRef(t, "my.org/someimage@sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"),
250204
},
251205
store: &MockStore{},
252206
catalog: &catalogdv1.ClusterCatalog{
@@ -303,8 +257,8 @@ func TestCatalogdControllerReconcile(t *testing.T) {
303257
{
304258
name: "valid source type, unpack state == Unpacked, storage fails, failure reflected in status and error returned",
305259
expectedError: fmt.Errorf("error storing fbc: mockstore store error"),
306-
source: &MockPuller{
307-
fsys: &fstest.MapFS{},
260+
puller: &imageutil.MockPuller{
261+
ImageFS: &fstest.MapFS{},
308262
},
309263
store: &MockStore{
310264
shouldError: true,
@@ -349,8 +303,8 @@ func TestCatalogdControllerReconcile(t *testing.T) {
349303
},
350304
{
351305
name: "storage finalizer not set, storage finalizer gets set",
352-
source: &MockPuller{
353-
fsys: &fstest.MapFS{},
306+
puller: &imageutil.MockPuller{
307+
ImageFS: &fstest.MapFS{},
354308
},
355309
store: &MockStore{},
356310
catalog: &catalogdv1.ClusterCatalog{
@@ -383,8 +337,8 @@ func TestCatalogdControllerReconcile(t *testing.T) {
383337
},
384338
{
385339
name: "storage finalizer set, catalog deletion timestamp is not zero (or nil), finalizer removed",
386-
source: &MockPuller{
387-
fsys: &fstest.MapFS{},
340+
puller: &imageutil.MockPuller{
341+
ImageFS: &fstest.MapFS{},
388342
},
389343
store: &MockStore{},
390344
catalog: &catalogdv1.ClusterCatalog{
@@ -456,8 +410,8 @@ func TestCatalogdControllerReconcile(t *testing.T) {
456410
{
457411
name: "storage finalizer set, catalog deletion timestamp is not zero (or nil), storage delete failed, error returned, finalizer not removed and catalog continues serving",
458412
expectedError: fmt.Errorf("finalizer %q failed: %w", fbcDeletionFinalizer, fmt.Errorf("mockstore delete error")),
459-
source: &MockPuller{
460-
fsys: &fstest.MapFS{},
413+
puller: &imageutil.MockPuller{
414+
ImageFS: &fstest.MapFS{},
461415
},
462416
store: &MockStore{
463417
shouldError: true,
@@ -525,9 +479,9 @@ func TestCatalogdControllerReconcile(t *testing.T) {
525479
},
526480
{
527481
name: "storage finalizer set, catalog deletion timestamp is not zero (or nil), unpack cleanup failed, error returned, finalizer not removed but catalog stops serving",
528-
expectedError: fmt.Errorf("finalizer %q failed: %w", fbcDeletionFinalizer, fmt.Errorf("mocksource cleanup error")),
529-
source: &MockPuller{},
530-
cache: &MockCache{fmt.Errorf("mocksource cleanup error")},
482+
expectedError: fmt.Errorf("finalizer %q failed: %w", fbcDeletionFinalizer, fmt.Errorf("mockcache delete error")),
483+
puller: &imageutil.MockPuller{},
484+
cache: &imageutil.MockCache{DeleteErr: fmt.Errorf("mockcache delete error")},
531485
store: &MockStore{
532486
shouldError: false,
533487
},
@@ -592,8 +546,8 @@ func TestCatalogdControllerReconcile(t *testing.T) {
592546
},
593547
{
594548
name: "catalog availability set to disabled, status.urls should get unset",
595-
source: &MockPuller{
596-
fsys: &fstest.MapFS{},
549+
puller: &imageutil.MockPuller{
550+
ImageFS: &fstest.MapFS{},
597551
},
598552
store: &MockStore{},
599553
catalog: &catalogdv1.ClusterCatalog{
@@ -663,8 +617,8 @@ func TestCatalogdControllerReconcile(t *testing.T) {
663617
},
664618
{
665619
name: "catalog availability set to disabled, finalizer should get removed",
666-
source: &MockPuller{
667-
fsys: &fstest.MapFS{},
620+
puller: &imageutil.MockPuller{
621+
ImageFS: &fstest.MapFS{},
668622
},
669623
store: &MockStore{},
670624
catalog: &catalogdv1.ClusterCatalog{
@@ -738,13 +692,13 @@ func TestCatalogdControllerReconcile(t *testing.T) {
738692
t.Run(tt.name, func(t *testing.T) {
739693
reconciler := &ClusterCatalogReconciler{
740694
Client: nil,
741-
ImagePuller: tt.source,
695+
ImagePuller: tt.puller,
742696
ImageCache: tt.cache,
743697
Storage: tt.store,
744698
storedCatalogs: map[string]storedCatalogData{},
745699
}
746700
if reconciler.ImageCache == nil {
747-
reconciler.ImageCache = &MockCache{}
701+
reconciler.ImageCache = &imageutil.MockCache{}
748702
}
749703
require.NoError(t, reconciler.setupFinalizers())
750704
ctx := context.Background()
@@ -818,9 +772,9 @@ func TestPollingRequeue(t *testing.T) {
818772
t.Run(name, func(t *testing.T) {
819773
reconciler := &ClusterCatalogReconciler{
820774
Client: nil,
821-
ImagePuller: &MockPuller{
822-
fsys: &fstest.MapFS{},
823-
ref: mustRef(t, "my.org/someimage@sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"),
775+
ImagePuller: &imageutil.MockPuller{
776+
ImageFS: &fstest.MapFS{},
777+
Ref: mustRef(t, "my.org/someimage@sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"),
824778
},
825779
Storage: &MockStore{},
826780
storedCatalogs: map[string]storedCatalogData{},
@@ -1037,7 +991,7 @@ func TestPollingReconcilerUnpack(t *testing.T) {
1037991
}
1038992
reconciler := &ClusterCatalogReconciler{
1039993
Client: nil,
1040-
ImagePuller: &MockPuller{pullError: errors.New("mocksource error")},
994+
ImagePuller: &imageutil.MockPuller{Error: errors.New("mockpuller error")},
1041995
Storage: &MockStore{},
1042996
storedCatalogs: scd,
1043997
}

cmd/operator-controller/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"time"
2929

3030
"github.com/containers/image/v5/types"
31-
"github.com/go-logr/logr"
3231
"github.com/spf13/pflag"
3332
corev1 "k8s.io/api/core/v1"
3433
apiextensionsv1client "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1"
@@ -47,6 +46,7 @@ import (
4746
"sigs.k8s.io/controller-runtime/pkg/client"
4847
crfinalizer "sigs.k8s.io/controller-runtime/pkg/finalizer"
4948
"sigs.k8s.io/controller-runtime/pkg/healthz"
49+
"sigs.k8s.io/controller-runtime/pkg/log"
5050
"sigs.k8s.io/controller-runtime/pkg/metrics/filters"
5151
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
5252

@@ -313,7 +313,7 @@ func main() {
313313
DockerCertPath: pullCasDir,
314314
OCICertPath: pullCasDir,
315315
}
316-
logger := logr.FromContextOrDiscard(ctx)
316+
logger := log.FromContext(ctx)
317317
if _, err := os.Stat(authFilePath); err == nil && globalPullSecretKey != nil {
318318
logger.Info("using available authentication information for pulling image")
319319
srcContext.AuthFilePath = authFilePath
@@ -328,7 +328,7 @@ func main() {
328328

329329
clusterExtensionFinalizers := crfinalizer.NewFinalizers()
330330
if err := clusterExtensionFinalizers.Register(controllers.ClusterExtensionCleanupUnpackCacheFinalizer, finalizers.FinalizerFunc(func(ctx context.Context, obj client.Object) (crfinalizer.Result, error) {
331-
return crfinalizer.Result{}, imageCache.DeleteID(ctx, obj.GetName())
331+
return crfinalizer.Result{}, imageCache.Delete(ctx, obj.GetName())
332332
})); err != nil {
333333
setupLog.Error(err, "unable to register finalizer", "finalizerKey", controllers.ClusterExtensionCleanupUnpackCacheFinalizer)
334334
os.Exit(1)

0 commit comments

Comments
 (0)