Skip to content

Commit 1d2961c

Browse files
Merge branch 'kubernetes-client:release-1.x' into release-1.x
2 parents a2a9fd5 + 3c81be4 commit 1d2961c

File tree

5 files changed

+146
-143
lines changed

5 files changed

+146
-143
lines changed

.github/workflows/test.yml

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
name: Kubernetes Javascript Client - Validation
22

33
on:
4-
push:
5-
branches: [ master, release-1.x ]
6-
pull_request:
7-
branches: [ master, release-1.x ]
4+
push:
5+
branches: [master, release-1.x]
6+
pull_request:
7+
branches: [master, release-1.x]
88

99
jobs:
10-
build:
11-
runs-on: ubuntu-latest
12-
strategy:
13-
matrix:
14-
# Remove specific version from 20 when https://github.com/tschaub/mock-fs/issues/380 is fixed
15-
node: [ '22', '20.7.0', '18' ]
16-
name: Node ${{ matrix.node }} validation
17-
steps:
18-
- uses: actions/checkout@v2
19-
- uses: actions/setup-node@v2
20-
with:
21-
node-version: ${{ matrix.node }}
22-
# Pre-check to validate that versions match between package.json
23-
# and package-lock.json. Needs to run before npm install
24-
- run: node version-check.js
25-
- run: npm ci
26-
- run: npm test
27-
- run: npm run lint
28-
- run: npm audit --audit-level=critical
10+
build:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
node: ['23', '22', '20', '18']
15+
name: Node ${{ matrix.node }} validation
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: actions/setup-node@v4
19+
with:
20+
node-version: ${{ matrix.node }}
21+
# Pre-check to validate that versions match between package.json
22+
# and package-lock.json. Needs to run before npm install
23+
- run: node version-check.js
24+
- run: npm ci
25+
- run: npm test
26+
- run: npm run lint
27+
- run: npm audit --audit-level=critical

package-lock.json

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

src/log.ts

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import fetch from 'node-fetch';
2-
import { AbortSignal } from 'node-fetch/externals';
32
import { Writable } from 'node:stream';
43
import { ApiException } from './api';
54
import { KubeConfig } from './config';
@@ -136,36 +135,39 @@ export class Log {
136135
requestInit.signal = controller.signal as AbortSignal;
137136
requestInit.method = 'GET';
138137

139-
await fetch(requestURL.toString(), requestInit)
140-
.then((response) => {
141-
const status = response.status;
142-
if (status === 200) {
143-
// TODO: the follow search param still has the stream close prematurely based on my testing
144-
response.body.pipe(stream);
145-
} else if (status === 500) {
146-
const v1status = response.body as V1Status;
147-
const v1code = v1status.code;
148-
const v1message = v1status.message;
149-
if (v1code !== undefined && v1message !== undefined) {
150-
throw new ApiException<undefined | V1Status>(
151-
v1code,
152-
v1message,
153-
v1status,
154-
normalizeResponseHeaders(response),
155-
);
156-
}
157-
} else {
158-
throw new ApiException<undefined>(
159-
status,
160-
'Error occurred in log request',
161-
undefined,
138+
try {
139+
const response = await fetch(requestURL.toString(), requestInit);
140+
const status = response.status;
141+
if (status === 200) {
142+
// TODO: the follow search param still has the stream close prematurely based on my testing
143+
response.body.pipe(stream);
144+
} else if (status === 500) {
145+
const v1status = response.body as V1Status;
146+
const v1code = v1status.code;
147+
const v1message = v1status.message;
148+
if (v1code !== undefined && v1message !== undefined) {
149+
throw new ApiException<undefined | V1Status>(
150+
v1code,
151+
v1message,
152+
v1status,
162153
normalizeResponseHeaders(response),
163154
);
164155
}
165-
})
166-
.catch((err) => {
167-
throw new ApiException<undefined>(err, 'Error occurred in log request', undefined, err);
168-
});
156+
} else {
157+
throw new ApiException<undefined>(
158+
status,
159+
'Error occurred in log request',
160+
undefined,
161+
normalizeResponseHeaders(response),
162+
);
163+
}
164+
} catch (err: any) {
165+
if (err instanceof ApiException) {
166+
throw err;
167+
}
168+
169+
throw new ApiException<undefined>(500, 'Error occurred in log request', undefined, {});
170+
}
169171

170172
return controller;
171173
}

src/metrics.ts

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -88,44 +88,45 @@ export class Metrics {
8888
const requestInit = await this.config.applyToFetchOptions({});
8989
requestInit.method = 'GET';
9090

91-
return fetch(requestURL, requestInit)
92-
.then((response) => {
93-
return Promise.all([response.json(), response.status, response]);
94-
})
95-
.then(([json, status, response]) => {
96-
if (status === 200) {
97-
return json as T;
91+
try {
92+
const response = await fetch(requestURL, requestInit);
93+
const json = await response.json();
94+
const { status } = response;
95+
96+
if (status === 200) {
97+
return json as T;
98+
}
99+
100+
if (status === 500) {
101+
const v1status = json as V1Status;
102+
const v1code = v1status.code;
103+
const v1message = v1status.message;
104+
if (v1code !== undefined && v1message !== undefined) {
105+
throw new ApiException<undefined | V1Status>(
106+
v1code,
107+
v1message,
108+
v1status,
109+
normalizeResponseHeaders(response),
110+
);
98111
}
99-
if (status === 500) {
100-
const v1status = json as V1Status;
101-
const v1code = v1status.code;
102-
const v1message = v1status.message;
103-
if (v1code !== undefined && v1message !== undefined) {
104-
throw new ApiException<undefined | V1Status>(
105-
v1code,
106-
v1message,
107-
v1status,
108-
normalizeResponseHeaders(response),
109-
);
110-
}
111-
}
112-
throw new ApiException<undefined>(
113-
status,
114-
'Error occurred in metrics request',
115-
undefined,
116-
normalizeResponseHeaders(response),
117-
);
118-
})
119-
.catch((e) => {
120-
if (e instanceof ApiException) {
121-
throw e;
122-
}
123-
throw new ApiException<undefined | V1Status>(
124-
500,
125-
`Error occurred in metrics request: ${e.message}`,
126-
{},
127-
{},
128-
);
129-
});
112+
}
113+
114+
throw new ApiException<undefined>(
115+
status,
116+
'Error occurred in metrics request',
117+
undefined,
118+
normalizeResponseHeaders(response),
119+
);
120+
} catch (e: any) {
121+
if (e instanceof ApiException) {
122+
throw e;
123+
}
124+
throw new ApiException<undefined | V1Status>(
125+
500,
126+
`Error occurred in metrics request: ${e.message}`,
127+
{},
128+
{},
129+
);
130+
}
130131
}
131132
}

src/watch.ts

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { createInterface } from 'node:readline';
22
import fetch from 'node-fetch';
3-
import { AbortSignal } from 'node-fetch/externals';
43
import { KubeConfig } from './config';
54

65
export class Watch {
@@ -51,34 +50,36 @@ export class Watch {
5150
}
5251
};
5352

54-
await fetch(watchURL, requestInit)
55-
.then((response) => {
56-
if (response.status === 200) {
57-
response.body.on('error', doneCallOnce);
58-
response.body.on('close', () => doneCallOnce(null));
59-
response.body.on('finish', () => doneCallOnce(null));
53+
try {
54+
const response = await fetch(watchURL, requestInit);
6055

61-
const lines = createInterface(response.body);
62-
lines.on('error', doneCallOnce);
63-
lines.on('close', () => doneCallOnce(null));
64-
lines.on('finish', () => doneCallOnce(null));
65-
lines.on('line', (line) => {
66-
try {
67-
const data = JSON.parse(line.toString());
68-
callback(data.type, data.object, data);
69-
} catch (ignore) {
70-
// ignore parse errors
71-
}
72-
});
73-
} else {
74-
const error = new Error(response.statusText) as Error & {
75-
statusCode: number | undefined;
76-
};
77-
error.statusCode = response.status;
78-
throw error;
79-
}
80-
})
81-
.catch(doneCallOnce);
56+
if (response.status === 200) {
57+
response.body.on('error', doneCallOnce);
58+
response.body.on('close', () => doneCallOnce(null));
59+
response.body.on('finish', () => doneCallOnce(null));
60+
61+
const lines = createInterface(response.body);
62+
lines.on('error', doneCallOnce);
63+
lines.on('close', () => doneCallOnce(null));
64+
lines.on('finish', () => doneCallOnce(null));
65+
lines.on('line', (line) => {
66+
try {
67+
const data = JSON.parse(line.toString());
68+
callback(data.type, data.object, data);
69+
} catch (ignore) {
70+
// ignore parse errors
71+
}
72+
});
73+
} else {
74+
const error = new Error(response.statusText) as Error & {
75+
statusCode: number | undefined;
76+
};
77+
error.statusCode = response.status;
78+
throw error;
79+
}
80+
} catch (err) {
81+
doneCallOnce(err);
82+
}
8283

8384
return controller;
8485
}

0 commit comments

Comments
 (0)