Skip to content

Commit

Permalink
check the underlying storage for existing cluster catalog content
Browse files Browse the repository at this point in the history
Signed-off-by: Igor Troyanovsky <itroyano@redhat.com>
  • Loading branch information
itroyano committed Jun 25, 2024
1 parent 7558b05 commit 896eed7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/controllers/core/clustercatalog_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions pkg/controllers/core/clustercatalog_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions pkg/storage/localdir.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ type Instance interface {
Delete(catalog string) error
ContentURL(catalog string) string
StorageServerHandler() http.Handler
ContentExists(catalog string) bool
}

0 comments on commit 896eed7

Please sign in to comment.