feat: Add request details to k8s service locator (#13871)
* feat: Add request details to k8s service locator BREAKING_CHANGE: Service locator now takes additional args Signed-off-by: Matthew Clarke <mclarke@spotify.com> * changeset && api report Signed-off-by: Matthew Clarke <mclarke@spotify.com> * Update .changeset/silent-bees-repeat.md Co-authored-by: Patrik Oldsberg <poldsberg@gmail.com> Signed-off-by: Matthew Clarke <matthewclarke47@gmail.com> Signed-off-by: Matthew Clarke <mclarke@spotify.com> * update changeset Signed-off-by: Matthew Clarke <mclarke@spotify.com> * Update silent-bees-repeat.md Signed-off-by: Matthew Clarke <mclarke@spotify.com> Signed-off-by: Matthew Clarke <mclarke@spotify.com> Signed-off-by: Matthew Clarke <matthewclarke47@gmail.com> Co-authored-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-kubernetes-backend': patch
|
||||
---
|
||||
|
||||
kubernetes service locator now take request context parameters
|
||||
@@ -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<ObjectToFetch>;
|
||||
}
|
||||
|
||||
// @alpha (undocumented)
|
||||
export type SigningCreds = {
|
||||
accessKeyId: string | undefined;
|
||||
|
||||
@@ -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: [
|
||||
|
||||
@@ -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 }));
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -120,12 +120,23 @@ export interface KubernetesClustersSupplier {
|
||||
getClusters(): Promise<ClusterDetails[]>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @alpha
|
||||
*/
|
||||
export interface ServiceLocatorRequestContext {
|
||||
objectTypesToFetch: Set<ObjectToFetch>;
|
||||
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[] }>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user