diff --git a/central/imageintegration/datastore/datastore_impl.go b/central/imageintegration/datastore/datastore_impl.go index 7fbf0ba402b9c..138c04b93176e 100644 --- a/central/imageintegration/datastore/datastore_impl.go +++ b/central/imageintegration/datastore/datastore_impl.go @@ -52,20 +52,19 @@ func (ds *datastoreImpl) GetImageIntegrations(ctx context.Context, request *v1.G return nil, nil } - integrations, err := ds.storage.GetAll(ctx) - if err != nil { - return nil, err + if request.GetCluster() != "" { + return nil, nil } - integrationSlice := integrations[:0] - for _, integration := range integrations { - if request.GetCluster() != "" { - continue + var integrationSlice []*storage.ImageIntegration + err := ds.storage.Walk(ctx, func(integration *storage.ImageIntegration) error { + if request.GetName() == "" || request.GetName() == integration.GetName() { + integrationSlice = append(integrationSlice, integration) } - if request.GetName() != "" && request.GetName() != integration.GetName() { - continue - } - integrationSlice = append(integrationSlice, integration) + return nil + }) + if err != nil { + return nil, err } return integrationSlice, nil } diff --git a/central/imageintegration/datastore/singleton.go b/central/imageintegration/datastore/singleton.go index bd2519cb9d921..20b705c41b084 100644 --- a/central/imageintegration/datastore/singleton.go +++ b/central/imageintegration/datastore/singleton.go @@ -26,7 +26,11 @@ var ( func initializeIntegrations(iiStore store.Store) { ctx := sac.WithGlobalAccessScopeChecker(context.Background(), sac.AllowAllAccessScopeChecker()) - iis, err := iiStore.GetAll(ctx) + var iis []*storage.ImageIntegration + err := iiStore.Walk(ctx, func(ii *storage.ImageIntegration) error { + iis = append(iis, ii) + return nil + }) utils.CrashOnError(err) // If we are starting from scratch in online-mode, add the default image integrations. if !env.OfflineModeEnv.BooleanSetting() && len(iis) == 0 { diff --git a/central/imageintegration/store/mocks/store.go b/central/imageintegration/store/mocks/store.go index ced352f1d8007..9a4f78ff722d3 100644 --- a/central/imageintegration/store/mocks/store.go +++ b/central/imageintegration/store/mocks/store.go @@ -88,21 +88,6 @@ func (mr *MockStoreMockRecorder) Get(ctx, id any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockStore)(nil).Get), ctx, id) } -// GetAll mocks base method. -func (m *MockStore) GetAll(ctx context.Context) ([]*storage.ImageIntegration, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetAll", ctx) - ret0, _ := ret[0].([]*storage.ImageIntegration) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetAll indicates an expected call of GetAll. -func (mr *MockStoreMockRecorder) GetAll(ctx any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAll", reflect.TypeOf((*MockStore)(nil).GetAll), ctx) -} - // PruneMany mocks base method. func (m *MockStore) PruneMany(ctx context.Context, identifiers []string) error { m.ctrl.T.Helper() @@ -159,3 +144,17 @@ func (mr *MockStoreMockRecorder) UpsertMany(ctx, objs any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpsertMany", reflect.TypeOf((*MockStore)(nil).UpsertMany), ctx, objs) } + +// Walk mocks base method. +func (m *MockStore) Walk(ctx context.Context, fn func(*storage.ImageIntegration) error) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Walk", ctx, fn) + ret0, _ := ret[0].(error) + return ret0 +} + +// Walk indicates an expected call of Walk. +func (mr *MockStoreMockRecorder) Walk(ctx, fn any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Walk", reflect.TypeOf((*MockStore)(nil).Walk), ctx, fn) +} diff --git a/central/imageintegration/store/postgres/gen.go b/central/imageintegration/store/postgres/gen.go index 530aa3cd30fde..4cb6e7e4d4141 100644 --- a/central/imageintegration/store/postgres/gen.go +++ b/central/imageintegration/store/postgres/gen.go @@ -1,3 +1,3 @@ package postgres -//go:generate pg-table-bindings-wrapper --type=storage.ImageIntegration --search-category IMAGE_INTEGRATIONS --get-all-func --cached-store +//go:generate pg-table-bindings-wrapper --type=storage.ImageIntegration --search-category IMAGE_INTEGRATIONS --cached-store diff --git a/central/imageintegration/store/postgres/store.go b/central/imageintegration/store/postgres/store.go index 0ac1aeb6bfe1d..690bb233ae39c 100644 --- a/central/imageintegration/store/postgres/store.go +++ b/central/imageintegration/store/postgres/store.go @@ -51,7 +51,6 @@ type Store interface { GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) - GetAll(ctx context.Context) ([]*storeType, error) Walk(ctx context.Context, fn func(obj *storeType) error) error WalkByQuery(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error diff --git a/central/imageintegration/store/postgres/store_test.go b/central/imageintegration/store/postgres/store_test.go index 8f26e2cb0a656..a7ea2d5380710 100644 --- a/central/imageintegration/store/postgres/store_test.go +++ b/central/imageintegration/store/postgres/store_test.go @@ -92,9 +92,6 @@ func (s *ImageIntegrationsStoreSuite) TestStore() { } s.NoError(store.UpsertMany(ctx, imageIntegrations)) - allImageIntegration, err := store.GetAll(ctx) - s.NoError(err) - protoassert.ElementsMatch(s.T(), imageIntegrations, allImageIntegration) imageIntegrationCount, err = store.Count(ctx, search.EmptyQuery()) s.NoError(err) diff --git a/central/imageintegration/store/store.go b/central/imageintegration/store/store.go index b111eead9feac..d00838a762093 100644 --- a/central/imageintegration/store/store.go +++ b/central/imageintegration/store/store.go @@ -15,7 +15,7 @@ type Store interface { Count(ctx context.Context, q *v1.Query) (int, error) Search(ctx context.Context, q *v1.Query) ([]search.Result, error) Get(ctx context.Context, id string) (*storage.ImageIntegration, bool, error) - GetAll(ctx context.Context) ([]*storage.ImageIntegration, error) + Walk(ctx context.Context, fn func(obj *storage.ImageIntegration) error) error Upsert(ctx context.Context, integration *storage.ImageIntegration) error UpsertMany(ctx context.Context, objs []*storage.ImageIntegration) error Delete(ctx context.Context, id string) error