refactor: Change config option to be consistent with orphanStrategy
Signed-off-by: Jack Palmer <jackpalmer@spotify.com>
This commit is contained in:
@@ -171,7 +171,7 @@ To remove these entities automatically, you can use the following configuration.
|
||||
|
||||
```yaml
|
||||
catalog:
|
||||
evictOrphanedEntityProviders: true
|
||||
orphanProviderStrategy: delete
|
||||
```
|
||||
|
||||
## Processing Interval
|
||||
|
||||
Vendored
+7
-5
@@ -155,6 +155,13 @@ export interface Config {
|
||||
*/
|
||||
orphanStrategy?: 'keep' | 'delete';
|
||||
|
||||
/**
|
||||
* The strategy to use for entities that are referenced by providers that are orphaned,
|
||||
* i.e. entities with no providers currently configured in the catalog. The default value is
|
||||
* "keep".
|
||||
*/
|
||||
orphanProviderStrategy?: 'keep' | 'delete';
|
||||
|
||||
/**
|
||||
* The strategy to use when stitching together the final entities.
|
||||
*/
|
||||
@@ -216,10 +223,5 @@ export interface Config {
|
||||
* This flag is temporary and will be enabled by default in future releases.
|
||||
*/
|
||||
useUrlReadersSearch?: boolean;
|
||||
|
||||
/**
|
||||
* Evicts entities from the catalog when their related entity provider no longer exists.
|
||||
*/
|
||||
evictOrphanedEntityProviders?: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
+4
-4
@@ -16,9 +16,9 @@
|
||||
import { EntityProvider } from '@backstage/plugin-catalog-node';
|
||||
import { mockServices } from '@backstage/backend-test-utils';
|
||||
import { DefaultProviderDatabase } from '../database/DefaultProviderDatabase';
|
||||
import { evictOrphanedEntityProviders } from './evictOrphanedEntityProviders';
|
||||
import { evictEntitiesFromOrphanedProviders } from './evictEntitiesFromOrphanedProviders';
|
||||
|
||||
describe('evictOrphanedEntityProviders', () => {
|
||||
describe('evictEntitiesFromOrphanedProviders', () => {
|
||||
const db = {
|
||||
transaction: jest.fn().mockImplementation(cb => cb((() => {}) as any)),
|
||||
replaceUnprocessedEntities: jest.fn(),
|
||||
@@ -34,7 +34,7 @@ describe('evictOrphanedEntityProviders', () => {
|
||||
it('replaces unprocessed entities for orphaned providers with empty items', async () => {
|
||||
db.listReferenceSourceKeys.mockResolvedValue(['foo', 'bar']);
|
||||
|
||||
await evictOrphanedEntityProviders({ db, providers, logger });
|
||||
await evictEntitiesFromOrphanedProviders({ db, providers, logger });
|
||||
|
||||
expect(db.replaceUnprocessedEntities).toHaveBeenCalledTimes(2);
|
||||
expect(db.replaceUnprocessedEntities).toHaveBeenNthCalledWith(
|
||||
@@ -60,7 +60,7 @@ describe('evictOrphanedEntityProviders', () => {
|
||||
it('does not replace unprocessed entities for providers that are not orphaned', async () => {
|
||||
db.listReferenceSourceKeys.mockResolvedValue(['foo', 'provider1']);
|
||||
|
||||
await evictOrphanedEntityProviders({ db, providers, logger });
|
||||
await evictEntitiesFromOrphanedProviders({ db, providers, logger });
|
||||
|
||||
expect(db.replaceUnprocessedEntities).not.toHaveBeenCalledWith(
|
||||
expect.anything(),
|
||||
+1
-1
@@ -62,7 +62,7 @@ async function removeEntitiesForProvider({
|
||||
}
|
||||
}
|
||||
|
||||
export async function evictOrphanedEntityProviders(options: {
|
||||
export async function evictEntitiesFromOrphanedProviders(options: {
|
||||
db: ProviderDatabase;
|
||||
providers: EntityProvider[];
|
||||
logger: LoggerService;
|
||||
@@ -87,7 +87,7 @@ import {
|
||||
ProcessingIntervalFunction,
|
||||
} from '../processing';
|
||||
import { connectEntityProviders } from '../processing/connectEntityProviders';
|
||||
import { evictOrphanedEntityProviders } from '../processing/evictOrphanedEntityProviders';
|
||||
import { evictEntitiesFromOrphanedProviders } from '../processing/evictEntitiesFromOrphanedProviders';
|
||||
import { DefaultCatalogProcessingEngine } from '../processing/DefaultCatalogProcessingEngine';
|
||||
import { DefaultCatalogProcessingOrchestrator } from '../processing/DefaultCatalogProcessingOrchestrator';
|
||||
import {
|
||||
@@ -646,8 +646,10 @@ export class CatalogBuilder {
|
||||
|
||||
await connectEntityProviders(providerDatabase, entityProviders);
|
||||
|
||||
if (config.getOptionalBoolean('catalog.evictOrphanedEntityProviders')) {
|
||||
await evictOrphanedEntityProviders({
|
||||
if (
|
||||
config.getOptionalString('catalog.orphanProviderStrategy') === 'delete'
|
||||
) {
|
||||
await evictEntitiesFromOrphanedProviders({
|
||||
db: providerDatabase,
|
||||
providers: entityProviders,
|
||||
logger,
|
||||
|
||||
Reference in New Issue
Block a user