Skip to content

Commit f36a966

Browse files
committed
chore: Upgrade to @kubernetes/[email protected]
- Finally removes dependency on 'request' Signed-off-by: Sebastian Malton <[email protected]>
1 parent 90c449c commit f36a966

File tree

12 files changed

+388
-150
lines changed

12 files changed

+388
-150
lines changed

open-lens/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,6 @@
311311
"@types/react-router-dom": "^5.3.3",
312312
"@types/react-virtualized-auto-sizer": "^1.0.1",
313313
"@types/react-window": "^1.8.5",
314-
"@types/request-promise-native": "^1.0.18",
315314
"@types/tar": "^6.1.4",
316315
"@types/tcp-port-used": "^1.0.1",
317316
"@types/url-parse": "^1.4.8",

package-lock.json

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

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@
232232
"@k8slens/startable-stoppable": "^1.0.0-alpha.1",
233233
"@k8slens/tooltip": "^1.0.0-alpha.5",
234234
"@k8slens/utilities": "^1.0.0-alpha.1",
235-
"@kubernetes/client-node": "^0.18.1",
235+
"@kubernetes/client-node": "^1.0.0-rc2",
236236
"@material-ui/core": "^4.12.3",
237237
"@material-ui/lab": "^4.0.0-alpha.60",
238238
"@ogre-tools/fp": "^16.1.0",

packages/core/src/common/cluster/create-can-i.injectable.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ const createCanIInjectable = getInjectable({
2323

2424
return (api) => async (resourceAttributes: V1ResourceAttributes): Promise<boolean> => {
2525
try {
26-
const { body } = await api.createSelfSubjectAccessReview({
27-
apiVersion: "authorization.k8s.io/v1",
28-
kind: "SelfSubjectAccessReview",
29-
spec: { resourceAttributes },
26+
const review = await api.createSelfSubjectAccessReview({
27+
body: {
28+
apiVersion: "authorization.k8s.io/v1",
29+
kind: "SelfSubjectAccessReview",
30+
spec: { resourceAttributes },
31+
},
3032
});
3133

32-
return body.status?.allowed ?? false;
34+
return review.status?.allowed ?? false;
3335
} catch (error) {
3436
logger.error(`[AUTHORIZATION-REVIEW]: failed to create access review: ${error}`, { resourceAttributes });
3537

packages/core/src/common/cluster/create-request-namespace-list-permissions.injectable.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ const createRequestNamespaceListPermissionsInjectable = getInjectable({
2525

2626
return (api) => async (namespace) => {
2727
try {
28-
const { body: { status }} = await api.createSelfSubjectRulesReview({
29-
apiVersion: "authorization.k8s.io/v1",
30-
kind: "SelfSubjectRulesReview",
31-
spec: { namespace },
28+
const { status } = await api.createSelfSubjectRulesReview({
29+
body: {
30+
apiVersion: "authorization.k8s.io/v1",
31+
kind: "SelfSubjectRulesReview",
32+
spec: { namespace },
33+
},
3234
});
3335

3436
if (!status || status.incomplete) {

packages/core/src/common/cluster/list-namespaces.injectable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export type CreateListNamespaces = (api: CoreV1Api) => ListNamespaces;
1212
const createListNamespacesInjectable = getInjectable({
1313
id: "create-list-namespaces",
1414
instantiate: (): CreateListNamespaces => (api) => async () => {
15-
const { body: { items }} = await api.listNamespace();
15+
const { items } = await api.listNamespace();
1616

1717
return items
1818
.map(ns => ns.metadata?.name)

packages/core/src/common/cluster/request-namespace-list-permissions.test.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import type { AsyncFnMock } from "@async-fn/jest";
77
import asyncFn from "@async-fn/jest";
88
import type { AuthorizationV1Api, V1SubjectRulesReviewStatus } from "@kubernetes/client-node";
99
import type { DiContainer } from "@ogre-tools/injectable";
10-
import type { IncomingMessage } from "http";
1110
import { anyObject } from "jest-mock-extended";
1211
import { getDiForUnitTesting } from "../../main/getDiForUnitTesting";
1312
import { cast } from "../../test-utils/cast";
@@ -46,11 +45,13 @@ describe("requestNamespaceListPermissions", () => {
4645
});
4746

4847
it("should request the creation of a SelfSubjectRulesReview", () => {
49-
expect(createSelfSubjectRulesReviewMock).toBeCalledWith(anyObject({
50-
spec: {
51-
namespace: "irrelevant-namespace",
52-
},
53-
}));
48+
expect(createSelfSubjectRulesReviewMock).toBeCalledWith({
49+
body: anyObject({
50+
spec: {
51+
namespace: "irrelevant-namespace",
52+
},
53+
}),
54+
});
5455
});
5556

5657
([
@@ -189,11 +190,8 @@ describe("requestNamespaceListPermissions", () => {
189190
describe(`when api returns ${description}`, () => {
190191
beforeEach(async () => {
191192
await createSelfSubjectRulesReviewMock.resolve({
192-
body: {
193-
status,
194-
spec: {},
195-
},
196-
response: null as unknown as IncomingMessage,
193+
status,
194+
spec: {},
197195
});
198196
});
199197

packages/core/src/features/cluster/refresh-accessibility-technical.test.ts

Lines changed: 44 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import type { AsyncFnMock } from "@async-fn/jest";
77
import asyncFn from "@async-fn/jest";
8-
import type { AuthorizationV1Api, CoreV1Api, V1APIGroupList, V1APIVersions, V1NamespaceList, V1SelfSubjectAccessReview, V1SelfSubjectRulesReview } from "@kubernetes/client-node";
8+
import type { AuthorizationV1Api, CoreV1Api, V1APIGroupList, V1APIVersions, V1SelfSubjectAccessReview, V1SelfSubjectRulesReview } from "@kubernetes/client-node";
99
import type { Cluster } from "../../common/cluster/cluster";
1010
import createAuthorizationApiInjectable from "../../common/cluster/create-authorization-api.injectable";
1111
import writeJsonFileInjectable from "../../common/fs/write-json-file.injectable";
@@ -477,20 +477,18 @@ const nonCoreApiResponse = {
477477
} as V1APIGroupList;
478478

479479
const listNamespaceResponse = {
480-
body: {
481-
items: [
482-
{
483-
metadata: {
484-
name: "default",
485-
},
480+
items: [
481+
{
482+
metadata: {
483+
name: "default",
486484
},
487-
{
488-
metadata: {
489-
name: "my-namespace",
490-
},
485+
},
486+
{
487+
metadata: {
488+
name: "my-namespace",
491489
},
492-
],
493-
} as PartialDeep<V1NamespaceList>,
490+
},
491+
],
494492
} as Awaited<ReturnType<CoreV1Api["listNamespace"]>>;
495493

496494
const coreApiKindsResponse = {
@@ -585,51 +583,44 @@ const discoveryK8sIoKindsResponse = {
585583
],
586584
};
587585

588-
type CreateSelfSubjectRulesReviewRes = Awaited<ReturnType<AuthorizationV1Api["createSelfSubjectRulesReview"]>>;
589-
590586
const defaultIncompletePermissions = {
591-
body: {
592-
status: {
593-
incomplete: true,
594-
},
595-
} as PartialDeep<V1SelfSubjectRulesReview>,
596-
} as CreateSelfSubjectRulesReviewRes;
587+
status: {
588+
incomplete: true,
589+
},
590+
} as V1SelfSubjectRulesReview;
597591

598592
const emptyPermissions = {
599-
body: {
600-
status: {
601-
resourceRules: [],
602-
},
603-
} as PartialDeep<V1SelfSubjectRulesReview>,
604-
} as CreateSelfSubjectRulesReviewRes;
593+
status: {
594+
resourceRules: [],
595+
incomplete: false,
596+
nonResourceRules: [],
597+
},
598+
spec: {},
599+
} as V1SelfSubjectRulesReview;
605600

606601
const defaultSingleListPermissions = {
607-
body: {
608-
status: {
609-
resourceRules: [{
602+
status: {
603+
resourceRules: [{
604+
apiGroups: [""],
605+
resources: ["pods"],
606+
verbs: ["list"],
607+
}],
608+
},
609+
} as V1SelfSubjectRulesReview;
610+
611+
const defaultMultipleListPermissions = {
612+
status: {
613+
resourceRules: [
614+
{
615+
apiGroups: [""],
616+
resources: ["pods"],
617+
verbs: ["get"],
618+
},
619+
{
610620
apiGroups: [""],
611621
resources: ["pods"],
612622
verbs: ["list"],
613-
}],
614-
},
615-
} as PartialDeep<V1SelfSubjectRulesReview>,
616-
} as CreateSelfSubjectRulesReviewRes;
617-
618-
const defaultMultipleListPermissions = {
619-
body: {
620-
status: {
621-
resourceRules: [
622-
{
623-
apiGroups: [""],
624-
resources: ["pods"],
625-
verbs: ["get"],
626-
},
627-
{
628-
apiGroups: [""],
629-
resources: ["pods"],
630-
verbs: ["list"],
631-
},
632-
],
633-
},
634-
} as PartialDeep<V1SelfSubjectRulesReview>,
635-
} as CreateSelfSubjectRulesReviewRes;
623+
},
624+
],
625+
},
626+
} as V1SelfSubjectRulesReview;

packages/core/src/main/cluster/cluster-connection.injectable.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
* Licensed under MIT License. See LICENSE in root directory for more information.
44
*/
55

6-
import { type KubeConfig, HttpError } from "@kubernetes/client-node";
6+
import type { KubeConfig } from "@kubernetes/client-node";
7+
import { ApiException } from "@kubernetes/client-node";
78
import { reaction, comparer, runInAction } from "mobx";
89
import { ClusterStatus } from "../../common/cluster-types";
910
import type { CreateListNamespaces } from "../../common/cluster/list-namespaces.injectable";
@@ -375,10 +376,8 @@ class ClusterConnection {
375376
const ctx = proxyConfig.getContextObject(this.cluster.contextName.get());
376377
const namespaceList = [ctx?.namespace].filter(isDefined);
377378

378-
if (namespaceList.length === 0 && error instanceof HttpError && error.statusCode === 403) {
379-
const { response } = error as HttpError & { response: Response };
380-
381-
this.dependencies.logger.info("[CLUSTER]: listing namespaces is forbidden, broadcasting", { clusterId: this.cluster.id, error: response.body });
379+
if (namespaceList.length === 0 && error instanceof ApiException && error.code === 403) {
380+
this.dependencies.logger.info("[CLUSTER]: listing namespaces is forbidden, broadcasting", { clusterId: this.cluster.id, error: error.body || error.message });
382381
this.dependencies.broadcastMessage(clusterListNamespaceForbiddenChannel, this.cluster.id);
383382
}
384383

packages/core/src/main/prometheus/provider.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ export const createPrometheusProvider = ({ getService, ...opts }: CreatePromethe
5252
export async function findFirstNamespacedService(client: CoreV1Api, ...selectors: string[]): Promise<PrometheusServiceInfo> {
5353
try {
5454
for (const selector of selectors) {
55-
const { body: { items: [service] }} = await client.listServiceForAllNamespaces(undefined, undefined, undefined, selector);
55+
const { items: [service] } = await client.listServiceForAllNamespaces({
56+
labelSelector: selector,
57+
});
5658

5759
if (service?.metadata?.namespace && service.metadata.name && service.spec?.ports) {
5860
return {
@@ -71,7 +73,7 @@ export async function findFirstNamespacedService(client: CoreV1Api, ...selectors
7173

7274
export async function findNamespacedService(client: CoreV1Api, name: string, namespace: string): Promise<PrometheusServiceInfo> {
7375
try {
74-
const { body: service } = await client.readNamespacedService(name, namespace);
76+
const service = await client.readNamespacedService({ name, namespace });
7577

7678
if (!service.metadata?.namespace || !service.metadata.name || !service.spec?.ports) {
7779
throw new Error(`Service found in namespace="${namespace}" did not have required information`);

0 commit comments

Comments
 (0)