Replace cluster warning event polling with watches (#1521)

* replace cluster warning event polling with watches

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* cleanup

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* fix loadAll calls

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* tweak

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen authored and GitHub committed 2020-11-26 09:39:16 +02:00
1 parent 1547142125
commit 8739baab5b
3 files changed
+65 -52

No files matched your search

+1 -46
View File
@@ -42,7 +42,6 @@ export interface ClusterState {
accessible: boolean;
ready: boolean;
failureReason: string;
eventCount: number;
isAdmin: boolean;
allowedNamespaces: string[]
allowedResources: string[]
@@ -74,7 +73,6 @@ export class Cluster implements ClusterModel, ClusterState {
@observable disconnected = true; // false if user has selected to connect
@observable failureReason: string;
@observable isAdmin = false;
@observable eventCount = 0;
@observable preferences: ClusterPreferences = {};
@observable metadata: ClusterMetadata = {};
@observable allowedNamespaces: string[] = [];
@@ -209,10 +207,7 @@ export class Cluster implements ClusterModel, ClusterState {
await this.refreshConnectionStatus();
if (this.accessible) {
this.isAdmin = await this.isClusterAdmin();
await Promise.all([
this.refreshEvents(),
this.refreshAllowedResources(),
]);
await this.refreshAllowedResources();
if (opts.refreshMetadata) {
this.refreshMetadata();
}
@@ -242,11 +237,6 @@ export class Cluster implements ClusterModel, ClusterState {
this.allowedResources = await this.getAllowedResources();
}
@action
async refreshEvents() {
this.eventCount = await this.getEventCount();
}
protected getKubeconfig(): KubeConfig {
return loadConfig(this.kubeConfigPath);
}
@@ -332,40 +322,6 @@ export class Cluster implements ClusterModel, ClusterState {
});
}
protected async getEventCount(): Promise<number> {
if (!this.isAdmin) {
return 0;
}
const client = this.getProxyKubeconfig().makeApiClient(CoreV1Api);
try {
const response = await client.listEventForAllNamespaces(false, null, null, null, 1000);
const uniqEventSources = new Set();
const warnings = response.body.items.filter(e => e.type !== 'Normal');
for (const w of warnings) {
if (w.involvedObject.kind === 'Pod') {
try {
const { body: pod } = await client.readNamespacedPod(w.involvedObject.name, w.involvedObject.namespace);
logger.debug(`checking pod ${w.involvedObject.namespace}/${w.involvedObject.name}`);
if (podHasIssues(pod)) {
uniqEventSources.add(w.involvedObject.uid);
}
} catch (err) {
}
} else {
uniqEventSources.add(w.involvedObject.uid);
}
}
const nodes = (await client.listNode()).body.items;
const nodeNotificationCount = nodes
.map(getNodeWarningConditions)
.reduce((sum, conditions) => sum + conditions.length, 0);
return uniqEventSources.size + nodeNotificationCount;
} catch (error) {
logger.error("Failed to fetch event count: " + JSON.stringify(error));
return 0;
}
}
toJSON(): ClusterModel {
const model: ClusterModel = {
id: this.id,
@@ -393,7 +349,6 @@ export class Cluster implements ClusterModel, ClusterState {
accessible: this.accessible,
failureReason: this.failureReason,
isAdmin: this.isAdmin,
eventCount: this.eventCount,
allowedNamespaces: this.allowedNamespaces,
allowedResources: this.allowedResources,
};