Merge pull request #13697 from mclarke47/k8s-add-new-endpoints-to-api
feat(kubernetes): add new backend endpoints to api interface
This commit is contained in:
@@ -8,6 +8,7 @@ import { Config } from '@backstage/config';
|
||||
import { CoreV1Api } from '@kubernetes/client-node';
|
||||
import { Credentials } from 'aws-sdk';
|
||||
import { CustomObjectsApi } from '@kubernetes/client-node';
|
||||
import type { CustomResourceMatcher } from '@backstage/plugin-kubernetes-common';
|
||||
import { Duration } from 'luxon';
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import express from 'express';
|
||||
@@ -101,9 +102,6 @@ export interface CustomResource extends ObjectToFetch {
|
||||
objectType: 'customresources';
|
||||
}
|
||||
|
||||
// @alpha (undocumented)
|
||||
export type CustomResourceMatcher = Omit<ObjectToFetch, 'objectType'>;
|
||||
|
||||
// @alpha (undocumented)
|
||||
export interface CustomResourcesByEntity extends KubernetesObjectsByEntity {
|
||||
// (undocumented)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -89,6 +89,16 @@ export interface CronJobsFetchResponse {
|
||||
type: 'cronjobs';
|
||||
}
|
||||
|
||||
// @public (undocumented)
|
||||
export interface CustomObjectsByEntityRequest {
|
||||
// (undocumented)
|
||||
auth: KubernetesRequestAuth;
|
||||
// (undocumented)
|
||||
customResources: CustomResourceMatcher[];
|
||||
// (undocumented)
|
||||
entity: Entity;
|
||||
}
|
||||
|
||||
// @public (undocumented)
|
||||
export interface CustomResourceFetchResponse {
|
||||
// (undocumented)
|
||||
@@ -97,6 +107,16 @@ export interface CustomResourceFetchResponse {
|
||||
type: 'customresources';
|
||||
}
|
||||
|
||||
// @public (undocumented)
|
||||
export interface CustomResourceMatcher {
|
||||
// (undocumented)
|
||||
apiVersion: string;
|
||||
// (undocumented)
|
||||
group: string;
|
||||
// (undocumented)
|
||||
plural: string;
|
||||
}
|
||||
|
||||
// @public (undocumented)
|
||||
export interface DaemonSetsFetchResponse {
|
||||
// (undocumented)
|
||||
@@ -233,4 +253,12 @@ export interface StatefulSetsFetchResponse {
|
||||
// (undocumented)
|
||||
type: 'statefulsets';
|
||||
}
|
||||
|
||||
// @public (undocumented)
|
||||
export interface WorkloadsByEntityRequest {
|
||||
// (undocumented)
|
||||
auth: KubernetesRequestAuth;
|
||||
// (undocumented)
|
||||
entity: Entity;
|
||||
}
|
||||
```
|
||||
|
||||
@@ -39,6 +39,26 @@ export interface KubernetesRequestAuth {
|
||||
};
|
||||
}
|
||||
|
||||
/** @public */
|
||||
export interface CustomResourceMatcher {
|
||||
group: string;
|
||||
apiVersion: string;
|
||||
plural: string;
|
||||
}
|
||||
|
||||
/** @public */
|
||||
export interface WorkloadsByEntityRequest {
|
||||
auth: KubernetesRequestAuth;
|
||||
entity: Entity;
|
||||
}
|
||||
|
||||
/** @public */
|
||||
export interface CustomObjectsByEntityRequest {
|
||||
auth: KubernetesRequestAuth;
|
||||
customResources: CustomResourceMatcher[];
|
||||
entity: Entity;
|
||||
}
|
||||
|
||||
/** @public */
|
||||
export interface KubernetesRequestBody {
|
||||
auth?: KubernetesRequestAuth;
|
||||
|
||||
@@ -10,6 +10,7 @@ import { BackstagePlugin } from '@backstage/core-plugin-api';
|
||||
import { ClientPodStatus } from '@backstage/plugin-kubernetes-common';
|
||||
import { ClusterAttributes } from '@backstage/plugin-kubernetes-common';
|
||||
import { ClusterObjects } from '@backstage/plugin-kubernetes-common';
|
||||
import { CustomObjectsByEntityRequest } from '@backstage/plugin-kubernetes-common';
|
||||
import { DiscoveryApi } from '@backstage/core-plugin-api';
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import { IdentityApi } from '@backstage/core-plugin-api';
|
||||
@@ -31,6 +32,7 @@ import { V1Pod } from '@kubernetes/client-node';
|
||||
import { V1ReplicaSet } from '@kubernetes/client-node';
|
||||
import { V1Service } from '@kubernetes/client-node';
|
||||
import { V1StatefulSet } from '@kubernetes/client-node';
|
||||
import { WorkloadsByEntityRequest } from '@backstage/plugin-kubernetes-common';
|
||||
|
||||
// Warning: (ae-forgotten-export) The symbol "ClusterProps" needs to be exported by the entry point index.d.ts
|
||||
// Warning: (ae-missing-release-tag) "Cluster" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
|
||||
@@ -245,9 +247,17 @@ export interface KubernetesApi {
|
||||
}[]
|
||||
>;
|
||||
// (undocumented)
|
||||
getCustomObjectsByEntity(
|
||||
request: CustomObjectsByEntityRequest,
|
||||
): Promise<ObjectsByEntityResponse>;
|
||||
// (undocumented)
|
||||
getObjectsByEntity(
|
||||
requestBody: KubernetesRequestBody,
|
||||
): Promise<ObjectsByEntityResponse>;
|
||||
// (undocumented)
|
||||
getWorkloadsByEntity(
|
||||
request: WorkloadsByEntityRequest,
|
||||
): Promise<ObjectsByEntityResponse>;
|
||||
}
|
||||
|
||||
// Warning: (ae-missing-release-tag) "kubernetesApiRef" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
|
||||
@@ -304,9 +314,17 @@ export class KubernetesBackendClient implements KubernetesApi {
|
||||
}[]
|
||||
>;
|
||||
// (undocumented)
|
||||
getCustomObjectsByEntity(
|
||||
request: CustomObjectsByEntityRequest,
|
||||
): Promise<ObjectsByEntityResponse>;
|
||||
// (undocumented)
|
||||
getObjectsByEntity(
|
||||
requestBody: KubernetesRequestBody,
|
||||
): Promise<ObjectsByEntityResponse>;
|
||||
// (undocumented)
|
||||
getWorkloadsByEntity(
|
||||
request: WorkloadsByEntityRequest,
|
||||
): Promise<ObjectsByEntityResponse>;
|
||||
}
|
||||
|
||||
// Warning: (ae-forgotten-export) The symbol "KubernetesContentProps" needs to be exported by the entry point index.d.ts
|
||||
|
||||
@@ -24,8 +24,10 @@ import {
|
||||
KubernetesApi,
|
||||
} from '../src';
|
||||
import {
|
||||
CustomObjectsByEntityRequest,
|
||||
FetchResponse,
|
||||
ObjectsByEntityResponse,
|
||||
WorkloadsByEntityRequest,
|
||||
} from '@backstage/plugin-kubernetes-common';
|
||||
import fixture1 from '../src/__fixtures__/1-deployments.json';
|
||||
import fixture2 from '../src/__fixtures__/2-deployments.json';
|
||||
@@ -59,6 +61,16 @@ class MockKubernetesClient implements KubernetesApi {
|
||||
({ type: type.toLocaleLowerCase('en-US'), resources } as FetchResponse),
|
||||
);
|
||||
}
|
||||
async getWorkloadsByEntity(
|
||||
_request: WorkloadsByEntityRequest,
|
||||
): Promise<ObjectsByEntityResponse> {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
async getCustomObjectsByEntity(
|
||||
_request: CustomObjectsByEntityRequest,
|
||||
): Promise<ObjectsByEntityResponse> {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
|
||||
async getObjectsByEntity(): Promise<ObjectsByEntityResponse> {
|
||||
return {
|
||||
|
||||
@@ -18,8 +18,11 @@ import { KubernetesApi } from './types';
|
||||
import {
|
||||
KubernetesRequestBody,
|
||||
ObjectsByEntityResponse,
|
||||
WorkloadsByEntityRequest,
|
||||
CustomObjectsByEntityRequest,
|
||||
} from '@backstage/plugin-kubernetes-common';
|
||||
import { DiscoveryApi, IdentityApi } from '@backstage/core-plugin-api';
|
||||
import { 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,25 @@ export class KubernetesBackendClient implements KubernetesApi {
|
||||
);
|
||||
}
|
||||
|
||||
async getWorkloadsByEntity(
|
||||
request: WorkloadsByEntityRequest,
|
||||
): Promise<ObjectsByEntityResponse> {
|
||||
return await this.postRequired('/resources/workloads/query', {
|
||||
auth: request.auth,
|
||||
entityRef: stringifyEntityRef(request.entity),
|
||||
});
|
||||
}
|
||||
|
||||
async getCustomObjectsByEntity(
|
||||
request: CustomObjectsByEntityRequest,
|
||||
): Promise<ObjectsByEntityResponse> {
|
||||
return await this.postRequired(`/resources/custom/query`, {
|
||||
entityRef: stringifyEntityRef(request.entity),
|
||||
auth: request.auth,
|
||||
customResources: request.customResources,
|
||||
});
|
||||
}
|
||||
|
||||
async getClusters(): Promise<{ name: string; authProvider: string }[]> {
|
||||
const { token: idToken } = await this.identityApi.getCredentials();
|
||||
const url = `${await this.discoveryApi.getBaseUrl('kubernetes')}/clusters`;
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
import {
|
||||
KubernetesRequestBody,
|
||||
ObjectsByEntityResponse,
|
||||
WorkloadsByEntityRequest,
|
||||
CustomObjectsByEntityRequest,
|
||||
} from '@backstage/plugin-kubernetes-common';
|
||||
import { createApiRef } from '@backstage/core-plugin-api';
|
||||
|
||||
@@ -35,4 +37,10 @@ export interface KubernetesApi {
|
||||
oidcTokenProvider?: string | undefined;
|
||||
}[]
|
||||
>;
|
||||
getWorkloadsByEntity(
|
||||
request: WorkloadsByEntityRequest,
|
||||
): Promise<ObjectsByEntityResponse>;
|
||||
getCustomObjectsByEntity(
|
||||
request: CustomObjectsByEntityRequest,
|
||||
): Promise<ObjectsByEntityResponse>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user