diff --git a/.changeset/dirty-turkeys-remain.md b/.changeset/dirty-turkeys-remain.md new file mode 100644 index 0000000000..f9119e3880 --- /dev/null +++ b/.changeset/dirty-turkeys-remain.md @@ -0,0 +1,6 @@ +--- +'@backstage/plugin-kubernetes-backend': patch +'@backstage/plugin-kubernetes': patch +--- + +refactor: use `KUBERNETES_ANNOTATION` and `KUBERNETES_LABEL_SELECTOR_QUERY_ANNOTATION` annotations from `kubernetes-common` diff --git a/.changeset/dull-coats-help.md b/.changeset/dull-coats-help.md new file mode 100644 index 0000000000..60a099da2e --- /dev/null +++ b/.changeset/dull-coats-help.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-kubernetes-common': patch +--- + +Export `backstage.io/kubernetes-id` and `backstage.io/kubernetes-label-selector` annotations as constants diff --git a/plugins/kubernetes-backend/report.api.md b/plugins/kubernetes-backend/report.api.md index 281c8e5cac..345c53f65b 100644 --- a/plugins/kubernetes-backend/report.api.md +++ b/plugins/kubernetes-backend/report.api.md @@ -99,7 +99,7 @@ export type CustomResource = k8sAuthTypes.CustomResource; export type CustomResourcesByEntity = k8sAuthTypes.CustomResourcesByEntity; // @public (undocumented) -export const DEFAULT_OBJECTS: ObjectToFetch[]; +export const DEFAULT_OBJECTS: ObjectToFetch_2[]; // @public export class DispatchStrategy implements AuthenticationStrategy_2 { diff --git a/plugins/kubernetes-backend/src/service/KubernetesFanOutHandler.ts b/plugins/kubernetes-backend/src/service/KubernetesFanOutHandler.ts index 74be477578..424212287f 100644 --- a/plugins/kubernetes-backend/src/service/KubernetesFanOutHandler.ts +++ b/plugins/kubernetes-backend/src/service/KubernetesFanOutHandler.ts @@ -16,13 +16,8 @@ import { Entity } from '@backstage/catalog-model'; import { - CustomResource, - FetchResponseWrapper, - KubernetesFetcher, KubernetesObjectsProviderOptions, - KubernetesServiceLocator, ObjectsByEntityRequest, - ObjectToFetch, } from '../types/types'; import { ClientContainerStatus, @@ -31,6 +26,8 @@ import { ClusterObjects, CustomResourceMatcher, FetchResponse, + KUBERNETES_ANNOTATION, + KUBERNETES_LABEL_SELECTOR_QUERY_ANNOTATION, KubernetesRequestAuth, ObjectsByEntityResponse, PodFetchResponse, @@ -44,10 +41,15 @@ import { import { AuthenticationStrategy, ClusterDetails, + CustomResource, CustomResourcesByEntity, + FetchResponseWrapper, KubernetesCredential, + KubernetesFetcher, KubernetesObjectsByEntity, KubernetesObjectsProvider, + KubernetesServiceLocator, + ObjectToFetch, } from '@backstage/plugin-kubernetes-node'; import { BackstageCredentials, @@ -285,8 +287,8 @@ export class KubernetesFanOutHandler implements KubernetesObjectsProvider { const labelSelector: string = entity.metadata?.annotations?.[ - 'backstage.io/kubernetes-label-selector' - ] || `backstage.io/kubernetes-id=${entityName}`; + KUBERNETES_LABEL_SELECTOR_QUERY_ANNOTATION + ] || `${KUBERNETES_ANNOTATION}=${entityName}`; const namespace = entity.metadata?.annotations?.['backstage.io/kubernetes-namespace']; diff --git a/plugins/kubernetes-common/report.api.md b/plugins/kubernetes-common/report.api.md index cc99e5063d..80486259a2 100644 --- a/plugins/kubernetes-common/report.api.md +++ b/plugins/kubernetes-common/report.api.md @@ -317,6 +317,13 @@ export interface JobsFetchResponse { type: 'jobs'; } +// @public +export const KUBERNETES_ANNOTATION = 'backstage.io/kubernetes-id'; + +// @public +export const KUBERNETES_LABEL_SELECTOR_QUERY_ANNOTATION = + 'backstage.io/kubernetes-label-selector'; + // @public export const kubernetesClustersReadPermission: BasicPermission; diff --git a/plugins/kubernetes-common/src/catalog-entity-constants.ts b/plugins/kubernetes-common/src/catalog-entity-constants.ts index 996faf670d..472e19ef7a 100644 --- a/plugins/kubernetes-common/src/catalog-entity-constants.ts +++ b/plugins/kubernetes-common/src/catalog-entity-constants.ts @@ -14,6 +14,29 @@ * limitations under the License. */ +/** + * The annotation key used to identify Kubernetes resources in Backstage. + * This constant represents the standard annotation 'backstage.io/kubernetes-id' + * which links catalog entities to their corresponding Kubernetes resources. + * + * @public + */ +export const KUBERNETES_ANNOTATION = 'backstage.io/kubernetes-id'; + +/** + * Annotation used to specify a Kubernetes label selector query for filtering resources. + * When this annotation is added to a catalog entity, it defines criteria for selecting + * Kubernetes resources based on their labels. + * + * @public + * + * @remarks + * The value of this annotation should be a valid Kubernetes label selector query string. + * For example: 'app=my-app,environment=production' + */ +export const KUBERNETES_LABEL_SELECTOR_QUERY_ANNOTATION = + 'backstage.io/kubernetes-label-selector'; + /** * Annotation for specifying the API server of a Kubernetes cluster * diff --git a/plugins/kubernetes/src/Router.tsx b/plugins/kubernetes/src/Router.tsx index db54d6c513..c613de92c3 100644 --- a/plugins/kubernetes/src/Router.tsx +++ b/plugins/kubernetes/src/Router.tsx @@ -23,10 +23,10 @@ import { import { Route, Routes } from 'react-router-dom'; import { KubernetesContent } from './KubernetesContent'; import Button from '@material-ui/core/Button'; - -const KUBERNETES_ANNOTATION = 'backstage.io/kubernetes-id'; -const KUBERNETES_LABEL_SELECTOR_QUERY_ANNOTATION = - 'backstage.io/kubernetes-label-selector'; +import { + KUBERNETES_ANNOTATION, + KUBERNETES_LABEL_SELECTOR_QUERY_ANNOTATION, +} from '@backstage/plugin-kubernetes-common'; export const isKubernetesAvailable = (entity: Entity) => Boolean(entity.metadata.annotations?.[KUBERNETES_ANNOTATION]) ||