mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix exception in KubeStore.watch event buffer handling (#5120)
* Fix exception in KubeStore.watch event buffer handling Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix type error Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
f0978f02c9
commit
69f1ecb0b9
@ -655,7 +655,7 @@ export class KubeApi<T extends KubeObject> {
|
|||||||
if (event.type === "ERROR" && event.object.kind === "Status") {
|
if (event.type === "ERROR" && event.object.kind === "Status") {
|
||||||
errorReceived = true;
|
errorReceived = true;
|
||||||
|
|
||||||
return callback(null, new KubeStatus(event.object as any));
|
return callback(null, new KubeStatus(event.object));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.modifyWatchEvent(event);
|
this.modifyWatchEvent(event);
|
||||||
|
|||||||
@ -19,6 +19,7 @@ import type { RequestInit } from "node-fetch";
|
|||||||
// eslint-disable-next-line import/no-named-as-default
|
// eslint-disable-next-line import/no-named-as-default
|
||||||
import AbortController from "abort-controller";
|
import AbortController from "abort-controller";
|
||||||
import type { Patch } from "rfc6902";
|
import type { Patch } from "rfc6902";
|
||||||
|
import logger from "../logger";
|
||||||
|
|
||||||
export interface KubeObjectStoreLoadingParams {
|
export interface KubeObjectStoreLoadingParams {
|
||||||
namespaces: string[];
|
namespaces: string[];
|
||||||
@ -456,14 +457,27 @@ export abstract class KubeObjectStore<T extends KubeObject> extends ItemStore<T>
|
|||||||
protected updateFromEventsBuffer() {
|
protected updateFromEventsBuffer() {
|
||||||
const items = this.getItems();
|
const items = this.getItems();
|
||||||
|
|
||||||
for (const { type, object } of this.eventsBuffer.clear()) {
|
for (const event of this.eventsBuffer.clear()) {
|
||||||
const index = items.findIndex(item => item.getId() === object.metadata?.uid);
|
if (event.type === "ERROR") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { type, object } = event;
|
||||||
|
|
||||||
|
if (!object.metadata?.uid) {
|
||||||
|
logger.warn("[KUBE-STORE]: watch event did not have defined .metadata.uid, skipping", { event });
|
||||||
|
// Other parts of the code will break if this happens
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const index = items.findIndex(item => item.getId() === object.metadata.uid);
|
||||||
const item = items[index];
|
const item = items[index];
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "ADDED":
|
case "ADDED":
|
||||||
|
|
||||||
// falls through
|
// fallthrough
|
||||||
case "MODIFIED": {
|
case "MODIFIED": {
|
||||||
const newItem = new this.api.objectConstructor(object);
|
const newItem = new this.api.objectConstructor(object);
|
||||||
|
|
||||||
@ -481,6 +495,9 @@ export abstract class KubeObjectStore<T extends KubeObject> extends ItemStore<T>
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("[KUBE-STORE]: failed to handle event from watch buffer", { error, event });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// update items
|
// update items
|
||||||
|
|||||||
@ -4,9 +4,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import type { KubeJsonApiData } from "./kube-json-api";
|
import type { KubeJsonApiData } from "./kube-json-api";
|
||||||
|
import type { KubeStatusData } from "./kube-object";
|
||||||
|
|
||||||
export interface IKubeWatchEvent<T extends KubeJsonApiData> {
|
export type IKubeWatchEvent<T extends KubeJsonApiData> = {
|
||||||
type: "ADDED" | "MODIFIED" | "DELETED" | "ERROR";
|
type: "ADDED" | "MODIFIED" | "DELETED";
|
||||||
object?: T;
|
object: T;
|
||||||
}
|
} | {
|
||||||
|
type: "ERROR";
|
||||||
|
object: KubeStatusData;
|
||||||
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user