mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fix kube=api.test.ts
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
ffb840f0ed
commit
6d720db036
@ -12,25 +12,21 @@ import { PassThrough } from "stream";
|
|||||||
import type { ApiManager } from "../api-manager";
|
import type { ApiManager } from "../api-manager";
|
||||||
import { apiManager } from "../api-manager";
|
import { apiManager } from "../api-manager";
|
||||||
import type { FetchMock } from "jest-fetch-mock/types";
|
import type { FetchMock } from "jest-fetch-mock/types";
|
||||||
|
import { DeploymentApi, Ingress, IngressApi, Pod, PodApi } from "../endpoints";
|
||||||
|
import { getDiForUnitTesting } from "../../../main/getDiForUnitTesting";
|
||||||
|
|
||||||
jest.mock("../api-manager");
|
jest.mock("../api-manager");
|
||||||
|
|
||||||
const mockApiManager = apiManager as jest.Mocked<ApiManager>;
|
const mockApiManager = apiManager as jest.Mocked<ApiManager>;
|
||||||
const mockFetch = fetch as FetchMock;
|
const mockFetch = fetch as FetchMock;
|
||||||
|
|
||||||
class TestKubeObject extends KubeObject {
|
|
||||||
static kind = "Pod";
|
|
||||||
static namespaced = true;
|
|
||||||
static apiBase = "/api/v1/pods";
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestKubeApi extends KubeApi<TestKubeObject> {
|
|
||||||
public async checkPreferredVersion() {
|
|
||||||
return super.checkPreferredVersion();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("forRemoteCluster", () => {
|
describe("forRemoteCluster", () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
const di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||||
|
|
||||||
|
await di.runSetups();
|
||||||
|
});
|
||||||
|
|
||||||
it("builds api client for KubeObject", async () => {
|
it("builds api client for KubeObject", async () => {
|
||||||
const api = forRemoteCluster({
|
const api = forRemoteCluster({
|
||||||
cluster: {
|
cluster: {
|
||||||
@ -39,7 +35,7 @@ describe("forRemoteCluster", () => {
|
|||||||
user: {
|
user: {
|
||||||
token: "daa",
|
token: "daa",
|
||||||
},
|
},
|
||||||
}, TestKubeObject);
|
}, Pod);
|
||||||
|
|
||||||
expect(api).toBeInstanceOf(KubeApi);
|
expect(api).toBeInstanceOf(KubeApi);
|
||||||
});
|
});
|
||||||
@ -52,9 +48,9 @@ describe("forRemoteCluster", () => {
|
|||||||
user: {
|
user: {
|
||||||
token: "daa",
|
token: "daa",
|
||||||
},
|
},
|
||||||
}, TestKubeObject, TestKubeApi);
|
}, Pod, PodApi);
|
||||||
|
|
||||||
expect(api).toBeInstanceOf(TestKubeApi);
|
expect(api).toBeInstanceOf(PodApi);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("calls right api endpoint", async () => {
|
it("calls right api endpoint", async () => {
|
||||||
@ -65,7 +61,7 @@ describe("forRemoteCluster", () => {
|
|||||||
user: {
|
user: {
|
||||||
token: "daa",
|
token: "daa",
|
||||||
},
|
},
|
||||||
}, TestKubeObject);
|
}, Pod);
|
||||||
|
|
||||||
mockFetch.mockResponse(async (request: any) => {
|
mockFetch.mockResponse(async (request: any) => {
|
||||||
expect(request.url).toEqual("https://127.0.0.1:6443/api/v1/pods");
|
expect(request.url).toEqual("https://127.0.0.1:6443/api/v1/pods");
|
||||||
@ -84,7 +80,11 @@ describe("forRemoteCluster", () => {
|
|||||||
describe("KubeApi", () => {
|
describe("KubeApi", () => {
|
||||||
let request: KubeJsonApi;
|
let request: KubeJsonApi;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(async () => {
|
||||||
|
const di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||||
|
|
||||||
|
await di.runSetups();
|
||||||
|
|
||||||
request = new KubeJsonApi({
|
request = new KubeJsonApi({
|
||||||
serverAddress: `http://127.0.0.1:9999`,
|
serverAddress: `http://127.0.0.1:9999`,
|
||||||
apiBase: "/api-kube",
|
apiBase: "/api-kube",
|
||||||
@ -121,9 +121,9 @@ describe("KubeApi", () => {
|
|||||||
|
|
||||||
const apiBase = "/apis/networking.k8s.io/v1/ingresses";
|
const apiBase = "/apis/networking.k8s.io/v1/ingresses";
|
||||||
const fallbackApiBase = "/apis/extensions/v1beta1/ingresses";
|
const fallbackApiBase = "/apis/extensions/v1beta1/ingresses";
|
||||||
const kubeApi = new KubeApi({
|
const kubeApi = new IngressApi({
|
||||||
request,
|
request,
|
||||||
objectConstructor: KubeObject,
|
objectConstructor: Ingress,
|
||||||
apiBase,
|
apiBase,
|
||||||
fallbackApiBases: [fallbackApiBase],
|
fallbackApiBases: [fallbackApiBase],
|
||||||
checkPreferredVersion: true,
|
checkPreferredVersion: true,
|
||||||
@ -164,9 +164,10 @@ describe("KubeApi", () => {
|
|||||||
|
|
||||||
const apiBase = "apis/networking.k8s.io/v1/ingresses";
|
const apiBase = "apis/networking.k8s.io/v1/ingresses";
|
||||||
const fallbackApiBase = "/apis/extensions/v1beta1/ingresses";
|
const fallbackApiBase = "/apis/extensions/v1beta1/ingresses";
|
||||||
const kubeApi = new KubeApi({
|
const kubeApi = new IngressApi({
|
||||||
request,
|
request,
|
||||||
objectConstructor: Object.assign(KubeObject, { apiBase }),
|
objectConstructor: Object.assign(KubeObject, { apiBase }),
|
||||||
|
kind: "Ingress",
|
||||||
fallbackApiBases: [fallbackApiBase],
|
fallbackApiBases: [fallbackApiBase],
|
||||||
checkPreferredVersion: true,
|
checkPreferredVersion: true,
|
||||||
});
|
});
|
||||||
@ -183,41 +184,38 @@ describe("KubeApi", () => {
|
|||||||
it("registers with apiManager if checkPreferredVersion changes apiVersionPreferred", async () => {
|
it("registers with apiManager if checkPreferredVersion changes apiVersionPreferred", async () => {
|
||||||
expect.hasAssertions();
|
expect.hasAssertions();
|
||||||
|
|
||||||
const api = new TestKubeApi({
|
const api = new IngressApi({
|
||||||
objectConstructor: TestKubeObject,
|
objectConstructor: Ingress,
|
||||||
checkPreferredVersion: true,
|
checkPreferredVersion: true,
|
||||||
fallbackApiBases: ["/apis/extensions/v1beta1/ingresses"],
|
fallbackApiBases: ["/apis/extensions/v1beta1/ingresses"],
|
||||||
request: {
|
request: {
|
||||||
get: jest.fn()
|
get: jest.fn()
|
||||||
.mockImplementationOnce((path: string) => {
|
.mockImplementation((path: string) => {
|
||||||
expect(path).toBe("/apis/networking.k8s.io/v1");
|
switch (path) {
|
||||||
|
case "/apis/networking.k8s.io/v1":
|
||||||
throw new Error("no");
|
throw new Error("no");
|
||||||
})
|
case "/apis/extensions/v1beta1":
|
||||||
.mockImplementationOnce((path: string) => {
|
return {
|
||||||
expect(path).toBe("/apis/extensions/v1beta1");
|
resources: [
|
||||||
|
{
|
||||||
return {
|
name: "ingresses",
|
||||||
resources: [
|
},
|
||||||
{
|
],
|
||||||
name: "ingresses",
|
};
|
||||||
},
|
case "/apis/extensions":
|
||||||
],
|
return {
|
||||||
};
|
preferredVersion: {
|
||||||
})
|
version: "v1beta1",
|
||||||
.mockImplementationOnce((path: string) => {
|
},
|
||||||
expect(path).toBe("/apis/extensions");
|
};
|
||||||
|
default:
|
||||||
return {
|
throw new Error("unknown path");
|
||||||
preferredVersion: {
|
}
|
||||||
version: "v1beta1",
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}),
|
}),
|
||||||
} as Partial<KubeJsonApi> as KubeJsonApi,
|
} as Partial<KubeJsonApi> as KubeJsonApi,
|
||||||
});
|
});
|
||||||
|
|
||||||
await api.checkPreferredVersion();
|
await (api as any).checkPreferredVersion();
|
||||||
|
|
||||||
expect(api.apiVersionPreferred).toBe("v1beta1");
|
expect(api.apiVersionPreferred).toBe("v1beta1");
|
||||||
expect(mockApiManager.registerApi).toBeCalledWith("/apis/extensions/v1beta1/ingresses", expect.anything());
|
expect(mockApiManager.registerApi).toBeCalledWith("/apis/extensions/v1beta1/ingresses", expect.anything());
|
||||||
@ -226,41 +224,38 @@ describe("KubeApi", () => {
|
|||||||
it("registers with apiManager if checkPreferredVersion changes apiVersionPreferred with non-grouped apis", async () => {
|
it("registers with apiManager if checkPreferredVersion changes apiVersionPreferred with non-grouped apis", async () => {
|
||||||
expect.hasAssertions();
|
expect.hasAssertions();
|
||||||
|
|
||||||
const api = new TestKubeApi({
|
const api = new PodApi({
|
||||||
objectConstructor: TestKubeObject,
|
objectConstructor: Pod,
|
||||||
checkPreferredVersion: true,
|
checkPreferredVersion: true,
|
||||||
fallbackApiBases: ["/api/v1beta1/pods"],
|
fallbackApiBases: ["/api/v1beta1/pods"],
|
||||||
request: {
|
request: {
|
||||||
get: jest.fn()
|
get: jest.fn()
|
||||||
.mockImplementationOnce((path: string) => {
|
.mockImplementation((path: string) => {
|
||||||
expect(path).toBe("/api/v1");
|
switch (path) {
|
||||||
|
case "/api/v1":
|
||||||
throw new Error("no");
|
throw new Error("no");
|
||||||
})
|
case "/api/v1beta1":
|
||||||
.mockImplementationOnce((path: string) => {
|
return {
|
||||||
expect(path).toBe("/api/v1beta1");
|
resources: [
|
||||||
|
{
|
||||||
return {
|
name: "pods",
|
||||||
resources: [
|
},
|
||||||
{
|
],
|
||||||
name: "pods",
|
};
|
||||||
},
|
case "/api":
|
||||||
],
|
return {
|
||||||
};
|
preferredVersion: {
|
||||||
})
|
version: "v1beta1",
|
||||||
.mockImplementationOnce((path: string) => {
|
},
|
||||||
expect(path).toBe("/api");
|
};
|
||||||
|
default:
|
||||||
return {
|
throw new Error("unknown path");
|
||||||
preferredVersion: {
|
}
|
||||||
version: "v1beta1",
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}),
|
}),
|
||||||
} as Partial<KubeJsonApi> as KubeJsonApi,
|
} as Partial<KubeJsonApi> as KubeJsonApi,
|
||||||
});
|
});
|
||||||
|
|
||||||
await api.checkPreferredVersion();
|
await (api as any).checkPreferredVersion();
|
||||||
|
|
||||||
expect(api.apiVersionPreferred).toBe("v1beta1");
|
expect(api.apiVersionPreferred).toBe("v1beta1");
|
||||||
expect(mockApiManager.registerApi).toBeCalledWith("/api/v1beta1/pods", expect.anything());
|
expect(mockApiManager.registerApi).toBeCalledWith("/api/v1beta1/pods", expect.anything());
|
||||||
@ -268,12 +263,11 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("patch", () => {
|
describe("patch", () => {
|
||||||
let api: TestKubeApi;
|
let api: DeploymentApi;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
api = new TestKubeApi({
|
api = new DeploymentApi({
|
||||||
request,
|
request,
|
||||||
objectConstructor: TestKubeObject,
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -345,12 +339,12 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("delete", () => {
|
describe("delete", () => {
|
||||||
let api: TestKubeApi;
|
let api: PodApi;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
api = new TestKubeApi({
|
api = new PodApi({
|
||||||
request,
|
request,
|
||||||
objectConstructor: TestKubeObject,
|
objectConstructor: Pod,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -404,13 +398,13 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("watch", () => {
|
describe("watch", () => {
|
||||||
let api: TestKubeApi;
|
let api: PodApi;
|
||||||
let stream: PassThrough;
|
let stream: PassThrough;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
api = new TestKubeApi({
|
api = new PodApi({
|
||||||
request,
|
request,
|
||||||
objectConstructor: TestKubeObject,
|
objectConstructor: Pod,
|
||||||
});
|
});
|
||||||
stream = new PassThrough();
|
stream = new PassThrough();
|
||||||
});
|
});
|
||||||
@ -581,12 +575,12 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("create", () => {
|
describe("create", () => {
|
||||||
let api: TestKubeApi;
|
let api: PodApi;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
api = new TestKubeApi({
|
api = new PodApi({
|
||||||
request,
|
request,
|
||||||
objectConstructor: TestKubeObject,
|
objectConstructor: Pod,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -678,12 +672,12 @@ describe("KubeApi", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("update", () => {
|
describe("update", () => {
|
||||||
let api: TestKubeApi;
|
let api: PodApi;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
api = new TestKubeApi({
|
api = new PodApi({
|
||||||
request,
|
request,
|
||||||
objectConstructor: TestKubeObject,
|
objectConstructor: Pod,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,6 @@
|
|||||||
import { isFunction, merge } from "lodash";
|
import { isFunction, merge } from "lodash";
|
||||||
import { stringify } from "querystring";
|
import { stringify } from "querystring";
|
||||||
import { apiKubePrefix, isDevelopment } from "../../common/vars";
|
import { apiKubePrefix, isDevelopment } from "../../common/vars";
|
||||||
import logger from "../../main/logger";
|
|
||||||
import { apiManager } from "./api-manager";
|
import { apiManager } from "./api-manager";
|
||||||
import { apiBase, apiKube } from "./index";
|
import { apiBase, apiKube } from "./index";
|
||||||
import { createKubeApiURL, parseKubeApi } from "./kube-api-parse";
|
import { createKubeApiURL, parseKubeApi } from "./kube-api-parse";
|
||||||
@ -27,6 +26,9 @@ import { Agent } from "https";
|
|||||||
import type { Patch } from "rfc6902";
|
import type { Patch } from "rfc6902";
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
import type { PartialDeep } from "type-fest";
|
import type { PartialDeep } from "type-fest";
|
||||||
|
import { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||||
|
import loggerInjectable from "../logger.injectable";
|
||||||
|
import type { Logger } from "../logger";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The options used for creating a `KubeApi`
|
* The options used for creating a `KubeApi`
|
||||||
@ -35,7 +37,7 @@ export interface IKubeApiOptions<T extends KubeObject<any, any, KubeObjectScope>
|
|||||||
/**
|
/**
|
||||||
* base api-path for listing all resources, e.g. "/api/v1/pods"
|
* base api-path for listing all resources, e.g. "/api/v1/pods"
|
||||||
*
|
*
|
||||||
* If not specified then will be the one on the `objectConstructor`
|
* Must be provided either here or under `objectConstructor.apiBase`
|
||||||
* @deprecated should be specified by `objectConstructor`
|
* @deprecated should be specified by `objectConstructor`
|
||||||
*/
|
*/
|
||||||
apiBase?: string;
|
apiBase?: string;
|
||||||
@ -46,11 +48,13 @@ export interface IKubeApiOptions<T extends KubeObject<any, any, KubeObjectScope>
|
|||||||
objectConstructor: KubeObjectConstructor<T, Data>;
|
objectConstructor: KubeObjectConstructor<T, Data>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Must be provided either here or under `objectConstructor.namespaced`
|
||||||
* @deprecated should be specified by `objectConstructor`
|
* @deprecated should be specified by `objectConstructor`
|
||||||
*/
|
*/
|
||||||
isNamespaced?: boolean;
|
isNamespaced?: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Must be provided either here or under `objectConstructor.kind`
|
||||||
* @deprecated should be specified by `objectConstructor`
|
* @deprecated should be specified by `objectConstructor`
|
||||||
*/
|
*/
|
||||||
kind?: string;
|
kind?: string;
|
||||||
@ -317,6 +321,7 @@ export class KubeApi<
|
|||||||
protected readonly doCheckPreferredVersion: boolean;
|
protected readonly doCheckPreferredVersion: boolean;
|
||||||
protected readonly fullApiPathname: string;
|
protected readonly fullApiPathname: string;
|
||||||
protected readonly fallbackApiBases?: string[];
|
protected readonly fallbackApiBases?: string[];
|
||||||
|
protected readonly logger: Logger;
|
||||||
|
|
||||||
constructor({
|
constructor({
|
||||||
objectConstructor,
|
objectConstructor,
|
||||||
@ -331,10 +336,12 @@ export class KubeApi<
|
|||||||
assert(request, "request MUST be provided if not in a cluster page frame context");
|
assert(request, "request MUST be provided if not in a cluster page frame context");
|
||||||
|
|
||||||
const { apiBase, apiPrefix, apiGroup, apiVersion, resource } = parseKubeApi(fullApiPathname);
|
const { apiBase, apiPrefix, apiGroup, apiVersion, resource } = parseKubeApi(fullApiPathname);
|
||||||
|
const di = getLegacyGlobalDiForExtensionApi();
|
||||||
|
|
||||||
assert(kind);
|
assert(kind);
|
||||||
assert(apiPrefix);
|
assert(apiPrefix);
|
||||||
|
|
||||||
|
this.logger = di.inject(loggerInjectable);
|
||||||
this.doCheckPreferredVersion = doCheckPreferredVersion;
|
this.doCheckPreferredVersion = doCheckPreferredVersion;
|
||||||
this.fallbackApiBases = fallbackApiBases;
|
this.fallbackApiBases = fallbackApiBases;
|
||||||
this.fullApiPathname = fullApiPathname;
|
this.fullApiPathname = fullApiPathname;
|
||||||
@ -353,7 +360,7 @@ export class KubeApi<
|
|||||||
|
|
||||||
get apiVersionWithGroup() {
|
get apiVersionWithGroup() {
|
||||||
return [this.apiGroup, this.apiVersionPreferred ?? this.apiVersion]
|
return [this.apiGroup, this.apiVersionPreferred ?? this.apiVersion]
|
||||||
.filter(isDefined)
|
.filter(Boolean)
|
||||||
.join("/");
|
.join("/");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -375,10 +382,10 @@ export class KubeApi<
|
|||||||
const { apiPrefix, apiGroup, apiVersionWithGroup, resource } = parseKubeApi(apiUrl);
|
const { apiPrefix, apiGroup, apiVersionWithGroup, resource } = parseKubeApi(apiUrl);
|
||||||
|
|
||||||
// Request available resources
|
// Request available resources
|
||||||
const response = await this.request.get<IKubeResourceList>(`${apiPrefix}/${apiVersionWithGroup}`);
|
const { resources } = await this.request.get(`${apiPrefix}/${apiVersionWithGroup}`) as IKubeResourceList;
|
||||||
|
|
||||||
// If the resource is found in the group, use this apiUrl
|
// If the resource is found in the group, use this apiUrl
|
||||||
if (response.resources?.find(kubeResource => kubeResource.name === resource)) {
|
if (resources.find(({ name }) => name === resource)) {
|
||||||
return { apiPrefix, apiGroup };
|
return { apiPrefix, apiGroup };
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -398,7 +405,7 @@ export class KubeApi<
|
|||||||
return await this.getLatestApiPrefixGroup();
|
return await this.getLatestApiPrefixGroup();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// If valid API wasn't found, log the error and return defaults below
|
// If valid API wasn't found, log the error and return defaults below
|
||||||
logger.error(`[KUBE-API]: ${error}`);
|
this.logger.error(`[KUBE-API]: ${error}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -422,8 +429,8 @@ export class KubeApi<
|
|||||||
this.apiPrefix = apiPrefix;
|
this.apiPrefix = apiPrefix;
|
||||||
this.apiGroup = apiGroup;
|
this.apiGroup = apiGroup;
|
||||||
|
|
||||||
const url = [apiPrefix, apiGroup].filter(isDefined).join("/");
|
const url = [apiPrefix, apiGroup].filter(Boolean).join("/");
|
||||||
const res = await this.request.get<IKubePreferredVersion>(url);
|
const res = await this.request.get(url) as IKubePreferredVersion;
|
||||||
|
|
||||||
this.apiVersionPreferred = res?.preferredVersion?.version;
|
this.apiVersionPreferred = res?.preferredVersion?.version;
|
||||||
|
|
||||||
@ -663,7 +670,7 @@ export class KubeApi<
|
|||||||
const abortController = new WrappedAbortController(opts.abortController);
|
const abortController = new WrappedAbortController(opts.abortController);
|
||||||
|
|
||||||
abortController.signal.addEventListener("abort", () => {
|
abortController.signal.addEventListener("abort", () => {
|
||||||
logger.info(`[KUBE-API] watch (${watchId}) aborted ${watchUrl}`);
|
this.logger.info(`[KUBE-API] watch (${watchId}) aborted ${watchUrl}`);
|
||||||
clearTimeout(timedRetry);
|
clearTimeout(timedRetry);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -674,7 +681,7 @@ export class KubeApi<
|
|||||||
timeout: 600_000,
|
timeout: 600_000,
|
||||||
});
|
});
|
||||||
|
|
||||||
logger.info(`[KUBE-API] watch (${watchId}) ${retry === true ? "retried" : "started"} ${watchUrl}`);
|
this.logger.info(`[KUBE-API] watch (${watchId}) ${retry === true ? "retried" : "started"} ${watchUrl}`);
|
||||||
|
|
||||||
responsePromise
|
responsePromise
|
||||||
.then(response => {
|
.then(response => {
|
||||||
@ -682,7 +689,7 @@ export class KubeApi<
|
|||||||
let requestRetried = false;
|
let requestRetried = false;
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
logger.warn(`[KUBE-API] watch (${watchId}) error response ${watchUrl}`, { status: response.status });
|
this.logger.warn(`[KUBE-API] watch (${watchId}) error response ${watchUrl}`, { status: response.status });
|
||||||
|
|
||||||
return callback(null, response);
|
return callback(null, response);
|
||||||
}
|
}
|
||||||
@ -699,7 +706,7 @@ export class KubeApi<
|
|||||||
// Close current request
|
// Close current request
|
||||||
abortController.abort();
|
abortController.abort();
|
||||||
|
|
||||||
logger.info(`[KUBE-API] Watch timeout set, but not retried, retrying now`);
|
this.logger.info(`[KUBE-API] Watch timeout set, but not retried, retrying now`);
|
||||||
|
|
||||||
requestRetried = true;
|
requestRetried = true;
|
||||||
|
|
||||||
@ -718,7 +725,7 @@ export class KubeApi<
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info(`[KUBE-API] watch (${watchId}) ${eventName} ${watchUrl}`);
|
this.logger.info(`[KUBE-API] watch (${watchId}) ${eventName} ${watchUrl}`);
|
||||||
|
|
||||||
requestRetried = true;
|
requestRetried = true;
|
||||||
|
|
||||||
@ -747,7 +754,7 @@ export class KubeApi<
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
logger.error(`[KUBE-API] watch (${watchId}) throwed ${watchUrl}`, error);
|
this.logger.error(`[KUBE-API] watch (${watchId}) throwed ${watchUrl}`, error);
|
||||||
|
|
||||||
callback(null, error);
|
callback(null, error);
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user