Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from 'node:fs';
import https from 'node:https';
import http from 'node:http';
import yaml from 'js-yaml';
import net from 'node:net';
import path from 'node:path';
Expand Down Expand Up @@ -544,6 +545,8 @@ export class KubeConfig implements SecurityAuthentication {
} else {
throw new Error('Unsupported proxy type');
}
} else if (cluster && cluster.server && cluster.server.startsWith('http:')) {
agent = new http.Agent(agentOptions);
} else {
agent = new https.Agent(agentOptions);
}
Expand Down
27 changes: 26 additions & 1 deletion src/config_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { deepEqual, deepStrictEqual, notStrictEqual, rejects, strictEqual, throw
import child_process from 'node:child_process';
import { readFileSync } from 'node:fs';
import https from 'node:https';
import http from 'node:http';
import { Agent, RequestOptions } from 'node:https';
import path, { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
Expand Down Expand Up @@ -298,7 +299,7 @@ describe('KubeConfig', () => {
});
});

describe('applyHTTPSOptions', () => {
describe.only('applyHTTPSOptions', () => {
it('should apply tls-server-name to https.RequestOptions', async () => {
const kc = new KubeConfig();
kc.loadFromFile(kcTlsServerNameFileName);
Expand Down Expand Up @@ -448,6 +449,30 @@ describe('KubeConfig', () => {
message: 'Unsupported proxy type',
});
});
it('should apply http agent if cluster.server starts with http and no proxy-url is provided', async () => {
const kc = new KubeConfig();
kc.loadFromFile(kcProxyUrl);
kc.setCurrentContext('contextE');

const testServerName = 'http://example.com';
const rc = new RequestContext(testServerName, HttpMethod.GET);

await kc.applySecurityAuthentication(rc);

strictEqual(rc.getAgent() instanceof http.Agent, true);
});
it('should apply https agent if cluster.server starts with https and no proxy-url is provided', async () => {
const kc = new KubeConfig();
kc.loadFromFile(kcProxyUrl);
kc.setCurrentContext('contextF');

const testServerName = 'https://example.com';
const rc = new RequestContext(testServerName, HttpMethod.GET);

await kc.applySecurityAuthentication(rc);

strictEqual(rc.getAgent() instanceof https.Agent, true);
});
});

describe('loadClusterConfigObjects', () => {
Expand Down