Skip to content

Commit addb965

Browse files
committed
begin migration to native fetch()
Refs: #2306
1 parent 489e624 commit addb965

File tree

12 files changed

+863
-36
lines changed

12 files changed

+863
-36
lines changed

package-lock.json

Lines changed: 856 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
"husky": "^9.0.6",
8686
"mocha": "^11.0.1",
8787
"mock-fs": "^5.2.0",
88-
"nock": "^13.2.9",
88+
"nock": "^14.0.2",
8989
"prettier": "^3.0.0",
9090
"pretty-quick": "^4.0.0",
9191
"ts-mockito": "^2.3.1",

src/config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import yaml from 'js-yaml';
44
import net from 'node:net';
55
import path from 'node:path';
66

7-
import { Headers, RequestInit } from 'node-fetch';
87
import { RequestContext } from './api.js';
98
import { Authenticator } from './auth.js';
109
import { AzureAuth } from './azure_auth.js';

src/config_test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { mock } from 'node:test';
1010
import mockfs from 'mock-fs';
1111

1212
import { Authenticator } from './auth.js';
13-
import { Headers } from 'node-fetch';
1413
import { HttpMethod } from './index.js';
1514
import { assertRequestAgentsEqual, assertRequestOptionsEqual } from './test/match-buffer.js';
1615
import { CoreV1Api, RequestContext } from './api.js';
@@ -295,7 +294,7 @@ describe('KubeConfig', () => {
295294
strictEqual(headers.get('list'), 'a, b');
296295
strictEqual(headers.get('number'), '5');
297296
strictEqual(headers.get('string'), 'str');
298-
assertRequestAgentsEqual(requestInit.agent as Agent, expectedAgent);
297+
assertRequestAgentsEqual((requestInit as any).agent as Agent, expectedAgent);
299298
});
300299
});
301300

src/health.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import fetch from 'node-fetch';
21
import { KubeConfig } from './config.js';
32
import { RequestOptions } from 'node:https';
43

src/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,3 @@ export * from './health.js';
1818
export * from './middleware.js';
1919
export * from './patch.js';
2020
export { type ConfigOptions, type User, type Cluster, type Context } from './config_types.js';
21-
22-
// Export FetchError so that instanceof checks in user code will definitely use the same instance
23-
export { FetchError } from 'node-fetch';

src/log.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import fetch from 'node-fetch';
2-
import { Writable } from 'node:stream';
1+
import { Readable, Writable } from 'node:stream';
32
import { ApiException } from './api.js';
43
import { KubeConfig } from './config.js';
54
import { V1Status } from './gen/index.js';
@@ -140,7 +139,7 @@ export class Log {
140139
const status = response.status;
141140
if (status === 200) {
142141
// TODO: the follow search param still has the stream close prematurely based on my testing
143-
response.body!.pipe(stream);
142+
Readable.fromWeb(response.body!).pipe(stream);
144143
} else if (status === 500) {
145144
const v1status = (await response.json()) as V1Status;
146145
const v1code = v1status.code;

src/metrics.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import fetch from 'node-fetch';
21
import { KubeConfig } from './config.js';
32
import { ApiException, V1Status } from './gen/index.js';
43
import { normalizeResponseHeaders } from './util.js';

src/metrics_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ describe('Metrics', () => {
148148
const metricsClient = new Metrics(kc);
149149
await rejects(metricsClient.getPodMetrics(), (err) => {
150150
ok(err instanceof ApiException);
151-
match(err.message, /connect ECONNREFUSED 127.0.0.1:51011/);
151+
match(err.message, /Error occurred in metrics request: fetch failed/);
152152
return true;
153153
});
154154
});

src/util.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Response } from 'node-fetch';
21
import { CoreV1Api, V1Container, V1Pod } from './gen/index.js';
32

43
export async function podsForNode(api: CoreV1Api, nodeName: string): Promise<V1Pod[]> {

0 commit comments

Comments
 (0)