Skip to content

Commit

Permalink
feat: Allow using alternate RestClient class
Browse files Browse the repository at this point in the history
Useful to enable tunnel support, e.g. with WebsocketRestClient, while
still autodetecting which client configuration to use.
  • Loading branch information
danopia committed Aug 13, 2023
1 parent 2cc9950 commit 8a2259a
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions transports/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,22 @@ export class ClientProviderChain {
}
}

export const DefaultClientProvider
= new ClientProviderChain([
['InCluster', () => KubeConfigRestClient.forInCluster()],
['KubeConfig', () => KubeConfigRestClient.readKubeConfig()],
['KubectlProxy', () => KubeConfigRestClient.forKubectlProxy()],
['KubectlRaw', async () => new KubectlRawRestClient()],
export function makeClientProviderChain(restClientConstructor: typeof KubeConfigRestClient) {
return new ClientProviderChain([
['InCluster', () => restClientConstructor.forInCluster()],
['KubeConfig', () => restClientConstructor.readKubeConfig()],
['KubectlProxy', () => restClientConstructor.forKubectlProxy()],
['KubectlRaw', () => Promise.resolve(new KubectlRawRestClient())],
]);
}

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.
*/
export async function autoDetectClient(): Promise<RestClient> {
return DefaultClientProvider.getClient();
return await DefaultClientProvider.getClient();
}

0 comments on commit 8a2259a

Please sign in to comment.