diff --git a/.changeset/plenty-falcons-travel.md b/.changeset/plenty-falcons-travel.md new file mode 100644 index 0000000000..cfc3ffd6f5 --- /dev/null +++ b/.changeset/plenty-falcons-travel.md @@ -0,0 +1,6 @@ +--- +'@backstage/plugin-kubernetes-node': minor +'@backstage/plugin-kubernetes-backend': patch +--- + +The `kubernetes-node` plugin has been modified to house a new extension points for Kubernetes backend plugin; `KubernetesClusterSupplierExtensionPoint` is introduced . The `kubernetes-backend` plugin was modified to use this new extension point. diff --git a/plugins/kubernetes-backend/src/plugin.ts b/plugins/kubernetes-backend/src/plugin.ts index 83dbae15a0..2d5f1e1d46 100644 --- a/plugins/kubernetes-backend/src/plugin.ts +++ b/plugins/kubernetes-backend/src/plugin.ts @@ -26,6 +26,9 @@ import { KubernetesObjectsProviderExtensionPoint, kubernetesObjectsProviderExtensionPoint, KubernetesObjectsProvider, + KubernetesClusterSupplierExtensionPoint, + kubernetesClusterSupplierExtensionPoint, + KubernetesClustersSupplier, } from '@backstage/plugin-kubernetes-node'; class ObjectsProvider implements KubernetesObjectsProviderExtensionPoint { @@ -45,6 +48,23 @@ class ObjectsProvider implements KubernetesObjectsProviderExtensionPoint { } } +class ClusterSuplier implements KubernetesClusterSupplierExtensionPoint { + private clusterSupplier: KubernetesClustersSupplier | undefined; + + getClusterSupplier() { + return this.clusterSupplier; + } + + addClusterSupplier(clusterSupplier: KubernetesClustersSupplier) { + if (this.clusterSupplier) { + throw new Error( + 'Multiple Kubernetes Cluster Suppliers is not supported at this time', + ); + } + this.clusterSupplier = clusterSupplier; + } +} + /** * This is the backend plugin that provides the Kubernetes integration. * @alpha @@ -53,10 +73,15 @@ class ObjectsProvider implements KubernetesObjectsProviderExtensionPoint { export const kubernetesPlugin = createBackendPlugin({ pluginId: 'kubernetes', register(env) { - const extensionPoint = new ObjectsProvider(); + const extPointObjectsProvider = new ObjectsProvider(); + const extPointClusterSuplier = new ClusterSuplier(); env.registerExtensionPoint( kubernetesObjectsProviderExtensionPoint, - extensionPoint, + extPointObjectsProvider, + ); + env.registerExtensionPoint( + kubernetesClusterSupplierExtensionPoint, + extPointClusterSuplier, ); env.registerInit({ @@ -76,7 +101,8 @@ export const kubernetesPlugin = createBackendPlugin({ catalogApi, permissions, }) - .setObjectsProvider(extensionPoint.getObjectsProvider()) + .setObjectsProvider(extPointObjectsProvider.getObjectsProvider()) + .setClusterSupplier(extPointClusterSuplier.getClusterSupplier()) .build(); http.use(router); }, diff --git a/plugins/kubernetes-backend/src/types/index.ts b/plugins/kubernetes-backend/src/types/index.ts index c8413c1aa9..17ce00d020 100644 --- a/plugins/kubernetes-backend/src/types/index.ts +++ b/plugins/kubernetes-backend/src/types/index.ts @@ -17,7 +17,10 @@ export * from './types'; export type { + AuthMetadata, + ClusterDetails, CustomResourcesByEntity, + KubernetesClustersSupplier, KubernetesObjectsByEntity, KubernetesObjectsProvider, } from '@backstage/plugin-kubernetes-node'; diff --git a/plugins/kubernetes-backend/src/types/types.ts b/plugins/kubernetes-backend/src/types/types.ts index 6781dc1161..a4bd38802b 100644 --- a/plugins/kubernetes-backend/src/types/types.ts +++ b/plugins/kubernetes-backend/src/types/types.ts @@ -16,7 +16,6 @@ import { Entity } from '@backstage/catalog-model'; import { Logger } from 'winston'; -import type { JsonObject } from '@backstage/types'; import type { CustomResourceMatcher, FetchResponse, @@ -25,6 +24,7 @@ import type { } from '@backstage/plugin-kubernetes-common'; import { Config } from '@backstage/config'; import { KubernetesCredential } from '../auth/types'; +import { ClusterDetails } from '@backstage/plugin-kubernetes-node'; /** * @@ -107,20 +107,6 @@ export type KubernetesObjectTypes = // If updating this list, also make sure to update // `objectTypes` and `apiVersionOverrides` in config.d.ts! -/** - * Used to load cluster details from different sources - * @public - */ -export interface KubernetesClustersSupplier { - /** - * Returns the cached list of clusters. - * - * Implementations _should_ cache the clusters and refresh them periodically, - * as getClusters is called whenever the list of clusters is needed. - */ - getClusters(): Promise; -} - /** * @public */ @@ -146,70 +132,6 @@ export interface KubernetesServiceLocator { */ export type ServiceLocatorMethod = 'multiTenant' | 'singleTenant' | 'http'; // TODO implement http -/** - * Provider-specific authentication configuration - * @public - */ -export type AuthMetadata = Record; - -/** - * - * @public - */ -export interface ClusterDetails { - /** - * Specifies the name of the Kubernetes cluster. - */ - name: string; - url: string; - authMetadata: AuthMetadata; - skipTLSVerify?: boolean; - /** - * Whether to skip the lookup to the metrics server to retrieve pod resource usage. - * It is not guaranteed that the Kubernetes distro has the metrics server installed. - */ - skipMetricsLookup?: boolean; - caData?: string | undefined; - caFile?: string | undefined; - /** - * Specifies the link to the Kubernetes dashboard managing this cluster. - * @remarks - * Note that you should specify the app used for the dashboard - * using the dashboardApp property, in order to properly format - * links to kubernetes resources, otherwise it will assume that you're running the standard one. - * @see dashboardApp - * @see dashboardParameters - */ - dashboardUrl?: string; - /** - * Specifies the app that provides the Kubernetes dashboard. - * This will be used for formatting links to kubernetes objects inside the dashboard. - * @remarks - * The existing apps are: standard, rancher, openshift, gke, aks, eks - * Note that it will default to the regular dashboard provided by the Kubernetes project (standard). - * Note that you can add your own formatter by registering it to the clusterLinksFormatters dictionary. - * @defaultValue standard - * @see dashboardUrl - * @example - * ```ts - * import { clusterLinksFormatters } from '@backstage/plugin-kubernetes'; - * clusterLinksFormatters.myDashboard = (options) => ...; - * ``` - */ - dashboardApp?: string; - /** - * Specifies specific parameters used by some dashboard URL formatters. - * This is used by the GKE formatter which requires the project, region and cluster name. - * @see dashboardApp - */ - dashboardParameters?: JsonObject; - /** - * Specifies which custom resources to look for when returning an entity's - * Kubernetes resources. - */ - customResources?: CustomResourceMatcher[]; -} - /** * * @public diff --git a/plugins/kubernetes-node/package.json b/plugins/kubernetes-node/package.json index 25e7a5da44..56f4ba01c4 100644 --- a/plugins/kubernetes-node/package.json +++ b/plugins/kubernetes-node/package.json @@ -30,6 +30,7 @@ "dependencies": { "@backstage/backend-plugin-api": "workspace:^", "@backstage/catalog-model": "workspace:^", - "@backstage/plugin-kubernetes-common": "workspace:^" + "@backstage/plugin-kubernetes-common": "workspace:^", + "@backstage/types": "workspace:^" } } diff --git a/plugins/kubernetes-node/src/extensions.ts b/plugins/kubernetes-node/src/extensions.ts index 152622cf96..3975fa65c3 100644 --- a/plugins/kubernetes-node/src/extensions.ts +++ b/plugins/kubernetes-node/src/extensions.ts @@ -14,6 +14,7 @@ * limitations under the License. */ import { createExtensionPoint } from '@backstage/backend-plugin-api'; +import { KubernetesClustersSupplier } from '@backstage/plugin-kubernetes-node'; import { KubernetesObjectsProvider } from '@backstage/plugin-kubernetes-node'; /** @@ -34,3 +35,22 @@ export const kubernetesObjectsProviderExtensionPoint = createExtensionPoint({ id: 'kubernetes.objects-provider', }); + +/** + * The interface for {@link kubernetesClusterSupplierExtensionPoint}. + * + * @public + */ +export interface KubernetesClusterSupplierExtensionPoint { + addClusterSupplier(clusterSupplier: KubernetesClustersSupplier): void; +} + +/** + * An extension point the exposes the ability to configure a cluster supplier. + * + * @public + */ +export const kubernetesClusterSupplierExtensionPoint = + createExtensionPoint({ + id: 'kubernetes.cluster-supplier', + }); diff --git a/plugins/kubernetes-node/src/index.ts b/plugins/kubernetes-node/src/index.ts index 09ea4123ce..a3da594b43 100644 --- a/plugins/kubernetes-node/src/index.ts +++ b/plugins/kubernetes-node/src/index.ts @@ -32,6 +32,8 @@ export { kubernetesObjectsProviderExtensionPoint, type KubernetesObjectsProviderExtensionPoint, + kubernetesClusterSupplierExtensionPoint, + type KubernetesClusterSupplierExtensionPoint, } from './extensions'; export * from './types'; diff --git a/plugins/kubernetes-node/src/types/types.ts b/plugins/kubernetes-node/src/types/types.ts index 182f3ecfeb..f9f60b7085 100644 --- a/plugins/kubernetes-node/src/types/types.ts +++ b/plugins/kubernetes-node/src/types/types.ts @@ -19,6 +19,7 @@ import { KubernetesRequestAuth, ObjectsByEntityResponse, } from '@backstage/plugin-kubernetes-common'; +import { JsonObject } from '@backstage/types'; /** * @@ -51,3 +52,81 @@ export interface KubernetesObjectsByEntity { export interface CustomResourcesByEntity extends KubernetesObjectsByEntity { customResources: CustomResourceMatcher[]; } + +/** + * Provider-specific authentication configuration + * @public + */ +export type AuthMetadata = Record; + +/** + * + * @public + */ +export interface ClusterDetails { + /** + * Specifies the name of the Kubernetes cluster. + */ + name: string; + url: string; + authMetadata: AuthMetadata; + skipTLSVerify?: boolean; + /** + * Whether to skip the lookup to the metrics server to retrieve pod resource usage. + * It is not guaranteed that the Kubernetes distro has the metrics server installed. + */ + skipMetricsLookup?: boolean; + caData?: string | undefined; + caFile?: string | undefined; + /** + * Specifies the link to the Kubernetes dashboard managing this cluster. + * @remarks + * Note that you should specify the app used for the dashboard + * using the dashboardApp property, in order to properly format + * links to kubernetes resources, otherwise it will assume that you're running the standard one. + * @see dashboardApp + * @see dashboardParameters + */ + dashboardUrl?: string; + /** + * Specifies the app that provides the Kubernetes dashboard. + * This will be used for formatting links to kubernetes objects inside the dashboard. + * @remarks + * The existing apps are: standard, rancher, openshift, gke, aks, eks + * Note that it will default to the regular dashboard provided by the Kubernetes project (standard). + * Note that you can add your own formatter by registering it to the clusterLinksFormatters dictionary. + * @defaultValue standard + * @see dashboardUrl + * @example + * ```ts + * import { clusterLinksFormatters } from '@backstage/plugin-kubernetes'; + * clusterLinksFormatters.myDashboard = (options) => ...; + * ``` + */ + dashboardApp?: string; + /** + * Specifies specific parameters used by some dashboard URL formatters. + * This is used by the GKE formatter which requires the project, region and cluster name. + * @see dashboardApp + */ + dashboardParameters?: JsonObject; + /** + * Specifies which custom resources to look for when returning an entity's + * Kubernetes resources. + */ + customResources?: CustomResourceMatcher[]; +} + +/** + * Used to load cluster details from different sources + * @public + */ +export interface KubernetesClustersSupplier { + /** + * Returns the cached list of clusters. + * + * Implementations _should_ cache the clusters and refresh them periodically, + * as getClusters is called whenever the list of clusters is needed. + */ + getClusters(): Promise; +} diff --git a/yarn.lock b/yarn.lock index 8a7e8a1dac..0d8a47e589 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7673,6 +7673,7 @@ __metadata: "@backstage/catalog-model": "workspace:^" "@backstage/cli": "workspace:^" "@backstage/plugin-kubernetes-common": "workspace:^" + "@backstage/types": "workspace:^" languageName: unknown linkType: soft