diff --git a/.changeset/silent-bees-repeat.md b/.changeset/silent-bees-repeat.md new file mode 100644 index 0000000000..4592d9a703 --- /dev/null +++ b/.changeset/silent-bees-repeat.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-kubernetes-backend': patch +--- + +kubernetes service locator now take request context parameters diff --git a/ADOPTERS.md b/ADOPTERS.md index 4378eb14f9..e7e0e7784c 100644 --- a/ADOPTERS.md +++ b/ADOPTERS.md @@ -91,7 +91,7 @@ _You can do this by using the [Adopter form](https://form.typeform.com/to/zcOaKi | [HBO Max](https://hbomax.com) | [@mdb](https://github.com/mdb), [@nesta219](https://github.com/nesta219), [@nmische](https://github.com/nmische), [@hbomark](https://github.com/hbomark) | Developer portal hosting service catalog and API documentation, as well as cloud infrastructure details, operational visibility tools, and a custom plugin for browsing notable platform change events, such as deployments and configuration updates. | | [RCHLO](https://www.riachuelo.com.br) & [MIDWAY](https://www.midway.com.br) | [@marcosborges](https://github.com/marcosborges), [@defaultbr](https://github.com/defaultbr) | Self-Service Platform | | [HP Inc](https://www.hp.com) | [Damon Kaswell](https://github.com/dekoding) | DevEx engagement hub (dev portal: docs, standards, Q&A) and extensive assets catalog (APIs, services, code, data, etc.) for the pan-HP internal developer community. | -| [VMware](https://www.vmware.com) | [@mpriamo](https://github.com/mpriamo), [@krisapplegate](https://github.com/krisapplegate) | Part of [Tanzu Application Platform](https://docs.vmware.com/en/VMware-Tanzu-Application-Platform/index.html) offering; internal developer portal | +| [VMware](https://www.vmware.com) | [Waldir Montoya](https://github.com/waldirmontoya25), [Kris Applegate](https://github.com/krisapplegate), [Jamie Klassen](https://github.com/jamieklassen) | Part of [Tanzu Application Platform](https://docs.vmware.com/en/VMware-Tanzu-Application-Platform/index.html) offering; internal developer portal | | [Ualá](https://www.uala.com.ar/) | [Santiago Bernal](https://github.com/sabernal) | Initial work being done to centralize documentation for all our microservices and APIs, as well as scaffolding new services and tracking code quality | | [IKEA IT AB](https://www.ingka.com) | [@bjornramberg](https://github.com/bjornramberg), [@supriyachitale](https://github.com/supriyachitale) | Supporting engineers at scale with self serve access and connecting the dots of our engineering platform and services, enabling product teams to move faster and go further, and unleashing innovation, reuse and co-creation across the organisation. | | [Invitae](https://www.invitae.com/en) | [@ryan-hanchett](https://github.com/ryan-hanchett), [@gmandler42](https://github.com/gmandler42) | Centralized Developer Experience portal, putting all of our tooling behind a single pane of glass and creating a living service catalog. | diff --git a/plugins/kubernetes-backend/api-report.md b/plugins/kubernetes-backend/api-report.md index 4219387819..bf2c9e8082 100644 --- a/plugins/kubernetes-backend/api-report.md +++ b/plugins/kubernetes-backend/api-report.md @@ -326,7 +326,10 @@ export type KubernetesObjectTypes = // @alpha export interface KubernetesServiceLocator { // (undocumented) - getClustersByEntity(entity: Entity): Promise<{ + getClustersByEntity( + entity: Entity, + requestContext: ServiceLocatorRequestContext, + ): Promise<{ clusters: ClusterDetails[]; }>; } @@ -403,6 +406,14 @@ export interface ServiceAccountClusterDetails extends ClusterDetails {} // @alpha (undocumented) export type ServiceLocatorMethod = 'multiTenant' | 'http'; +// @alpha (undocumented) +export interface ServiceLocatorRequestContext { + // (undocumented) + customResources: CustomResourceMatcher[]; + // (undocumented) + objectTypesToFetch: Set; +} + // @alpha (undocumented) export type SigningCreds = { accessKeyId: string | undefined; diff --git a/plugins/kubernetes-backend/src/service-locator/MultiTenantServiceLocator.test.ts b/plugins/kubernetes-backend/src/service-locator/MultiTenantServiceLocator.test.ts index 2ead460848..b40503efc9 100644 --- a/plugins/kubernetes-backend/src/service-locator/MultiTenantServiceLocator.test.ts +++ b/plugins/kubernetes-backend/src/service-locator/MultiTenantServiceLocator.test.ts @@ -16,6 +16,7 @@ import '@backstage/backend-common'; import { Entity } from '@backstage/catalog-model'; +import { ServiceLocatorRequestContext } from '../types/types'; import { MultiTenantServiceLocator } from './MultiTenantServiceLocator'; describe('MultiTenantConfigClusterLocator', () => { @@ -24,7 +25,10 @@ describe('MultiTenantConfigClusterLocator', () => { getClusters: async () => [], }); - const result = await sut.getClustersByEntity({} as Entity); + const result = await sut.getClustersByEntity( + {} as Entity, + {} as ServiceLocatorRequestContext, + ); expect(result).toStrictEqual({ clusters: [] }); }); @@ -43,7 +47,10 @@ describe('MultiTenantConfigClusterLocator', () => { }, }); - const result = await sut.getClustersByEntity({} as Entity); + const result = await sut.getClustersByEntity( + {} as Entity, + {} as ServiceLocatorRequestContext, + ); expect(result).toStrictEqual({ clusters: [ @@ -76,7 +83,10 @@ describe('MultiTenantConfigClusterLocator', () => { }, }); - const result = await sut.getClustersByEntity({} as Entity); + const result = await sut.getClustersByEntity( + {} as Entity, + {} as ServiceLocatorRequestContext, + ); expect(result).toStrictEqual({ clusters: [ diff --git a/plugins/kubernetes-backend/src/service-locator/MultiTenantServiceLocator.ts b/plugins/kubernetes-backend/src/service-locator/MultiTenantServiceLocator.ts index 7bafbb10f3..ed902b194a 100644 --- a/plugins/kubernetes-backend/src/service-locator/MultiTenantServiceLocator.ts +++ b/plugins/kubernetes-backend/src/service-locator/MultiTenantServiceLocator.ts @@ -19,6 +19,7 @@ import { ClusterDetails, KubernetesClustersSupplier, KubernetesServiceLocator, + ServiceLocatorRequestContext, } from '../types/types'; // This locator assumes that every service is located on every cluster @@ -33,6 +34,7 @@ export class MultiTenantServiceLocator implements KubernetesServiceLocator { // As this implementation always returns all clusters serviceId is ignored here getClustersByEntity( _entity: Entity, + _requestContext: ServiceLocatorRequestContext, ): Promise<{ clusters: ClusterDetails[] }> { return this.clusterSupplier.getClusters().then(clusters => ({ clusters })); } diff --git a/plugins/kubernetes-backend/src/service/KubernetesFanOutHandler.ts b/plugins/kubernetes-backend/src/service/KubernetesFanOutHandler.ts index 23163d1004..64bbec6051 100644 --- a/plugins/kubernetes-backend/src/service/KubernetesFanOutHandler.ts +++ b/plugins/kubernetes-backend/src/service/KubernetesFanOutHandler.ts @@ -27,6 +27,7 @@ import { CustomResource, CustomResourcesByEntity, KubernetesObjectsByEntity, + ServiceLocatorRequestContext, } from '../types/types'; import { KubernetesAuthTranslator } from '../kubernetes-auth-translator/types'; import { KubernetesAuthTranslatorGenerator } from '../kubernetes-auth-translator/KubernetesAuthTranslatorGenerator'; @@ -231,7 +232,10 @@ export class KubernetesFanOutHandler { entity.metadata?.name; const clusterDetailsDecoratedForAuth: ClusterDetails[] = - await this.decorateClusterDetailsWithAuth(entity, auth); + await this.decorateClusterDetailsWithAuth(entity, auth, { + objectTypesToFetch: objectTypesToFetch, + customResources: customResources ?? [], + }); this.logger.info( `entity.metadata.name=${entityName} clusterDetails=[${clusterDetailsDecoratedForAuth @@ -274,9 +278,10 @@ export class KubernetesFanOutHandler { private async decorateClusterDetailsWithAuth( entity: Entity, auth: KubernetesRequestAuth, + requestContext: ServiceLocatorRequestContext, ) { const clusterDetails: ClusterDetails[] = await ( - await this.serviceLocator.getClustersByEntity(entity) + await this.serviceLocator.getClustersByEntity(entity, requestContext) ).clusters; // Execute all of these async actions simultaneously/without blocking sequentially as no common object is modified by them diff --git a/plugins/kubernetes-backend/src/types/types.ts b/plugins/kubernetes-backend/src/types/types.ts index 5ddfe7367d..a90f94c491 100644 --- a/plugins/kubernetes-backend/src/types/types.ts +++ b/plugins/kubernetes-backend/src/types/types.ts @@ -120,12 +120,23 @@ export interface KubernetesClustersSupplier { getClusters(): Promise; } +/** + * @alpha + */ +export interface ServiceLocatorRequestContext { + objectTypesToFetch: Set; + customResources: CustomResourceMatcher[]; +} + /** * Used to locate which cluster(s) a service is running on * @alpha */ export interface KubernetesServiceLocator { - getClustersByEntity(entity: Entity): Promise<{ clusters: ClusterDetails[] }>; + getClustersByEntity( + entity: Entity, + requestContext: ServiceLocatorRequestContext, + ): Promise<{ clusters: ClusterDetails[] }>; } /**