From 36ca7838492e3ff1b31fd48baf35c1ddaf81246a Mon Sep 17 00:00:00 2001 From: Daniel Lamando Date: Sun, 13 Aug 2023 20:37:13 +0200 Subject: [PATCH] fix: Retype alternate RestClient API more liberally --- transports/mod.ts | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/transports/mod.ts b/transports/mod.ts index f35fbcb..eddb8ec 100644 --- a/transports/mod.ts +++ b/transports/mod.ts @@ -39,21 +39,35 @@ export class ClientProviderChain { } } -export function makeClientProviderChain(restClientConstructor: typeof KubeConfigRestClient) { +/** Constructs the typical list of Kubernetes API clients, + * using an alternative client for connecting to KubeConfig contexts. + * The Kubectl client is unaffected by this. */ +export function makeClientProviderChain(restClientFactory: KubeConfigClientFactory) { return new ClientProviderChain([ - ['InCluster', () => restClientConstructor.forInCluster()], - ['KubeConfig', () => restClientConstructor.readKubeConfig()], - ['KubectlProxy', () => restClientConstructor.forKubectlProxy()], + ['InCluster', () => restClientFactory.forInCluster()], + ['KubeConfig', () => restClientFactory.readKubeConfig()], + ['KubectlProxy', () => restClientFactory.forKubectlProxy()], ['KubectlRaw', () => Promise.resolve(new KubectlRawRestClient())], ]); } +/** A subset of KubeConfigRestClient's static interface. */ +interface KubeConfigClientFactory { + forInCluster(): Promise; + forKubectlProxy(): Promise; + readKubeConfig( + path?: string, + contextName?: string, + ): Promise; +} + export const DefaultClientProvider = makeClientProviderChain(KubeConfigRestClient); /** - * Trial-and-error approach for automatically deciding how to talk to Kubernetes. - * You'll still need to set the correct permissions for where you are running. - * You can probably be more specific and secure with app-specific Deno.args flags. + * Automatic trial-and-error approach for deciding how to talk to Kubernetes. + * Influenced by Deno's current permissions and Deno may prompt for more permissions. + * Will emit a list of problems if no usable clients are found. + * You'll likely want to set the correct Deno permissions for your installation. */ export async function autoDetectClient(): Promise { return await DefaultClientProvider.getClient();