diff --git a/pkg/controllers/core/clustercatalog_controller.go b/pkg/controllers/core/clustercatalog_controller.go index a803730..e64122d 100644 --- a/pkg/controllers/core/clustercatalog_controller.go +++ b/pkg/controllers/core/clustercatalog_controller.go @@ -135,7 +135,7 @@ func (r *ClusterCatalogReconciler) reconcile(ctx context.Context, catalog *v1alp // if ResolvedSource is not nil, it indicates that this is not the first time we're // unpacking this catalog. if catalog.Status.ResolvedSource != nil { - if !unpackAgain(catalog) { + if !unpackAgain(r, catalog) { return ctrl.Result{}, nil } } @@ -247,11 +247,15 @@ func updateStatusStorageDeleteError(status *v1alpha1.ClusterCatalogStatus, err e return err } -func unpackAgain(catalog *v1alpha1.ClusterCatalog) bool { +func unpackAgain(r *ClusterCatalogReconciler, catalog *v1alpha1.ClusterCatalog) bool { // if the spec.Source.Image.Ref was changed, unpack the new ref if catalog.Spec.Source.Image.Ref != catalog.Status.ResolvedSource.Image.Ref { return true } + // if the content isn't available, unpack again + if !r.Storage.ContentExists(catalog.Name) { + return true + } // if pollInterval is nil, don't unpack again if catalog.Spec.Source.Image.PollInterval == nil { return false diff --git a/pkg/controllers/core/clustercatalog_controller_test.go b/pkg/controllers/core/clustercatalog_controller_test.go index e3d8ecc..a48e17c 100644 --- a/pkg/controllers/core/clustercatalog_controller_test.go +++ b/pkg/controllers/core/clustercatalog_controller_test.go @@ -75,6 +75,10 @@ func (m MockStore) StorageServerHandler() http.Handler { panic("not needed") } +func (m MockStore) ContentExists(_ string) bool { + return true +} + func TestCatalogdControllerReconcile(t *testing.T) { for _, tt := range []struct { name string diff --git a/pkg/storage/localdir.go b/pkg/storage/localdir.go index a34924c..96b7c21 100644 --- a/pkg/storage/localdir.go +++ b/pkg/storage/localdir.go @@ -60,6 +60,15 @@ func (s LocalDir) StorageServerHandler() http.Handler { return mux } +func (s LocalDir) ContentExists(catalog string) bool { + var filesystem = &filesOnlyFilesystem{os.DirFS(s.RootDir)} + _, err := filesystem.Open(catalog) + if err != nil && os.IsNotExist(err) { + return false + } + return true +} + // filesOnlyFilesystem is a file system that can open only regular // files from the underlying filesystem. All other file types result // in os.ErrNotExists diff --git a/pkg/storage/storage.go b/pkg/storage/storage.go index 44f37f5..09fbded 100644 --- a/pkg/storage/storage.go +++ b/pkg/storage/storage.go @@ -15,4 +15,5 @@ type Instance interface { Delete(catalog string) error ContentURL(catalog string) string StorageServerHandler() http.Handler + ContentExists(catalog string) bool }