Skip to content

Commit d7cfec6

Browse files
authored
Merge pull request #2359 from cjihrig/revert
Revert "begin migration to native fetch()"
2 parents b0a62db + 77380b8 commit d7cfec6

File tree

13 files changed

+1199
-1112
lines changed

13 files changed

+1199
-1112
lines changed

package-lock.json

Lines changed: 1180 additions & 1104 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
@@ -83,7 +83,7 @@
8383
"eslint-plugin-erasable-syntax-only": "^0.3.0",
8484
"husky": "^9.0.6",
8585
"mock-fs": "^5.2.0",
86-
"nock": "^14.0.2",
86+
"nock": "^13.2.9",
8787
"prettier": "^3.0.0",
8888
"pretty-quick": "^4.0.0",
8989
"ts-mockito": "^2.3.1",

src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ 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';
78
import { RequestContext } from './api.js';
89
import { Authenticator } from './auth.js';
910
import { AzureAuth } from './azure_auth.js';

src/config_test.ts

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

1212
import { Authenticator } from './auth.js';
13+
import { Headers } from 'node-fetch';
1314
import { HttpMethod } from './index.js';
1415
import { assertRequestAgentsEqual, assertRequestOptionsEqual } from './test/match-buffer.js';
1516
import { CoreV1Api, RequestContext } from './api.js';
@@ -294,7 +295,7 @@ describe('KubeConfig', () => {
294295
strictEqual(headers.get('list'), 'a, b');
295296
strictEqual(headers.get('number'), '5');
296297
strictEqual(headers.get('string'), 'str');
297-
assertRequestAgentsEqual((requestInit as any).agent as Agent, expectedAgent);
298+
assertRequestAgentsEqual(requestInit.agent as Agent, expectedAgent);
298299
});
299300
});
300301

src/health.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import fetch from 'node-fetch';
12
import { KubeConfig } from './config.js';
23
import { RequestOptions } from 'node:https';
34

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@ 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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Readable, Writable } from 'node:stream';
1+
import fetch from 'node-fetch';
2+
import { Writable } from 'node:stream';
23
import { ApiException } from './api.js';
34
import { KubeConfig } from './config.js';
45
import { V1Status } from './gen/index.js';
@@ -139,7 +140,7 @@ export class Log {
139140
const status = response.status;
140141
if (status === 200) {
141142
// TODO: the follow search param still has the stream close prematurely based on my testing
142-
Readable.fromWeb(response.body!).pipe(stream);
143+
response.body!.pipe(stream);
143144
} else if (status === 500) {
144145
const v1status = (await response.json()) as V1Status;
145146
const v1code = v1status.code;

src/metrics.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import fetch from 'node-fetch';
12
import { KubeConfig } from './config.js';
23
import { ApiException, V1Status } from './gen/index.js';
34
import { normalizeResponseHeaders } from './util.js';

src/metrics_test.ts

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

src/util.ts

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

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

0 commit comments

Comments
 (0)