Merge pull request #9376 from K-Phoen/resource-dependency-of

Resource dependency of
This commit is contained in:
Fredrik Adelöw
2022-02-10 15:54:53 +01:00
committed by GitHub
6 changed files with 43 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog-backend': patch
---
Support "dependencyOf" relation in Resource entities
@@ -1121,6 +1121,17 @@ This field is optional.
| [`Component`](#kind-component) | Same as this entity, typically `default` | [`dependsOn`, and reverse `dependencyOf`](well-known-relations.md#dependson-and-dependencyof) |
| [`Resource`](#kind-resource) | Same as this entity, typically `default` | [`dependsOn`, and reverse `dependencyOf`](well-known-relations.md#dependson-and-dependencyof) |
### `spec.dependencyOf` [optional]
An array of [entity references](references.md#string-references) to the
components and resources that the resource is a dependency of, e.g. `artist-lookup`.
This field is optional.
| [`kind`](#apiversion-and-kind-required) | Default [`namespace`](#namespace-optional) | Generated [relation](well-known-relations.md) type |
| --------------------------------------- | ------------------------------------------ | --------------------------------------------------------------------------------------------- |
| [`Component`](#kind-component) | Same as this entity, typically `default` | [`dependencyOf`, and reverse `dependsOn`](well-known-relations.md#dependson-and-dependencyof) |
| [`Resource`](#kind-resource) | Same as this entity, typically `default` | [`dependencyOf`, and reverse `dependsOn`](well-known-relations.md#dependson-and-dependencyof) |
## Kind: System
Describes the following entity kind:
+1
View File
@@ -479,6 +479,7 @@ interface ResourceEntityV1alpha1 extends Entity {
type: string;
owner: string;
dependsOn?: string[];
dependencyOf?: string[];
system?: string;
};
}
@@ -34,6 +34,7 @@ export interface ResourceEntityV1alpha1 extends Entity {
type: string;
owner: string;
dependsOn?: string[];
dependencyOf?: string[];
system?: string;
};
}
@@ -251,13 +251,14 @@ describe('BuiltinKindsEntityProcessor', () => {
type: 'database',
owner: 'o',
dependsOn: ['Component:c', 'Resource:r'],
dependencyOf: ['Component:d'],
system: 's',
},
};
await processor.postProcessEntity(entity, location, emit);
expect(emit).toBeCalledTimes(8);
expect(emit).toBeCalledTimes(10);
expect(emit).toBeCalledWith({
type: 'relation',
relation: {
@@ -325,6 +326,23 @@ describe('BuiltinKindsEntityProcessor', () => {
target: { kind: 'System', namespace: 'default', name: 's' },
},
});
expect(emit).toBeCalledWith({
type: 'relation',
relation: {
source: { kind: 'Resource', namespace: 'default', name: 'n' },
type: 'dependencyOf',
target: { kind: 'Component', namespace: 'default', name: 'd' },
},
});
expect(emit).toBeCalledWith({
type: 'relation',
relation: {
source: { kind: 'Component', namespace: 'default', name: 'd' },
type: 'dependsOn',
target: { kind: 'Resource', namespace: 'default', name: 'n' },
},
});
});
it('generates an error for resource entities with unspecified dependsOn entity reference kinds', async () => {
@@ -225,6 +225,12 @@ export class BuiltinKindsEntityProcessor implements CatalogProcessor {
RELATION_DEPENDS_ON,
RELATION_DEPENDENCY_OF,
);
doEmit(
resource.spec.dependencyOf,
{ defaultNamespace: selfRef.namespace },
RELATION_DEPENDENCY_OF,
RELATION_DEPENDS_ON,
);
doEmit(
resource.spec.system,
{ defaultKind: 'System', defaultNamespace: selfRef.namespace },