import * as k8s from '@kubernetes/client-node'; import { Logger } from 'winston'; import { ResourceOperations } from './ResourceOperations.js'; import type { ApiType, Configuration } from '@kubernetes/client-node'; /** * Configuration options for KubernetesClient */ export interface KubernetesClientConfig { /** * Path to kubeconfig file. If not specified, will try default locations */ kubeConfigPath?: string; /** * Specific context to use from kubeconfig. If not specified, uses current context */ context?: string; /** * Whether to use in-cluster configuration (for pods running inside k8s) */ inCluster?: boolean; /** * Bearer token for authentication */ bearerToken?: string; /** * Kubernetes API server URL (used with bearerToken) */ apiServerUrl?: string; /** * Skip TLS verification (not recommended for production) */ skipTlsVerify?: boolean; /** * Logger instance for debug output */ logger?: Logger; } /** * Authentication method types */ export declare enum AuthMethod { KUBECONFIG = "kubeconfig", IN_CLUSTER = "in-cluster", TOKEN = "token" } /** * KubernetesClient provides a high-level interface for interacting with Kubernetes clusters */ export declare class KubernetesClient { private config; private kc; private coreV1Api; private appsV1Api; private batchV1Api; private networkingV1Api; private storageV1Api; private autoscalingV2Api; private policyV1Api; private discoveryV1Api; private rbacAuthorizationV1Api; private authorizationV1Api; private authMethod; private logger?; private _resources; private _customObjectsApi?; constructor(config?: KubernetesClientConfig); /** * Detect which authentication method to use based on configuration */ private detectAuthMethod; /** * Initialize the Kubernetes client based on the detected auth method */ private initializeClient; /** * Initialize using kubeconfig file */ private initializeKubeConfig; /** * Initialize using in-cluster configuration */ private initializeInClusterConfig; /** * Initialize using bearer token */ private initializeTokenConfig; /** * Get the path to the kubeconfig file */ private getKubeConfigPath; /** * Initialize API clients for different Kubernetes resources */ private initializeApiClients; /** * Get the current cluster information */ getCurrentCluster(): k8s.Cluster | null; /** * Get the current context name */ getCurrentContext(): string; /** * Get the current namespace from the active context, falling back to 'default' if undefined */ getCurrentNamespace(): string | undefined; /** * Get all available contexts */ getContexts(): string[]; /** * Refresh the current context by reloading the kubeconfig file * This ensures we always use the latest context when executing operations */ refreshCurrentContext(): Promise; /** * Switch to a different context */ switchContext(contextName: string): Promise; /** * Get the authentication method being used */ getAuthMethod(): AuthMethod; /** * Test the connection to the Kubernetes API server */ testConnection(): Promise; /** * Factory method to create a KubernetesClient from a kubeconfig file */ static fromKubeConfig(kubeConfigPath?: string, context?: string, logger?: Logger): KubernetesClient; /** * Factory method to create a KubernetesClient for in-cluster use */ static fromInCluster(logger?: Logger): KubernetesClient; /** * Factory method to create a KubernetesClient using a bearer token */ static fromToken(apiServerUrl: string, bearerToken: string, skipTlsVerify?: boolean, logger?: Logger): KubernetesClient; get core(): k8s.CoreV1Api; get apps(): k8s.AppsV1Api; get batch(): k8s.BatchV1Api; get networking(): k8s.NetworkingV1Api; get storage(): k8s.StorageV1Api; get kubeConfig(): k8s.KubeConfig; get autoscaling(): k8s.AutoscalingV2Api; get policy(): k8s.PolicyV1Api; get discovery(): k8s.DiscoveryV1Api; get rbac(): k8s.RbacAuthorizationV1Api; get authorization(): k8s.AuthorizationV1Api; /** * Get resource operations for working with Kubernetes resources */ get resources(): ResourceOperations; /** * Returns a Kubernetes API client for the specified API constructor. * This allows for accessing various Kubernetes APIs in a type-safe manner. * @param apiClientConstructor The constructor of the API client to instantiate (e.g., k8s.CoreV1Api). * It should conform to `new (config: Configuration) => T`. * @returns An instance of the requested API client. */ getGenericApiClient(apiClientConstructor: new (config: Configuration) => T): T; /** * Makes a generic GET request to the Kubernetes API server. * This is useful for accessing API endpoints not covered by specific client APIs (e.g., custom resources or aggregated APIs like metrics.k8s.io). * @param path The API path to request (e.g., '/apis/metrics.k8s.io/v1beta1/nodes'). * @returns A promise that resolves with the API response. * @throws Will throw an error if the request fails. */ getRaw(path: string): Promise; get customObjects(): k8s.CustomObjectsApi; /** * Sets whether to skip TLS verification for API requests * @param skip True to skip TLS verification, false otherwise */ setSkipTlsVerify(skip: boolean): void; } //# sourceMappingURL=KubernetesClient.d.ts.map