@gorizond/catalog-backend-module-fleet
Version:
Backstage catalog backend module for Rancher Fleet GitOps entities
193 lines (192 loc) • 5.42 kB
TypeScript
/**
* Fleet Kubernetes Locator
*
* Dynamically discovers Rancher downstream clusters and exposes them as
* Backstage Kubernetes cluster definitions. Uses a single Rancher token that
* has access to all downstream clusters; does not mint per-cluster service
* accounts. Include `local` management cluster as well.
*/
import { Config } from "@backstage/config";
import { LoggerService } from "@backstage/backend-plugin-api";
import { CustomResourceMatcher } from "@backstage/plugin-kubernetes-common";
import type { V1Node } from "@kubernetes/client-node";
type ClusterLocatorEntry = {
name: string;
url: string;
authProvider: "serviceAccount";
serviceAccountToken: string;
caData?: string;
skipTLSVerify?: boolean;
customResources?: CustomResourceMatcher[];
};
type RancherCluster = {
id: string;
name?: string;
namespace?: string;
links?: Record<string, string>;
annotations?: Record<string, string>;
labels?: Record<string, string>;
driver?: string;
provider?: string;
caCert?: string;
clusterCIDR?: string;
state?: string;
transitioning?: string;
transitioningMessage?: string;
conditions?: Array<{
type?: string;
status?: string;
message?: string;
reason?: string;
lastUpdateTime?: string;
lastTransitionTime?: string;
}>;
rancherKubernetesEngineConfig?: {
kubernetesVersion?: string;
services?: {
etcd?: {
backupConfig?: Record<string, unknown>;
};
};
};
};
type HarvesterVirtualMachine = {
apiVersion?: string;
kind?: string;
metadata?: {
name?: string;
namespace?: string;
uid?: string;
labels?: Record<string, string>;
};
spec?: {
runStrategy?: string;
template?: {
spec?: {
domain?: {
cpu?: {
cores?: number;
};
resources?: {
requests?: Record<string, string>;
limits?: Record<string, string>;
};
};
};
};
};
status?: {
printableStatus?: string;
ready?: boolean;
conditions?: Array<Record<string, unknown>>;
};
};
type RancherNode = {
id?: string;
nodeName?: string;
hostname?: string;
name?: string;
};
type MachineDeployment = {
apiVersion?: string;
kind?: string;
metadata?: {
name?: string;
namespace?: string;
labels?: Record<string, string>;
};
spec?: {
replicas?: number;
selector?: {
matchLabels?: Record<string, string>;
};
template?: {
metadata?: {
labels?: Record<string, string>;
};
};
};
status?: {
availableReplicas?: number;
readyReplicas?: number;
updatedReplicas?: number;
};
};
export interface FleetK8sLocatorOptions {
logger: LoggerService;
config: Config;
}
/**
* Discover Rancher downstream clusters using a single Rancher token.
*/
export declare class FleetK8sLocator {
private readonly logger;
private readonly rancherUrl;
private readonly rancherToken;
private readonly skipTLSVerify;
private readonly includeLocal;
private readonly fleetNamespaces;
private constructor();
static fromConfig({ logger, config, }: FleetK8sLocatorOptions): FleetK8sLocator | undefined;
/**
* Returns cluster locator entries suitable for Backstage kubernetes plugin
* (type: config).
*/
listClusters(): Promise<ClusterLocatorEntry[]>;
/**
* Returns lightweight cluster summaries (id + friendly name) without CRD scanning.
*/
listClusterSummaries(): Promise<Array<{
id: string;
name?: string;
}>>;
listRancherClusterDetails(): Promise<RancherCluster[]>;
/**
* Return Rancher nodes grouped by cluster for use in catalog sync.
*/
listClusterNodes(): Promise<Array<{
clusterId: string;
clusterName?: string;
nodes: RancherNode[];
}>>;
/**
* Return detailed Kubernetes nodes grouped by cluster (full Node objects).
*/
listClusterNodesDetailed(): Promise<Array<{
clusterId: string;
clusterName?: string;
nodes: V1Node[];
}>>;
/**
* Return MachineDeployments grouped by cluster (if Cluster API is installed).
*/
listClusterMachineDeployments(): Promise<Array<{
clusterId: string;
clusterName?: string;
items: MachineDeployment[];
}>>;
listClusterVersions(): Promise<Array<{
clusterId: string;
clusterName?: string;
version?: string;
}>>;
listHarvesterVirtualMachines(): Promise<Array<{
clusterId: string;
clusterName?: string;
items: HarvesterVirtualMachine[];
}>>;
/**
* Convert to Backstage kubernetes.clusterLocatorMethods (type: config).
*/
asClusterLocatorMethods(): Promise<Array<{
type: "config";
clusters: ClusterLocatorEntry[];
}>>;
private fetchRancherClusters;
private fetchClusterNodes;
private buildAgent;
private fetchJson;
private fetchBundleDeployments;
private buildCustomResourcesByCluster;
}
export {};