(feat): kubernetes add new backend endpoints to api interface
Signed-off-by: Matthew Clarke <mclarke@spotify.com>
This commit is contained in:
@@ -25,7 +25,6 @@ import {
|
||||
FetchResponseWrapper,
|
||||
ObjectToFetch,
|
||||
CustomResource,
|
||||
CustomResourceMatcher,
|
||||
CustomResourcesByEntity,
|
||||
KubernetesObjectsByEntity,
|
||||
} from '../types/types';
|
||||
@@ -40,6 +39,7 @@ import {
|
||||
ObjectsByEntityResponse,
|
||||
PodFetchResponse,
|
||||
KubernetesRequestAuth,
|
||||
CustomResourceMatcher,
|
||||
} from '@backstage/plugin-kubernetes-common';
|
||||
import {
|
||||
ContainerStatus,
|
||||
|
||||
@@ -18,6 +18,7 @@ import { Entity } from '@backstage/catalog-model';
|
||||
import { Logger } from 'winston';
|
||||
import type { JsonObject } from '@backstage/types';
|
||||
import type {
|
||||
CustomResourceMatcher,
|
||||
FetchResponse,
|
||||
KubernetesFetchError,
|
||||
KubernetesRequestAuth,
|
||||
@@ -86,12 +87,6 @@ export interface CustomResource extends ObjectToFetch {
|
||||
objectType: 'customresources';
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @alpha
|
||||
*/
|
||||
export type CustomResourceMatcher = Omit<ObjectToFetch, 'objectType'>;
|
||||
|
||||
/**
|
||||
*
|
||||
* @alpha
|
||||
|
||||
@@ -39,6 +39,13 @@ export interface KubernetesRequestAuth {
|
||||
};
|
||||
}
|
||||
|
||||
/** @public */
|
||||
export interface CustomResourceMatcher {
|
||||
group: string;
|
||||
apiVersion: string;
|
||||
plural: string;
|
||||
}
|
||||
|
||||
/** @public */
|
||||
export interface KubernetesRequestBody {
|
||||
auth?: KubernetesRequestAuth;
|
||||
|
||||
@@ -16,10 +16,13 @@
|
||||
|
||||
import { KubernetesApi } from './types';
|
||||
import {
|
||||
KubernetesRequestAuth,
|
||||
KubernetesRequestBody,
|
||||
ObjectsByEntityResponse,
|
||||
CustomResourceMatcher,
|
||||
} from '@backstage/plugin-kubernetes-common';
|
||||
import { DiscoveryApi, IdentityApi } from '@backstage/core-plugin-api';
|
||||
import { Entity, stringifyEntityRef } from '@backstage/catalog-model';
|
||||
|
||||
export class KubernetesBackendClient implements KubernetesApi {
|
||||
private readonly discoveryApi: DiscoveryApi;
|
||||
@@ -51,10 +54,7 @@ export class KubernetesBackendClient implements KubernetesApi {
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
private async postRequired(
|
||||
path: string,
|
||||
requestBody: KubernetesRequestBody,
|
||||
): Promise<any> {
|
||||
private async postRequired(path: string, requestBody: any): Promise<any> {
|
||||
const url = `${await this.discoveryApi.getBaseUrl('kubernetes')}${path}`;
|
||||
const { token: idToken } = await this.identityApi.getCredentials();
|
||||
const response = await fetch(url, {
|
||||
@@ -78,6 +78,28 @@ export class KubernetesBackendClient implements KubernetesApi {
|
||||
);
|
||||
}
|
||||
|
||||
async getWorkloadsByEntity(
|
||||
auth: KubernetesRequestAuth,
|
||||
entity: Entity,
|
||||
): Promise<ObjectsByEntityResponse> {
|
||||
return await this.postRequired('/resources/workloads/query', {
|
||||
auth,
|
||||
entityRef: stringifyEntityRef(entity),
|
||||
});
|
||||
}
|
||||
|
||||
async getCustomObjectsByEntity(
|
||||
auth: KubernetesRequestAuth,
|
||||
customResources: CustomResourceMatcher[],
|
||||
entity: Entity,
|
||||
): Promise<ObjectsByEntityResponse> {
|
||||
return await this.postRequired(`/resources/custom/query`, {
|
||||
entityRef: stringifyEntityRef(entity),
|
||||
auth,
|
||||
customResources,
|
||||
});
|
||||
}
|
||||
|
||||
async getClusters(): Promise<{ name: string; authProvider: string }[]> {
|
||||
const { token: idToken } = await this.identityApi.getCredentials();
|
||||
const url = `${await this.discoveryApi.getBaseUrl('kubernetes')}/clusters`;
|
||||
|
||||
@@ -15,10 +15,13 @@
|
||||
*/
|
||||
|
||||
import {
|
||||
KubernetesRequestAuth,
|
||||
KubernetesRequestBody,
|
||||
ObjectsByEntityResponse,
|
||||
CustomResourceMatcher,
|
||||
} from '@backstage/plugin-kubernetes-common';
|
||||
import { createApiRef } from '@backstage/core-plugin-api';
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
|
||||
export const kubernetesApiRef = createApiRef<KubernetesApi>({
|
||||
id: 'plugin.kubernetes.service',
|
||||
@@ -35,4 +38,13 @@ export interface KubernetesApi {
|
||||
oidcTokenProvider?: string | undefined;
|
||||
}[]
|
||||
>;
|
||||
getWorkloadsByEntity(
|
||||
auth: KubernetesRequestAuth,
|
||||
entity: Entity,
|
||||
): Promise<ObjectsByEntityResponse>;
|
||||
getCustomObjectsByEntity(
|
||||
auth: KubernetesRequestAuth,
|
||||
customResources: CustomResourceMatcher[],
|
||||
entity: Entity,
|
||||
): Promise<ObjectsByEntityResponse>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user