UNPKG

@gorizond/catalog-backend-module-fleet

Version:

Backstage catalog backend module for Rancher Fleet GitOps entities

139 lines (138 loc) 5.83 kB
/** * Entity Mapper * Converts Fleet Custom Resources to Backstage Catalog Entities * * Mapping: * - Fleet Rancher Cluster (config) → Domain * - GitRepo → System * - Bundle → Component (type: service) * - BundleDeployment → Resource (type: fleet-deployment) */ import { Entity } from "@backstage/catalog-model"; import { FleetGitRepo, FleetBundle, FleetBundleDeployment, FleetYaml, FleetYamlApiDefinition, FleetClusterConfig } from "./types"; export declare const ANNOTATION_FLEET_REPO = "fleet.cattle.io/repo"; export declare const ANNOTATION_FLEET_BRANCH = "fleet.cattle.io/branch"; export declare const ANNOTATION_FLEET_NAMESPACE = "fleet.cattle.io/namespace"; export declare const ANNOTATION_FLEET_TARGETS = "fleet.cattle.io/targets"; export declare const ANNOTATION_FLEET_REPO_NAME = "fleet.cattle.io/repo-name"; export declare const ANNOTATION_FLEET_BUNDLE_PATH = "fleet.cattle.io/bundle-path"; export declare const ANNOTATION_FLEET_STATUS = "fleet.cattle.io/status"; export declare const ANNOTATION_FLEET_READY_CLUSTERS = "fleet.cattle.io/ready-clusters"; export declare const ANNOTATION_FLEET_CLUSTER = "fleet.cattle.io/cluster"; export declare const ANNOTATION_FLEET_SOURCE_GITREPO = "fleet.cattle.io/source-gitrepo"; export declare const ANNOTATION_FLEET_SOURCE_BUNDLE = "fleet.cattle.io/source-bundle"; export declare const ANNOTATION_KUBERNETES_ID = "backstage.io/kubernetes-id"; export declare const ANNOTATION_KUBERNETES_NAMESPACE = "backstage.io/kubernetes-namespace"; export declare const ANNOTATION_KUBERNETES_LABEL_SELECTOR = "backstage.io/kubernetes-label-selector"; export declare const ANNOTATION_TECHDOCS_ENTITY = "backstage.io/techdocs-entity"; export declare function toBackstageName(value: string): string; /** * Convert a name to Backstage-safe entity name with truncation + hash * to keep it short while preserving uniqueness and ending rules. */ export declare function toStableBackstageName(value: string, maxLength?: number): string; /** * Create entity namespace from Fleet namespace */ export declare function toEntityNamespace(fleetNamespace: string): string; export interface MapperContext { cluster: FleetClusterConfig; locationKey: string; fleetYaml?: FleetYaml; autoTechdocsRef?: boolean; } export declare function mapFleetClusterToDomain(context: MapperContext, entityNamespace?: string): Entity; export declare function mapClusterToResource(clusterId: string, clusterName: string | undefined, namespace: string, context: MapperContext, details?: { version?: string; nodeCount?: number; readyNodeCount?: number; machineDeploymentCount?: number; vmCount?: number; state?: string; transitioning?: string; transitioningMessage?: string; conditions?: Array<Record<string, unknown>>; etcdBackupConfig?: Record<string, unknown>; driver?: string; }): Entity; export declare function mapNodeToResource(params: { nodeId: string; nodeName?: string; clusterId: string; clusterName?: string; workspaceNamespace: string; context: MapperContext; details?: { labels?: Record<string, string>; capacity?: Record<string, string>; allocatable?: Record<string, string>; taints?: Array<Record<string, unknown>>; addresses?: Array<Record<string, unknown>>; providerId?: string; kubeletVersion?: string; osImage?: string; containerRuntime?: string; architecture?: string; harvesterVmRef?: string; }; }): Entity; export declare function mapMachineDeploymentToResource(params: { mdName: string; clusterId: string; clusterName?: string; workspaceNamespace: string; context: MapperContext; details?: { namespace?: string; labels?: Record<string, string>; selector?: Record<string, string>; replicas?: number; availableReplicas?: number; readyReplicas?: number; updatedReplicas?: number; }; }): Entity; export declare function mapVirtualMachineToResource(params: { vmName: string; /** * Backstage-safe entity name. If not provided, vmName will be sanitized. * Allows differentiating VM entities from nodes with the same name. */ entityName?: string; clusterId: string; clusterName?: string; workspaceNamespace: string; context: MapperContext; details?: { namespace?: string; labels?: Record<string, string>; requests?: Record<string, string>; limits?: Record<string, string>; runStrategy?: string; printableStatus?: string; ready?: boolean; }; }): Entity; export declare function mapGitRepoToSystem(gitRepo: FleetGitRepo, context: MapperContext): Entity; export declare function mapBundleToComponent(bundle: FleetBundle, context: MapperContext): Entity; export declare function mapBundleDeploymentToResource(bundleDeployment: FleetBundleDeployment, clusterId: string, context: MapperContext, systemRef?: string, clusterName?: string): Entity; export declare function mapApiDefinitionToApi(apiDef: FleetYamlApiDefinition, gitRepoName: string, context: MapperContext): Entity; declare function extractWorkspaceNamespaceFromBundleDeploymentNamespace(namespace: string): string | undefined; export { extractWorkspaceNamespaceFromBundleDeploymentNamespace }; /** * Extract entity metadata from bundle labels */ export declare function extractBundleMetadata(bundle: FleetBundle): { gitRepoName?: string; bundlePath?: string; commitId?: string; }; export interface EntityBatch { domains: Entity[]; systems: Entity[]; components: Entity[]; resources: Entity[]; apis: Entity[]; } export declare function createEmptyBatch(): EntityBatch; export declare function flattenBatch(batch: EntityBatch): Entity[];