Creating extension point for kubernetesFetcher
Signed-off-by: Andres Mauricio Gomez P <andmagom@outlook.com>
This commit is contained in:
@@ -90,6 +90,8 @@
|
||||
"@backstage/backend-app-api": "workspace:^",
|
||||
"@backstage/backend-test-utils": "workspace:^",
|
||||
"@backstage/cli": "workspace:^",
|
||||
"@backstage/plugin-permission-backend": "workspace:^",
|
||||
"@backstage/plugin-permission-backend-module-allow-all-policy": "workspace:^",
|
||||
"@types/aws4": "^1.5.1",
|
||||
"msw": "^1.0.0",
|
||||
"supertest": "^6.1.3",
|
||||
|
||||
@@ -32,6 +32,11 @@ import {
|
||||
KubernetesAuthStrategyExtensionPoint,
|
||||
AuthenticationStrategy,
|
||||
kubernetesAuthStrategyExtensionPoint,
|
||||
KubernetesFetcher,
|
||||
} from '@backstage/plugin-kubernetes-node';
|
||||
import {
|
||||
KubernetesFetcherExtensionPoint,
|
||||
kubernetesFetcherExtensionPoint,
|
||||
} from '@backstage/plugin-kubernetes-node';
|
||||
|
||||
class ObjectsProvider implements KubernetesObjectsProviderExtensionPoint {
|
||||
@@ -68,6 +73,23 @@ class ClusterSuplier implements KubernetesClusterSupplierExtensionPoint {
|
||||
}
|
||||
}
|
||||
|
||||
class Fetcher implements KubernetesFetcherExtensionPoint {
|
||||
private fetcher: KubernetesFetcher | undefined;
|
||||
|
||||
getFetcher() {
|
||||
return this.fetcher;
|
||||
}
|
||||
|
||||
addFetcher(fetcher: KubernetesFetcher) {
|
||||
if (this.fetcher) {
|
||||
throw new Error(
|
||||
'Multiple Kubernetes Fetchers is not supported at this time',
|
||||
);
|
||||
}
|
||||
this.fetcher = fetcher;
|
||||
}
|
||||
}
|
||||
|
||||
class AuthStrategy implements KubernetesAuthStrategyExtensionPoint {
|
||||
private authStrategies: Array<{
|
||||
key: string;
|
||||
@@ -108,6 +130,7 @@ export const kubernetesPlugin = createBackendPlugin({
|
||||
const extPointObjectsProvider = new ObjectsProvider();
|
||||
const extPointClusterSuplier = new ClusterSuplier();
|
||||
const extPointAuthStrategy = new AuthStrategy();
|
||||
const extPointFetcher = new Fetcher();
|
||||
env.registerExtensionPoint(
|
||||
kubernetesObjectsProviderExtensionPoint,
|
||||
extPointObjectsProvider,
|
||||
@@ -120,6 +143,10 @@ export const kubernetesPlugin = createBackendPlugin({
|
||||
kubernetesAuthStrategyExtensionPoint,
|
||||
extPointAuthStrategy,
|
||||
);
|
||||
env.registerExtensionPoint(
|
||||
kubernetesFetcherExtensionPoint,
|
||||
extPointFetcher,
|
||||
);
|
||||
|
||||
env.registerInit({
|
||||
deps: {
|
||||
@@ -139,7 +166,8 @@ export const kubernetesPlugin = createBackendPlugin({
|
||||
permissions,
|
||||
})
|
||||
.setObjectsProvider(extPointObjectsProvider.getObjectsProvider())
|
||||
.setClusterSupplier(extPointClusterSuplier.getClusterSupplier());
|
||||
.setClusterSupplier(extPointClusterSuplier.getClusterSupplier())
|
||||
.setFetcher(extPointFetcher.getFetcher());
|
||||
AuthStrategy.addAuthStrategiesFromArray(
|
||||
extPointAuthStrategy.getAuthenticationStrategies(),
|
||||
builder,
|
||||
|
||||
@@ -18,75 +18,16 @@ import { Entity } from '@backstage/catalog-model';
|
||||
import { Logger } from 'winston';
|
||||
import type {
|
||||
CustomResourceMatcher,
|
||||
FetchResponse,
|
||||
KubernetesFetchError,
|
||||
KubernetesRequestBody,
|
||||
} from '@backstage/plugin-kubernetes-common';
|
||||
import { Config } from '@backstage/config';
|
||||
import {
|
||||
ClusterDetails,
|
||||
KubernetesCredential,
|
||||
CustomResource,
|
||||
KubernetesFetcher,
|
||||
ObjectToFetch,
|
||||
} from '@backstage/plugin-kubernetes-node';
|
||||
|
||||
/**
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface ObjectFetchParams {
|
||||
serviceId: string;
|
||||
clusterDetails: ClusterDetails;
|
||||
credential: KubernetesCredential;
|
||||
objectTypesToFetch: Set<ObjectToFetch>;
|
||||
labelSelector?: string;
|
||||
customResources: CustomResource[];
|
||||
namespace?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches information from a kubernetes cluster using the cluster details object to target a specific cluster
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface KubernetesFetcher {
|
||||
fetchObjectsForService(
|
||||
params: ObjectFetchParams,
|
||||
): Promise<FetchResponseWrapper>;
|
||||
fetchPodMetricsByNamespaces(
|
||||
clusterDetails: ClusterDetails,
|
||||
credential: KubernetesCredential,
|
||||
namespaces: Set<string>,
|
||||
labelSelector?: string,
|
||||
): Promise<FetchResponseWrapper>;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface FetchResponseWrapper {
|
||||
errors: KubernetesFetchError[];
|
||||
responses: FetchResponse[];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface ObjectToFetch {
|
||||
objectType: KubernetesObjectTypes;
|
||||
group: string;
|
||||
apiVersion: string;
|
||||
plural: string;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface CustomResource extends ObjectToFetch {
|
||||
objectType: 'customresources';
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @public
|
||||
@@ -157,4 +98,9 @@ export type {
|
||||
AuthMetadata,
|
||||
ClusterDetails,
|
||||
KubernetesClustersSupplier,
|
||||
ObjectToFetch,
|
||||
CustomResource,
|
||||
ObjectFetchParams,
|
||||
FetchResponseWrapper,
|
||||
KubernetesFetcher,
|
||||
} from '@backstage/plugin-kubernetes-node';
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
"dependencies": {
|
||||
"@backstage/backend-plugin-api": "workspace:^",
|
||||
"@backstage/catalog-model": "workspace:^",
|
||||
"@backstage/plugin-kubernetes-backend": "workspace:^",
|
||||
"@backstage/plugin-kubernetes-common": "workspace:^",
|
||||
"@backstage/types": "workspace:^"
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { createExtensionPoint } from '@backstage/backend-plugin-api';
|
||||
import { KubernetesFetcher } from '@backstage/plugin-kubernetes-backend';
|
||||
import { AuthenticationStrategy } from '@backstage/plugin-kubernetes-node';
|
||||
import { KubernetesClustersSupplier } from '@backstage/plugin-kubernetes-node';
|
||||
import { KubernetesObjectsProvider } from '@backstage/plugin-kubernetes-node';
|
||||
@@ -74,3 +75,22 @@ export const kubernetesAuthStrategyExtensionPoint =
|
||||
createExtensionPoint<KubernetesAuthStrategyExtensionPoint>({
|
||||
id: 'kubernetes.auth-strategy',
|
||||
});
|
||||
|
||||
/**
|
||||
* The interface for {@link kubernetesFetcherExtensionPoint}.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface KubernetesFetcherExtensionPoint {
|
||||
addFetcher(fetcher: KubernetesFetcher): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* An extension point the exposes the ability to configure a kubernetes fetcher.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export const kubernetesFetcherExtensionPoint =
|
||||
createExtensionPoint<KubernetesFetcherExtensionPoint>({
|
||||
id: 'kubernetes.fetcher',
|
||||
});
|
||||
|
||||
@@ -29,13 +29,5 @@
|
||||
* @packageDocumentation
|
||||
*/
|
||||
|
||||
export {
|
||||
kubernetesObjectsProviderExtensionPoint,
|
||||
type KubernetesObjectsProviderExtensionPoint,
|
||||
kubernetesClusterSupplierExtensionPoint,
|
||||
type KubernetesClusterSupplierExtensionPoint,
|
||||
kubernetesAuthStrategyExtensionPoint,
|
||||
type KubernetesAuthStrategyExtensionPoint,
|
||||
} from './extensions';
|
||||
|
||||
export * from './extensions';
|
||||
export * from './types';
|
||||
|
||||
@@ -14,8 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import { KubernetesObjectTypes } from '@backstage/plugin-kubernetes-backend';
|
||||
import {
|
||||
CustomResourceMatcher,
|
||||
FetchResponse,
|
||||
KubernetesFetchError,
|
||||
KubernetesRequestAuth,
|
||||
ObjectsByEntityResponse,
|
||||
} from '@backstage/plugin-kubernetes-common';
|
||||
@@ -150,3 +153,62 @@ export interface AuthenticationStrategy {
|
||||
): Promise<KubernetesCredential>;
|
||||
validateCluster(authMetadata: AuthMetadata): Error[];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface ObjectToFetch {
|
||||
objectType: KubernetesObjectTypes; // TODO - Review
|
||||
group: string;
|
||||
apiVersion: string;
|
||||
plural: string;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface CustomResource extends ObjectToFetch {
|
||||
objectType: 'customresources';
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface ObjectFetchParams {
|
||||
serviceId: string;
|
||||
clusterDetails: ClusterDetails;
|
||||
credential: KubernetesCredential;
|
||||
objectTypesToFetch: Set<ObjectToFetch>;
|
||||
labelSelector?: string;
|
||||
customResources: CustomResource[];
|
||||
namespace?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface FetchResponseWrapper {
|
||||
errors: KubernetesFetchError[];
|
||||
responses: FetchResponse[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches information from a kubernetes cluster using the cluster details object to target a specific cluster
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export interface KubernetesFetcher {
|
||||
fetchObjectsForService(
|
||||
params: ObjectFetchParams,
|
||||
): Promise<FetchResponseWrapper>;
|
||||
fetchPodMetricsByNamespaces(
|
||||
clusterDetails: ClusterDetails,
|
||||
credential: KubernetesCredential,
|
||||
namespaces: Set<string>,
|
||||
labelSelector?: string,
|
||||
): Promise<FetchResponseWrapper>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user